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.

2816 lines
78 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: serverui.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 "serverUI.h"
  18. #include "servwiz.h" // CRootHintsQueryThread
  19. #include "domain.h"
  20. #include "zone.h"
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // CDNSServer_InterfacesPropertyPage
  23. BEGIN_MESSAGE_MAP(CDNSServer_InterfacesPropertyPage, CPropertyPageBase)
  24. ON_BN_CLICKED(IDC_LISTEN_ON_ALL_RADIO, OnListenOnAllAddresses)
  25. ON_BN_CLICKED(IDC_LISTEN_ON_SPECIFIED_RADIO, OnListenOnSpecifiedAddresses)
  26. END_MESSAGE_MAP()
  27. void CDNSServer_InterfacesPropertyPage::CListenAddressesIPEditor::OnChangeData()
  28. {
  29. CDNSServer_InterfacesPropertyPage* pPage =
  30. (CDNSServer_InterfacesPropertyPage*)GetParentWnd();
  31. pPage->SetDirty(TRUE);
  32. if (GetCount() == 0)
  33. {
  34. CButton* pListenAllButton = pPage->GetListenOnAllRadio();
  35. pListenAllButton->SetCheck(TRUE);
  36. pPage->GetListenOnSpecifiedRadio()->SetCheck(FALSE);
  37. pPage->SelectionHelper(TRUE);
  38. pListenAllButton->SetFocus();
  39. }
  40. }
  41. CDNSServer_InterfacesPropertyPage::CDNSServer_InterfacesPropertyPage()
  42. : m_bAllWasPreviousSelection(FALSE),
  43. CPropertyPageBase(IDD_SERVER_INTERFACES_PAGE)
  44. {
  45. }
  46. BOOL CDNSServer_InterfacesPropertyPage::OnInitDialog()
  47. {
  48. CPropertyPageBase::OnInitDialog();
  49. CDNSServerPropertyPageHolder* pHolder =
  50. (CDNSServerPropertyPageHolder*)GetHolder();
  51. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  52. VERIFY(m_listenAddressesEditor.Initialize(this,
  53. GetParent(),
  54. IDC_BUTTON_UP,
  55. IDC_BUTTON_DOWN,
  56. IDC_BUTTON_ADD,
  57. IDC_BUTTON_REMOVE,
  58. IDC_IPEDIT,
  59. IDC_LIST));
  60. if (!pServerNode->HasServerInfo())
  61. {
  62. EnableWindow(FALSE);
  63. return TRUE;
  64. }
  65. BOOL bListenAll = FALSE;
  66. DWORD cAddrCount;
  67. PIP_ADDRESS pipAddrs;
  68. pServerNode->GetListenAddressesInfo(&cAddrCount, &pipAddrs);
  69. if (cAddrCount == 0)
  70. {
  71. // listening on all addresses
  72. pServerNode->GetServerAddressesInfo(&cAddrCount, &pipAddrs);
  73. bListenAll = TRUE;
  74. m_bAllWasPreviousSelection = TRUE;
  75. }
  76. GetListenOnAllRadio()->SetCheck(bListenAll);
  77. GetListenOnSpecifiedRadio()->SetCheck(!bListenAll);
  78. if (cAddrCount > 0)
  79. {
  80. m_listenAddressesEditor.AddAddresses(pipAddrs, cAddrCount);
  81. m_bAllWasPreviousSelection = FALSE;
  82. }
  83. m_listenAddressesEditor.EnableUI(!bListenAll, TRUE);
  84. SetDirty(FALSE);
  85. return TRUE; // return TRUE unless you set the focus to a control
  86. // EXCEPTION: OCX Property Pages should return FALSE
  87. }
  88. void CDNSServer_InterfacesPropertyPage::SelectionHelper(BOOL bListenAll)
  89. {
  90. CDNSServerPropertyPageHolder* pHolder =
  91. (CDNSServerPropertyPageHolder*)GetHolder();
  92. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  93. if ((m_bAllWasPreviousSelection && !bListenAll) || bListenAll)
  94. {
  95. m_listenAddressesEditor.Clear();
  96. }
  97. DWORD cAddrCount;
  98. PIP_ADDRESS pipAddrs;
  99. pServerNode->GetServerAddressesInfo(&cAddrCount, &pipAddrs);
  100. if (cAddrCount > 0)
  101. {
  102. m_listenAddressesEditor.AddAddresses(pipAddrs, cAddrCount);
  103. }
  104. m_listenAddressesEditor.EnableUI(!bListenAll, TRUE);
  105. m_bAllWasPreviousSelection = bListenAll;
  106. SetDirty(TRUE);
  107. }
  108. void CDNSServer_InterfacesPropertyPage::OnListenOnSpecifiedAddresses()
  109. {
  110. //ASSERT(!GetListenOnAllRadio()->GetCheck());
  111. //ASSERT(GetListenOnSpecifiedRadio()->GetCheck());
  112. SelectionHelper(FALSE);
  113. }
  114. void CDNSServer_InterfacesPropertyPage::OnListenOnAllAddresses()
  115. {
  116. //ASSERT(GetListenOnAllRadio()->GetCheck());
  117. //ASSERT(!GetListenOnSpecifiedRadio()->GetCheck());
  118. SelectionHelper(TRUE);
  119. }
  120. BOOL CDNSServer_InterfacesPropertyPage::OnApply()
  121. {
  122. CDNSServerPropertyPageHolder* pHolder =
  123. (CDNSServerPropertyPageHolder*)GetHolder();
  124. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  125. if (!IsDirty())
  126. return TRUE;
  127. int cAddrCount = 0;
  128. if (GetListenOnSpecifiedRadio()->GetCheck())
  129. {
  130. // get the data from the IP editor
  131. cAddrCount = m_listenAddressesEditor.GetCount();
  132. }
  133. BOOL bRet = TRUE;
  134. DWORD* pArr = (cAddrCount > 0) ? (DWORD*) malloc(sizeof(DWORD)*cAddrCount) : NULL;
  135. if (pArr != NULL && cAddrCount > 0)
  136. {
  137. int nFilled = 0;
  138. m_listenAddressesEditor.GetAddresses(pArr, cAddrCount, &nFilled);
  139. ASSERT(nFilled == cAddrCount);
  140. }
  141. // write to server
  142. DNS_STATUS err = pServerNode->ResetListenAddresses(cAddrCount, pArr);
  143. if (err != 0)
  144. {
  145. DNSErrorDialog(err, IDS_MSG_SERVER_INTERFACE_UPDATE_FAILED);
  146. bRet = FALSE;
  147. }
  148. if (pArr)
  149. {
  150. free(pArr);
  151. pArr = 0;
  152. }
  153. return bRet;
  154. }
  155. ////////////////////////////////////////////////////////////////////////////////////
  156. // CDomainForwardersEditInfo
  157. CDomainForwardersEditInfo::CDomainForwardersEditInfo(
  158. CDNSZoneNode* pZoneNode,
  159. BOOL bADIntegrated,
  160. BOOL bAllOthers)
  161. : m_bADIntegrated(bADIntegrated),
  162. m_pZoneNode(pZoneNode)
  163. {
  164. m_bAllOthersDomain = bAllOthers;
  165. m_actionItem = nochange;
  166. if (pZoneNode != NULL)
  167. {
  168. m_bRPCData = TRUE;
  169. pZoneNode->GetMastersInfo(&m_cAddrCount, &m_pIPList);
  170. m_szDomainName = pZoneNode->GetDisplayName();
  171. m_bSlave = pZoneNode->IsForwarderSlave();
  172. m_dwTimeout = pZoneNode->ForwarderTimeout();
  173. }
  174. else
  175. {
  176. m_bRPCData = FALSE;
  177. m_cAddrCount = 0;
  178. m_pIPList = NULL;
  179. m_szDomainName = L"";
  180. m_bSlave = DNS_DEFAULT_SLAVE;
  181. m_dwTimeout = DNS_DEFAULT_FORWARD_TIMEOUT;
  182. }
  183. }
  184. CDomainForwardersEditInfo::~CDomainForwardersEditInfo()
  185. {
  186. if (m_bAllOthersDomain && m_pAllOthers != NULL)
  187. {
  188. delete m_pAllOthers;
  189. }
  190. if (m_pIPList != NULL && m_actionItem != nochange)
  191. {
  192. free(m_pIPList);
  193. m_pIPList = NULL;
  194. }
  195. }
  196. void CDomainForwardersEditInfo::SetAllOthersDomain(CAllOthersDomainInfo* pAllOthers)
  197. {
  198. if (pAllOthers != NULL)
  199. {
  200. m_bAllOthersDomain = TRUE;
  201. m_pAllOthers = pAllOthers;
  202. m_cAddrCount = m_pAllOthers->m_cAddrCount;
  203. m_pIPList = m_pAllOthers->m_pipAddrs;
  204. m_bSlave = m_pAllOthers->m_fSlave;
  205. m_dwTimeout = m_pAllOthers->m_dwForwardTimeout;
  206. }
  207. }
  208. void CDomainForwardersEditInfo::SetAction(ACTION_ITEM action)
  209. {
  210. m_actionItem = action;
  211. }
  212. BOOL CDomainForwardersEditInfo::Update(BOOL bSlave, DWORD dwTimeout, DWORD dwCount, PIP_ADDRESS pipArray)
  213. {
  214. BOOL bUpdate = FALSE;
  215. if (bSlave != m_bSlave ||
  216. dwTimeout != m_dwTimeout)
  217. {
  218. bUpdate = TRUE;
  219. m_bSlave = bSlave;
  220. m_dwTimeout = dwTimeout;
  221. }
  222. if (dwCount != m_cAddrCount)
  223. {
  224. if (m_pIPList != NULL)
  225. {
  226. if (!m_bRPCData)
  227. {
  228. //
  229. // Free the memory if it isn't part of the RPC structure
  230. //
  231. free(m_pIPList);
  232. m_pIPList = NULL;
  233. }
  234. }
  235. m_bRPCData = FALSE;
  236. m_pIPList = pipArray;
  237. m_cAddrCount = dwCount;
  238. bUpdate = TRUE;
  239. }
  240. else
  241. {
  242. if (m_pIPList != NULL)
  243. {
  244. for (UINT nIndex = 0; nIndex < dwCount; nIndex++)
  245. {
  246. if (nIndex <= m_cAddrCount)
  247. {
  248. if (pipArray[nIndex] != m_pIPList[nIndex])
  249. {
  250. bUpdate = TRUE;
  251. if (!m_bRPCData)
  252. {
  253. free(m_pIPList);
  254. m_pIPList = NULL;
  255. }
  256. m_bRPCData = FALSE;
  257. m_pIPList = pipArray;
  258. m_cAddrCount = dwCount;
  259. break;
  260. }
  261. }
  262. else
  263. {
  264. bUpdate = TRUE;
  265. if (m_actionItem != nochange)
  266. {
  267. free(m_pIPList);
  268. m_pIPList = NULL;
  269. }
  270. m_pIPList = pipArray;
  271. m_cAddrCount = dwCount;
  272. break;
  273. }
  274. }
  275. }
  276. else if (m_pIPList != NULL && dwCount > 0)
  277. {
  278. bUpdate = TRUE;
  279. m_pIPList = pipArray;
  280. m_cAddrCount = dwCount;
  281. }
  282. }
  283. if (bUpdate)
  284. {
  285. switch (GetAction())
  286. {
  287. case nochange:
  288. case update:
  289. SetAction(update);
  290. break;
  291. case remove:
  292. case add:
  293. default:
  294. break;
  295. }
  296. }
  297. return bUpdate;
  298. }
  299. ///////////////////////////////////////////////////////////////////////////////
  300. // CDNSServer_AddDomainForwarderDialog
  301. class CDNSServer_AddDomainForwarderDialog : public CHelpDialog
  302. {
  303. public:
  304. CDNSServer_AddDomainForwarderDialog(CDNSServerNode* pServerNode,
  305. CComponentDataObject* pComponentData)
  306. : CHelpDialog(IDD_SERVER_NEW_DOMAIN_FORWARDER, pComponentData),
  307. m_pComponentData(pComponentData),
  308. m_pServerNode(pServerNode)
  309. {
  310. m_bOkable = FALSE;
  311. m_szDomainName = L"";
  312. }
  313. ~CDNSServer_AddDomainForwarderDialog() {}
  314. //
  315. // Public data
  316. //
  317. CString m_szDomainName;
  318. DECLARE_MESSAGE_MAP()
  319. virtual BOOL OnInitDialog();
  320. virtual void OnOK();
  321. afx_msg void OnDomainEdit();
  322. private:
  323. BOOL m_bOkable;
  324. CDNSServerNode* m_pServerNode;
  325. CComponentDataObject* m_pComponentData;
  326. };
  327. BEGIN_MESSAGE_MAP(CDNSServer_AddDomainForwarderDialog, CHelpDialog)
  328. ON_EN_CHANGE(IDC_DOMAIN_NAME_EDIT, OnDomainEdit)
  329. END_MESSAGE_MAP()
  330. BOOL CDNSServer_AddDomainForwarderDialog::OnInitDialog()
  331. {
  332. CHelpDialog::OnInitDialog();
  333. GetDlgItem(IDOK)->EnableWindow(m_bOkable);
  334. SendDlgItemMessage(IDC_DOMAIN_NAME_EDIT, EM_SETLIMITTEXT, (WPARAM)254, 0);
  335. return TRUE;
  336. }
  337. void CDNSServer_AddDomainForwarderDialog::OnDomainEdit()
  338. {
  339. GetDlgItemText(IDC_DOMAIN_NAME_EDIT, m_szDomainName);
  340. m_bOkable = !m_szDomainName.IsEmpty();
  341. GetDlgItem(IDOK)->EnableWindow(m_bOkable);
  342. }
  343. void CDNSServer_AddDomainForwarderDialog::OnOK()
  344. {
  345. DNS_STATUS err = ::ValidateDnsNameAgainstServerFlags(m_szDomainName,
  346. DnsNameDomain,
  347. m_pServerNode->GetNameCheckFlag());
  348. if (err != 0)
  349. {
  350. CString szFormatMsg;
  351. VERIFY(szFormatMsg.LoadString(IDS_MSG_DOMAIN_FORWARDER_ILLEGAL_NAME));
  352. CString szMessage;
  353. szMessage.Format(szFormatMsg, m_szDomainName);
  354. DNSErrorDialog(err, szMessage);
  355. return;
  356. }
  357. CHelpDialog::OnOK();
  358. }
  359. ///////////////////////////////////////////////////////////////////////////////
  360. // CDNSServer_DomainForwardersPropertyPage
  361. void CDNSServer_DomainForwardersPropertyPage::CForwarderAddressesIPEditor::OnChangeData()
  362. {
  363. CDNSServer_DomainForwardersPropertyPage* pPage =
  364. (CDNSServer_DomainForwardersPropertyPage*)GetParentWnd();
  365. pPage->SetDirty(TRUE);
  366. }
  367. BEGIN_MESSAGE_MAP(CDNSServer_DomainForwardersPropertyPage, CPropertyPageBase)
  368. ON_LBN_SELCHANGE(IDC_DOMAIN_LIST, OnDomainSelChange)
  369. ON_BN_CLICKED(IDC_DOMAIN_ADD_BUTTON, OnAddDomain)
  370. ON_BN_CLICKED(IDC_DOMAIN_REMOVE_BUTTON, OnRemoveDomain)
  371. ON_BN_CLICKED(IDC_SLAVE_CHECK, OnSlaveCheckChange)
  372. ON_EN_CHANGE(IDC_FWD_TIMEOUT_EDIT, OnForwarderTimeoutChange)
  373. END_MESSAGE_MAP()
  374. CDNSServer_DomainForwardersPropertyPage::CDNSServer_DomainForwardersPropertyPage()
  375. : CPropertyPageBase(IDD_SERVER_DOMAIN_FORWARDERS_PAGE)
  376. {
  377. m_pCurrentInfo = NULL;
  378. m_bPostApply = FALSE;
  379. }
  380. void CDNSServer_DomainForwardersPropertyPage::OnDomainSelChange()
  381. {
  382. CDNSServerPropertyPageHolder* pHolder =
  383. (CDNSServerPropertyPageHolder*)GetHolder();
  384. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  385. CListBox* pDomainList = (CListBox*)GetDlgItem(IDC_DOMAIN_LIST);
  386. if (pDomainList != NULL)
  387. {
  388. int iSel = pDomainList->GetCurSel();
  389. if (iSel != LB_ERR)
  390. {
  391. LRESULT lRes = pDomainList->GetItemData(iSel);
  392. if (lRes != LB_ERR)
  393. {
  394. //
  395. // Retrieve the edit info from the list box item
  396. //
  397. CDomainForwardersEditInfo* pInfo = reinterpret_cast<CDomainForwardersEditInfo*>(lRes);
  398. if (pInfo != NULL)
  399. {
  400. //
  401. // Store the previous selection's data before changing the UI.
  402. // This may be NULL during OnInitDialog so check before trying
  403. // to store the info.
  404. //
  405. if (m_pCurrentInfo != NULL)
  406. {
  407. BOOL bSlave = GetSlaveCheck()->GetCheck();
  408. DWORD dwTimeout = m_forwardTimeoutEdit.GetVal();
  409. DWORD cAddrCount = m_forwarderAddressesEditor.GetCount();
  410. DWORD* pArr = (cAddrCount > 0) ? (DWORD*) malloc(sizeof(DWORD)*cAddrCount) : NULL;
  411. if (pArr != NULL)
  412. {
  413. if (cAddrCount > 0)
  414. {
  415. int nFilled = 0;
  416. m_forwarderAddressesEditor.GetAddresses(pArr, cAddrCount, &nFilled);
  417. ASSERT(nFilled == (int)cAddrCount);
  418. }
  419. }
  420. m_pCurrentInfo->Update(bSlave, dwTimeout, cAddrCount, pArr);
  421. }
  422. m_pCurrentInfo = pInfo;
  423. //
  424. // Enable the remove button according to the selection
  425. //
  426. if (pInfo->IsAllOthers())
  427. {
  428. GetDlgItem(IDC_DOMAIN_REMOVE_BUTTON)->EnableWindow(FALSE);
  429. }
  430. else
  431. {
  432. GetDlgItem(IDC_DOMAIN_REMOVE_BUTTON)->EnableWindow(TRUE);
  433. }
  434. if (pServerNode->GetBuildNumber() < DNS_SRV_BUILD_NUMBER_WHISTLER ||
  435. (pServerNode->GetMajorVersion() <= DNS_SRV_MAJOR_VERSION_NT_5 &&
  436. pServerNode->GetMinorVersion() < DNS_SRV_MINOR_VERSION_WHISTLER))
  437. {
  438. //
  439. // Domain forwarding not available on pre-Whistler servers
  440. //
  441. GetDlgItem(IDC_DOMAIN_ADD_BUTTON)->EnableWindow(FALSE);
  442. GetDlgItem(IDC_DOMAIN_REMOVE_BUTTON)->EnableWindow(FALSE);
  443. }
  444. //
  445. // load data into the controls
  446. //
  447. GetSlaveCheck()->SetCheck(pInfo->IsSlave());
  448. m_forwardTimeoutEdit.SetVal(pInfo->GetTimeout());
  449. //
  450. // Display the text of the forwarder is AD integrated
  451. //
  452. GetDlgItem(IDC_FORWARDER_ADINT_STATIC)->ShowWindow(pInfo->IsADIntegrated());
  453. //
  454. // Clear the IP Editor controls
  455. //
  456. m_forwarderAddressesEditor.Clear();
  457. DWORD cAddrCount = 0;
  458. PIP_ADDRESS pipAddrs = pInfo->GetIPList(&cAddrCount);
  459. if (cAddrCount > 0 && pipAddrs != NULL)
  460. {
  461. m_forwarderAddressesEditor.AddAddresses(pipAddrs, cAddrCount);
  462. }
  463. }
  464. }
  465. }
  466. }
  467. SetDirty(TRUE);
  468. }
  469. void CDNSServer_DomainForwardersPropertyPage::OnAddDomain()
  470. {
  471. CDNSServerPropertyPageHolder* pHolder =
  472. (CDNSServerPropertyPageHolder*)GetHolder();
  473. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  474. CDNSServer_AddDomainForwarderDialog dlg(pServerNode, pHolder->GetComponentData());
  475. if (dlg.DoModal() == IDOK)
  476. {
  477. CListBox* pDomainList = (CListBox*)GetDlgItem(IDC_DOMAIN_LIST);
  478. //
  479. // Check to see if the name already exists
  480. //
  481. int iIndex = LB_ERR;
  482. int iFindIdx = pDomainList->FindStringExact(-1, dlg.m_szDomainName);
  483. if (iFindIdx == LB_ERR)
  484. {
  485. //
  486. // Add the name if it isn't already there
  487. //
  488. iIndex = pDomainList->AddString(dlg.m_szDomainName);
  489. }
  490. else
  491. {
  492. //
  493. // If its there just point to it
  494. //
  495. iIndex = iFindIdx;
  496. }
  497. if (iIndex != LB_ERR)
  498. {
  499. CDomainForwardersEditInfo* pSearchInfo = m_EditList.DoesExist(dlg.m_szDomainName);
  500. if (pSearchInfo != NULL)
  501. {
  502. switch (pSearchInfo->GetAction())
  503. {
  504. case CDomainForwardersEditInfo::nochange:
  505. case CDomainForwardersEditInfo::update:
  506. case CDomainForwardersEditInfo::remove:
  507. pSearchInfo->SetAction(CDomainForwardersEditInfo::update);
  508. break;
  509. case CDomainForwardersEditInfo::add:
  510. default:
  511. break;
  512. }
  513. int iIdx = pDomainList->FindStringExact(-1, dlg.m_szDomainName);
  514. if (iIdx != LB_ERR)
  515. {
  516. pDomainList->SetCurSel(iIdx);
  517. pDomainList->SetItemData(iIdx, (LPARAM)pSearchInfo);
  518. OnDomainSelChange();
  519. }
  520. }
  521. else
  522. {
  523. //
  524. // Attach some data to keep track of whats being added or changed
  525. //
  526. CDomainForwardersEditInfo* pNewEditInfo = new CDomainForwardersEditInfo(NULL, FALSE);
  527. if (pNewEditInfo != NULL)
  528. {
  529. pNewEditInfo->SetDomainName(dlg.m_szDomainName);
  530. m_EditList.AddTail(pNewEditInfo);
  531. pDomainList->SetItemData(iIndex, (LPARAM)pNewEditInfo);
  532. switch (pNewEditInfo->GetAction())
  533. {
  534. case CDomainForwardersEditInfo::nochange:
  535. pNewEditInfo->SetAction(CDomainForwardersEditInfo::add);
  536. break;
  537. case CDomainForwardersEditInfo::update:
  538. case CDomainForwardersEditInfo::remove:
  539. case CDomainForwardersEditInfo::add:
  540. default:
  541. ASSERT(FALSE);
  542. break;
  543. }
  544. pDomainList->SetCurSel(iIndex);
  545. OnDomainSelChange();
  546. }
  547. }
  548. }
  549. }
  550. SetDirty(TRUE);
  551. }
  552. void CDNSServer_DomainForwardersPropertyPage::OnRemoveDomain()
  553. {
  554. CListBox* pDomainList = (CListBox*)GetDlgItem(IDC_DOMAIN_LIST);
  555. if (pDomainList != NULL)
  556. {
  557. int iSel = pDomainList->GetCurSel();
  558. if (iSel != LB_ERR)
  559. {
  560. CDomainForwardersEditInfo* pEditInfo = reinterpret_cast<CDomainForwardersEditInfo*>(pDomainList->GetItemData(iSel));
  561. if (pEditInfo != NULL)
  562. {
  563. ASSERT(pEditInfo == m_pCurrentInfo);
  564. switch (pEditInfo->GetAction())
  565. {
  566. case CDomainForwardersEditInfo::nochange:
  567. case CDomainForwardersEditInfo::update:
  568. case CDomainForwardersEditInfo::remove:
  569. pEditInfo->SetAction(CDomainForwardersEditInfo::remove);
  570. break;
  571. case CDomainForwardersEditInfo::add:
  572. m_EditList.Remove(pEditInfo);
  573. delete pEditInfo;
  574. break;
  575. default:
  576. ASSERT(FALSE);
  577. break;
  578. }
  579. }
  580. pDomainList->DeleteString(iSel);
  581. m_pCurrentInfo = NULL;
  582. //
  583. // Set the selection to the previous entry
  584. //
  585. pDomainList->SetCurSel(iSel - 1);
  586. OnDomainSelChange();
  587. }
  588. }
  589. SetDirty(TRUE);
  590. }
  591. void CDNSServer_DomainForwardersPropertyPage::OnSlaveCheckChange()
  592. {
  593. SetDirty(TRUE);
  594. }
  595. void CDNSServer_DomainForwardersPropertyPage::OnForwarderTimeoutChange()
  596. {
  597. SetDirty(TRUE);
  598. }
  599. BOOL CDNSServer_DomainForwardersPropertyPage::OnInitDialog()
  600. {
  601. CPropertyPageBase::OnInitDialog();
  602. CDNSServerPropertyPageHolder* pHolder =
  603. (CDNSServerPropertyPageHolder*)GetHolder();
  604. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  605. //
  606. // initialize controls
  607. //
  608. VERIFY(m_forwarderAddressesEditor.Initialize(this,
  609. GetParent(),
  610. IDC_BUTTON_UP,
  611. IDC_BUTTON_DOWN,
  612. IDC_BUTTON_ADD,
  613. IDC_BUTTON_REMOVE,
  614. IDC_IPEDIT,
  615. IDC_LIST));
  616. VERIFY(m_forwardTimeoutEdit.SubclassDlgItem(IDC_FWD_TIMEOUT_EDIT, this));
  617. m_forwardTimeoutEdit.SetRange(1,0xffff ); // DWORD
  618. m_forwardTimeoutEdit.SetLimitText(5); // 0 to 65535
  619. //
  620. // Disable IME support on the controls
  621. //
  622. ImmAssociateContext(m_forwardTimeoutEdit.GetSafeHwnd(), NULL);
  623. if (!pServerNode->HasServerInfo())
  624. {
  625. //
  626. // clear the root hints message text
  627. //
  628. SetDlgItemText(IDC_STATIC_MESSAGE, NULL);
  629. EnableWindow(FALSE);
  630. return TRUE;
  631. }
  632. //
  633. // Don't show the AD Integrated text unless the forwarder is
  634. // AD integrated (rare)
  635. //
  636. GetDlgItem(IDC_FORWARDER_ADINT_STATIC)->ShowWindow(FALSE);
  637. SetDirty(FALSE);
  638. return TRUE; // return TRUE unless you set the focus to a control
  639. // EXCEPTION: OCX Property Pages should return FALSE
  640. }
  641. BOOL CDNSServer_DomainForwardersPropertyPage::OnSetActive()
  642. {
  643. CDNSServerPropertyPageHolder* pHolder =
  644. (CDNSServerPropertyPageHolder*)GetHolder();
  645. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  646. BOOL bWasDirty = IsDirty();
  647. BOOL bServerHasRoot = FALSE;
  648. DNS_STATUS err = ServerHasRootZone(pServerNode->GetRPCName(), &bServerHasRoot);
  649. if (err == ERROR_SUCCESS && (bServerHasRoot || !pServerNode->DoesRecursion()))
  650. {
  651. //
  652. // the server is a root server or doesn't do recursion
  653. //
  654. EnableDialogControls(m_hWnd, FALSE);
  655. CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_ADD_FORWARDERS);
  656. if (pStatic != NULL)
  657. {
  658. pStatic->ShowWindow(FALSE);
  659. }
  660. pStatic = (CStatic*)GetDlgItem(IDC_STATIC_MESSAGE);
  661. if (pStatic != NULL)
  662. {
  663. if (bServerHasRoot)
  664. {
  665. pStatic->ShowWindow(TRUE);
  666. }
  667. else
  668. {
  669. pStatic->ShowWindow(FALSE);
  670. }
  671. }
  672. if (!pServerNode->DoesRecursion())
  673. {
  674. CString szNoRecursionText;
  675. VERIFY(szNoRecursionText.LoadString(IDS_DISABLED_FWDS_NO_RECURSION));
  676. SetDlgItemText(IDC_STATIC_CAPTION, szNoRecursionText);
  677. }
  678. GetDlgItem(IDC_DOMAIN_LIST)->EnableWindow(FALSE);
  679. GetDlgItem(IDC_LIST)->EnableWindow(FALSE);
  680. }
  681. else
  682. {
  683. //
  684. // clear the root hints message text
  685. //
  686. SetDlgItemText(IDC_STATIC_MESSAGE, NULL);
  687. if (!m_bPostApply)
  688. {
  689. //
  690. // Clear the list box
  691. //
  692. SendDlgItemMessage(IDC_DOMAIN_LIST, LB_RESETCONTENT, 0, 0);
  693. //
  694. // Clear any stored values
  695. //
  696. m_EditList.DeleteAll();
  697. m_pCurrentInfo = NULL;
  698. }
  699. //
  700. // Enable all the controls
  701. //
  702. EnableWindow(TRUE);
  703. EnableDialogControls(m_hWnd, TRUE);
  704. //
  705. // Get the domain forwarders info from hidden Category node
  706. //
  707. CDNSDomainForwardersNode* pDomainForwardersNode = pServerNode->GetDomainForwardersNode();
  708. if (pDomainForwardersNode == NULL)
  709. {
  710. ASSERT(FALSE);
  711. //
  712. // Disable all controls
  713. //
  714. SetDlgItemText(IDC_STATIC_MESSAGE, NULL);
  715. EnableWindow(FALSE);
  716. EnableDialogControls(m_hWnd, FALSE);
  717. CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_ADD_FORWARDERS);
  718. if (pStatic != NULL)
  719. {
  720. pStatic->ShowWindow(FALSE);
  721. }
  722. pStatic = (CStatic*)GetDlgItem(IDC_STATIC_MESSAGE);
  723. if (pStatic != NULL)
  724. {
  725. if (bServerHasRoot)
  726. {
  727. pStatic->ShowWindow(TRUE);
  728. }
  729. else
  730. {
  731. pStatic->ShowWindow(FALSE);
  732. }
  733. }
  734. return TRUE;
  735. }
  736. if (!m_bPostApply)
  737. {
  738. CNodeList* pNodeList = pDomainForwardersNode->GetContainerChildList();
  739. POSITION pos = pNodeList->GetHeadPosition();
  740. while (pos != NULL)
  741. {
  742. CDNSZoneNode* pZoneNode = dynamic_cast<CDNSZoneNode*>(pNodeList->GetNext(pos));
  743. if (pZoneNode != NULL && pZoneNode->GetZoneType() == DNS_ZONE_TYPE_FORWARDER)
  744. {
  745. //
  746. // Create a temporary list that will last through the duration of the page for all
  747. // the forwarders
  748. //
  749. BOOL bADIntegrated = pZoneNode->IsDSIntegrated();
  750. CDomainForwardersEditInfo* pForwardersInfo = new CDomainForwardersEditInfo(
  751. pZoneNode,
  752. bADIntegrated,
  753. FALSE);
  754. if (pForwardersInfo != NULL)
  755. {
  756. m_EditList.AddTail(pForwardersInfo);
  757. //
  758. // Add the forwarder to the UI
  759. //
  760. LRESULT lIndex = SendDlgItemMessage(IDC_DOMAIN_LIST, LB_ADDSTRING, 0, (LPARAM)pZoneNode->GetDisplayName());
  761. if (lIndex != LB_ERR)
  762. {
  763. SendDlgItemMessage(IDC_DOMAIN_LIST, LB_SETITEMDATA, lIndex, (LPARAM)pForwardersInfo);
  764. }
  765. }
  766. }
  767. }
  768. //
  769. // get data from server
  770. //
  771. DWORD cAddrCount;
  772. PIP_ADDRESS pipAddrs;
  773. DWORD dwForwardTimeout;
  774. DWORD fSlave;
  775. pServerNode->GetForwardersInfo(&cAddrCount, &pipAddrs, &dwForwardTimeout, &fSlave);
  776. //
  777. // Create an edit list for the "All other domains" item
  778. //
  779. CAllOthersDomainInfo* pAllOthers = new CAllOthersDomainInfo(cAddrCount,
  780. pipAddrs,
  781. dwForwardTimeout,
  782. fSlave);
  783. if (pAllOthers != NULL)
  784. {
  785. CDomainForwardersEditInfo* pForwardersInfo = new CDomainForwardersEditInfo(NULL, FALSE);
  786. if (pForwardersInfo != NULL)
  787. {
  788. pForwardersInfo->SetAllOthersDomain(pAllOthers);
  789. pForwardersInfo->SetDataFromRPC(TRUE);
  790. m_EditList.AddTail(pForwardersInfo);
  791. //
  792. // Load the "All other domains" string and add it at the beginning
  793. //
  794. CString szAllOthers;
  795. VERIFY(szAllOthers.LoadString(IDS_OTHER_DOMAINS));
  796. LRESULT lRes = 0;
  797. lRes = SendDlgItemMessage(IDC_DOMAIN_LIST, LB_INSERTSTRING, 0, (LPARAM)(LPCWSTR)szAllOthers);
  798. if (lRes != LB_ERR)
  799. {
  800. SendDlgItemMessage(IDC_DOMAIN_LIST, LB_SETITEMDATA, lRes, (LPARAM)pForwardersInfo);
  801. }
  802. }
  803. }
  804. }
  805. CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_MESSAGE);
  806. if (pStatic != NULL)
  807. {
  808. pStatic->EnableWindow(FALSE);
  809. pStatic->ShowWindow(FALSE);
  810. }
  811. pStatic = (CStatic*)GetDlgItem(IDC_STATIC_ADD_FORWARDERS);
  812. if (pStatic != NULL)
  813. {
  814. pStatic->EnableWindow(TRUE);
  815. pStatic->ShowWindow(TRUE);
  816. }
  817. if (!m_bPostApply)
  818. {
  819. //
  820. // Select the first item in the domain list
  821. //
  822. SendDlgItemMessage(IDC_DOMAIN_LIST, LB_SETCURSEL, 0, 0);
  823. OnDomainSelChange();
  824. }
  825. }
  826. if (pServerNode->GetBuildNumber() < DNS_SRV_BUILD_NUMBER_WHISTLER ||
  827. (pServerNode->GetMajorVersion() <= DNS_SRV_MAJOR_VERSION_NT_5 &&
  828. pServerNode->GetMinorVersion() < DNS_SRV_MINOR_VERSION_WHISTLER))
  829. {
  830. //
  831. // Domain forwarding not available on pre-Whistler servers
  832. //
  833. if (!bServerHasRoot && pServerNode->DoesRecursion())
  834. {
  835. CString szDownlevelServer;
  836. VERIFY(szDownlevelServer.LoadString(IDS_DISABLED_FWDS_DOWNLEVEL));
  837. SetDlgItemText(IDC_STATIC_CAPTION, szDownlevelServer);
  838. }
  839. GetDlgItem(IDC_DOMAIN_ADD_BUTTON)->EnableWindow(FALSE);
  840. GetDlgItem(IDC_DOMAIN_REMOVE_BUTTON)->EnableWindow(FALSE);
  841. }
  842. SetDirty(bWasDirty);
  843. return TRUE;
  844. }
  845. BOOL CDNSServer_DomainForwardersPropertyPage::OnApply()
  846. {
  847. USES_CONVERSION;
  848. CDNSServerPropertyPageHolder* pHolder =
  849. (CDNSServerPropertyPageHolder*)GetHolder();
  850. CComponentDataObject* pComponentData = pHolder->GetComponentData();
  851. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  852. if (!IsDirty())
  853. {
  854. return TRUE;
  855. }
  856. //
  857. // Retrieve the current UI info
  858. //
  859. CListBox* pDomainList = (CListBox*)GetDlgItem(IDC_DOMAIN_LIST);
  860. if (pDomainList != NULL)
  861. {
  862. int iSel = pDomainList->GetCurSel();
  863. if (iSel != LB_ERR)
  864. {
  865. LRESULT lRes = pDomainList->GetItemData(iSel);
  866. if (lRes != LB_ERR)
  867. {
  868. //
  869. // Retrieve the edit info from the list box item
  870. //
  871. CDomainForwardersEditInfo* pInfo = reinterpret_cast<CDomainForwardersEditInfo*>(lRes);
  872. if (pInfo != NULL)
  873. {
  874. //
  875. // Store the previous selection's data before changing the UI.
  876. // This may be NULL during OnInitDialog so check before trying
  877. // to store the info.
  878. //
  879. if (m_pCurrentInfo != NULL)
  880. {
  881. BOOL bSlave = GetSlaveCheck()->GetCheck();
  882. DWORD dwTimeout = m_forwardTimeoutEdit.GetVal();
  883. DWORD cAddrCount = m_forwarderAddressesEditor.GetCount();
  884. DWORD* pArr = (cAddrCount > 0) ? (DWORD*) malloc(sizeof(DWORD)*cAddrCount) : NULL;
  885. if (cAddrCount > 0 && pArr != NULL)
  886. {
  887. int nFilled = 0;
  888. m_forwarderAddressesEditor.GetAddresses(pArr, cAddrCount, &nFilled);
  889. ASSERT(nFilled == (int)cAddrCount);
  890. }
  891. m_pCurrentInfo->Update(bSlave, dwTimeout, cAddrCount, pArr);
  892. }
  893. }
  894. }
  895. }
  896. }
  897. POSITION pos = m_EditList.GetHeadPosition();
  898. while (pos != NULL)
  899. {
  900. CDomainForwardersEditInfo* pInfo = m_EditList.GetNext(pos);
  901. if (pInfo != NULL)
  902. {
  903. DNS_STATUS err = 0;
  904. CString szName;
  905. pInfo->GetDomainName(szName);
  906. DWORD cAddrCount = 0;
  907. PIP_ADDRESS pipAddrs = pInfo->GetIPList(&cAddrCount);
  908. DWORD dwTimeout = pInfo->GetTimeout();
  909. BOOL bSlave = pInfo->IsSlave();
  910. switch (pInfo->GetAction())
  911. {
  912. case CDomainForwardersEditInfo::add:
  913. {
  914. //
  915. // Add the new domain forwarder as a zone
  916. //
  917. ASSERT(!pInfo->IsAllOthers());
  918. if (!pInfo->IsAllOthers())
  919. {
  920. // Every domain that is entered must contain at least
  921. // one IP address of a server to forward to
  922. if (cAddrCount < 1)
  923. {
  924. CString err;
  925. err.Format(IDS_ERRMSG_SERVER_FORWARDER_NO_SERVER, szName);
  926. DNSMessageBox(err, MB_OK);
  927. return FALSE;
  928. }
  929. else
  930. {
  931. err = pServerNode->CreateForwarderZone(szName,
  932. pipAddrs,
  933. cAddrCount,
  934. dwTimeout,
  935. bSlave,
  936. pComponentData);
  937. }
  938. }
  939. }
  940. break;
  941. case CDomainForwardersEditInfo::remove:
  942. {
  943. //
  944. // Delete the zone representing the domain forwarder
  945. //
  946. ASSERT(!pInfo->IsAllOthers());
  947. if (!pInfo->IsAllOthers())
  948. {
  949. BOOL bDeleteFromDS = FALSE;
  950. if (pInfo->GetZoneNode()->GetZoneType() == DNS_ZONE_TYPE_FORWARDER &&
  951. pInfo->IsADIntegrated())
  952. {
  953. if (pServerNode->GetBootMethod() == BOOT_METHOD_DIRECTORY)
  954. {
  955. // ask confirmation on delete from DS
  956. int nRetVal = DNSMessageBox(IDS_MSG_FORWARDER_DELETE_FROM_DS_BOOT3,
  957. MB_YESNO | MB_DEFBUTTON2);
  958. if (nRetVal == IDNO)
  959. {
  960. break;
  961. }
  962. bDeleteFromDS = TRUE;
  963. }
  964. else
  965. {
  966. // ask confirmation on delete from DS
  967. int nRetVal = DNSMessageBox(IDS_MSG_FORWARDER_DELETE_FROM_DS,
  968. MB_YESNOCANCEL | MB_DEFBUTTON3);
  969. if (nRetVal == IDCANCEL)
  970. {
  971. break;
  972. }
  973. bDeleteFromDS = (nRetVal == IDYES);
  974. }
  975. }
  976. err = pInfo->GetZoneNode()->Delete(bDeleteFromDS);
  977. }
  978. }
  979. break;
  980. case CDomainForwardersEditInfo::update:
  981. {
  982. //
  983. // Update the zone representing the domain forwarder
  984. //
  985. if (pInfo->IsAllOthers())
  986. {
  987. //
  988. // write the default forwarder to the server
  989. //
  990. err = pServerNode->ResetForwarders(cAddrCount, pipAddrs, dwTimeout, bSlave);
  991. }
  992. else
  993. {
  994. err = ::DnssrvResetZoneMastersEx(pServerNode->GetRPCName(), // server name
  995. W_TO_UTF8(szName), // forwarder as zone name
  996. cAddrCount,
  997. pipAddrs,
  998. 0); // global masters only
  999. }
  1000. }
  1001. break;
  1002. case CDomainForwardersEditInfo::nochange:
  1003. default:
  1004. break;
  1005. }
  1006. if (err != 0)
  1007. {
  1008. if (err == DNS_ERROR_INVALID_ZONE_TYPE)
  1009. {
  1010. CString szFwdFailed;
  1011. CString szFwdFailedFormat;
  1012. VERIFY(szFwdFailedFormat.LoadString(IDS_MSG_FAIL_CREATE_DOMAIN_FORWARDER));
  1013. szFwdFailed.Format(szFwdFailedFormat, szName);
  1014. DNSMessageBox(szFwdFailed);
  1015. }
  1016. else
  1017. {
  1018. DNSErrorDialog(err, IDS_MSG_SERVER_FORWARDER_UPDATE_FAILED);
  1019. }
  1020. return FALSE;
  1021. }
  1022. pInfo->SetAction(CDomainForwardersEditInfo::nochange);
  1023. }
  1024. } // while
  1025. m_bPostApply = TRUE;
  1026. SetDirty(FALSE);
  1027. return TRUE;
  1028. }
  1029. ///////////////////////////////////////////////////////////////////////////////
  1030. // CDNSServer_AdvancedPropertyPage
  1031. BEGIN_MESSAGE_MAP(CDNSServer_AdvancedPropertyPage, CPropertyPageBase)
  1032. ON_CLBN_CHKCHANGE(IDC_ADVANCED_OPTIONS_LIST, OnAdvancedOptionsListChange)
  1033. ON_CBN_SELCHANGE(IDC_NAME_CHECKING_COMBO, OnComboSelChange)
  1034. ON_CBN_SELCHANGE(IDC_BOOT_METHOD_COMBO, OnComboSelChange)
  1035. ON_BN_CLICKED(IDC_RESET_BUTTON, OnResetButton)
  1036. ON_BN_CLICKED(IDC_CHECK_ENABLE_SCAVENGING, OnEnableScavenging)
  1037. END_MESSAGE_MAP()
  1038. #define ADVANCED_OPTIONS_LISTBOX_ENTRIES (SERVER_REGKEY_ARR_SIZE)
  1039. // boot method constants
  1040. #define BOOT_METHOD_COMBO_ITEM_COUNT 3 // # of options in the combo box
  1041. #define BOOT_METHOD_COMBO_FROM_REGISTRY 0
  1042. #define BOOT_METHOD_COMBO_FROM_FILE 1
  1043. #define BOOT_METHOD_COMBO_FROM_DIRECTORY 2
  1044. #define CHECK_NAMES_COMBO_ITEM_COUNT 4
  1045. CDNSServer_AdvancedPropertyPage::CDNSServer_AdvancedPropertyPage()
  1046. : CPropertyPageBase(IDD_SERVER_ADVANCED_PAGE),
  1047. m_advancedOptionsListBox(ADVANCED_OPTIONS_LISTBOX_ENTRIES)
  1048. {
  1049. }
  1050. void CDNSServer_AdvancedPropertyPage::SetAdvancedOptionsListbox(BOOL* bRegKeyOptionsArr)
  1051. {
  1052. m_advancedOptionsListBox.SetArrValue((DWORD*)bRegKeyOptionsArr,
  1053. ADVANCED_OPTIONS_LISTBOX_ENTRIES);
  1054. }
  1055. void CDNSServer_AdvancedPropertyPage::GetAdvancedOptionsListbox(BOOL* bRegKeyOptionsArr)
  1056. {
  1057. m_advancedOptionsListBox.GetArrValue((DWORD*)bRegKeyOptionsArr,
  1058. ADVANCED_OPTIONS_LISTBOX_ENTRIES);
  1059. }
  1060. void CDNSServer_AdvancedPropertyPage::SetBootMethodComboVal(UCHAR fBootMethod)
  1061. {
  1062. int nIndex = BOOT_METHOD_COMBO_FROM_DIRECTORY; // sensible default
  1063. switch (fBootMethod)
  1064. {
  1065. case BOOT_METHOD_FILE:
  1066. nIndex = BOOT_METHOD_COMBO_FROM_FILE;
  1067. break;
  1068. case BOOT_METHOD_REGISTRY:
  1069. nIndex = BOOT_METHOD_COMBO_FROM_REGISTRY;
  1070. break;
  1071. case BOOT_METHOD_DIRECTORY:
  1072. nIndex = BOOT_METHOD_COMBO_FROM_DIRECTORY;
  1073. break;
  1074. default:
  1075. nIndex = BOOT_METHOD_COMBO_FROM_DIRECTORY;
  1076. break;
  1077. };
  1078. VERIFY(CB_ERR != GetBootMethodCombo()->SetCurSel(nIndex));
  1079. }
  1080. UCHAR CDNSServer_AdvancedPropertyPage::GetBootMethodComboVal()
  1081. {
  1082. int nIndex = BOOT_METHOD_COMBO_FROM_DIRECTORY;
  1083. nIndex = GetBootMethodCombo()->GetCurSel();
  1084. ASSERT(nIndex != CB_ERR);
  1085. UCHAR fBootMethod = BOOT_METHOD_DIRECTORY; // sensible default
  1086. switch (nIndex)
  1087. {
  1088. case BOOT_METHOD_COMBO_FROM_FILE:
  1089. fBootMethod = BOOT_METHOD_FILE;
  1090. break;
  1091. case BOOT_METHOD_COMBO_FROM_REGISTRY:
  1092. fBootMethod = BOOT_METHOD_REGISTRY;
  1093. break;
  1094. case BOOT_METHOD_COMBO_FROM_DIRECTORY:
  1095. fBootMethod = BOOT_METHOD_DIRECTORY;
  1096. break;
  1097. default:
  1098. ASSERT(FALSE);
  1099. };
  1100. return fBootMethod;
  1101. }
  1102. void CDNSServer_AdvancedPropertyPage::SetNameCheckingComboVal(DWORD dwNameChecking)
  1103. {
  1104. int nIndex = DNS_DEFAULT_NAME_CHECK_FLAG;
  1105. switch (dwNameChecking)
  1106. {
  1107. case DNS_ALLOW_RFC_NAMES_ONLY:
  1108. nIndex = 0;
  1109. break;
  1110. case DNS_ALLOW_NONRFC_NAMES:
  1111. nIndex = 1;
  1112. break;
  1113. case DNS_ALLOW_MULTIBYTE_NAMES:
  1114. nIndex = 2;
  1115. break;
  1116. case DNS_ALLOW_ALL_NAMES:
  1117. nIndex = 3;
  1118. break;
  1119. default:
  1120. ASSERT(FALSE);
  1121. }
  1122. VERIFY(CB_ERR != GetNameCheckingCombo()->SetCurSel(nIndex));
  1123. }
  1124. DWORD CDNSServer_AdvancedPropertyPage::GetNameCheckingComboVal()
  1125. {
  1126. int nIndex = 0;
  1127. nIndex = GetNameCheckingCombo()->GetCurSel();
  1128. ASSERT(nIndex != CB_ERR);
  1129. DWORD dw = 0;
  1130. switch (nIndex)
  1131. {
  1132. case 0:
  1133. dw = DNS_ALLOW_RFC_NAMES_ONLY;
  1134. break;
  1135. case 1:
  1136. dw = DNS_ALLOW_NONRFC_NAMES;
  1137. break;
  1138. case 2:
  1139. dw = DNS_ALLOW_MULTIBYTE_NAMES;
  1140. break;
  1141. case 3:
  1142. dw = DNS_ALLOW_ALL_NAMES;
  1143. break;
  1144. default:
  1145. ASSERT(FALSE);
  1146. }
  1147. return dw;
  1148. }
  1149. void CDNSServer_AdvancedPropertyPage::OnEnableScavenging()
  1150. {
  1151. GetDlgItem(IDC_STATIC_SCAVENGE)->EnableWindow(((CButton*)GetDlgItem(IDC_CHECK_ENABLE_SCAVENGING))->GetCheck());
  1152. GetDlgItem(IDC_REFR_INT_EDIT)->EnableWindow(((CButton*)GetDlgItem(IDC_CHECK_ENABLE_SCAVENGING))->GetCheck());
  1153. GetDlgItem(IDC_REFR_INT_COMBO)->EnableWindow(((CButton*)GetDlgItem(IDC_CHECK_ENABLE_SCAVENGING))->GetCheck());
  1154. if (m_scavengingIntervalEditGroup.GetVal() == 0)
  1155. {
  1156. m_scavengingIntervalEditGroup.SetVal(DNS_DEFAULT_SCAVENGING_INTERVAL_ON);
  1157. }
  1158. SetDirty(TRUE);
  1159. }
  1160. void CDNSServer_AdvancedPropertyPage::SetUIData()
  1161. {
  1162. CDNSServerPropertyPageHolder* pHolder =
  1163. (CDNSServerPropertyPageHolder*)GetHolder();
  1164. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1165. // set server version
  1166. CEdit* pVersionEdit = (CEdit*)GetDlgItem(IDC_SERVER_VERSION_EDIT);
  1167. WCHAR szBuffer[128];
  1168. WORD wBuildNumber = pServerNode->GetBuildNumber();
  1169. if (wBuildNumber == 0)
  1170. wsprintf(szBuffer, _T("%d.%d"), pServerNode->GetMajorVersion(),
  1171. pServerNode->GetMinorVersion());
  1172. else
  1173. wsprintf(szBuffer, _T("%d.%d %d (0x%x)"), pServerNode->GetMajorVersion(),
  1174. pServerNode->GetMinorVersion(),
  1175. wBuildNumber, wBuildNumber);
  1176. pVersionEdit->SetWindowText(szBuffer);
  1177. // NOTICE: Assume ordering in the list is the same
  1178. // as in the array. "Name check Flag" and "Boot method" are the last ones
  1179. // in the array and are ignored (separate controls).
  1180. BOOL bRegKeyOptionsArr[SERVER_REGKEY_ARR_SIZE];
  1181. pServerNode->GetAdvancedOptions(bRegKeyOptionsArr);
  1182. SetAdvancedOptionsListbox(bRegKeyOptionsArr);
  1183. SetBootMethodComboVal(pServerNode->GetBootMethod());
  1184. SetNameCheckingComboVal(pServerNode->GetNameCheckFlag());
  1185. ((CButton*)GetDlgItem(IDC_CHECK_ENABLE_SCAVENGING))->SetCheck(pServerNode->GetScavengingState());
  1186. GetDlgItem(IDC_STATIC_SCAVENGE)->EnableWindow(pServerNode->GetScavengingState());
  1187. GetDlgItem(IDC_REFR_INT_EDIT)->EnableWindow(pServerNode->GetScavengingState());
  1188. GetDlgItem(IDC_REFR_INT_COMBO)->EnableWindow(pServerNode->GetScavengingState());
  1189. m_scavengingIntervalEditGroup.SetVal(pServerNode->GetScavengingInterval());
  1190. }
  1191. BOOL CDNSServer_AdvancedPropertyPage::OnInitDialog()
  1192. {
  1193. CPropertyPageBase::OnInitDialog();
  1194. CDNSServerPropertyPageHolder* pHolder =
  1195. (CDNSServerPropertyPageHolder*)GetHolder();
  1196. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1197. VERIFY(m_advancedOptionsListBox.Initialize(IDC_ADVANCED_OPTIONS_LIST,
  1198. IDS_SERVER_ADV_PP_OPTIONS,
  1199. this));
  1200. VERIFY(LoadStringsToComboBox(_Module.GetModuleInstance(),
  1201. GetNameCheckingCombo(),
  1202. IDS_SERVER_NAME_CHECKING_OPTIONS,
  1203. 256,
  1204. CHECK_NAMES_COMBO_ITEM_COUNT));
  1205. VERIFY(LoadStringsToComboBox(_Module.GetModuleInstance(),
  1206. GetBootMethodCombo(),
  1207. IDS_SERVER_BOOT_METHOD_OPTIONS,
  1208. 256,
  1209. BOOT_METHOD_COMBO_ITEM_COUNT));
  1210. if (!pServerNode->HasServerInfo())
  1211. {
  1212. EnableWindow(FALSE);
  1213. return TRUE;
  1214. }
  1215. m_scavengingIntervalEditGroup.m_pPage2 = this;
  1216. VERIFY(m_scavengingIntervalEditGroup.Initialize(this,
  1217. IDC_REFR_INT_EDIT, IDC_REFR_INT_COMBO,IDS_TIME_AGING_INTERVAL_UNITS));
  1218. SetUIData();
  1219. return TRUE; // return TRUE unless you set the focus to a control
  1220. // EXCEPTION: OCX Property Pages should return FALSE
  1221. }
  1222. BOOL _HandleAvancedOptionsErrors(DNS_STATUS* dwRegKeyOptionsErrorArr)
  1223. {
  1224. BOOL bAllFine = TRUE;
  1225. // check for errors in the array
  1226. for (UINT iKey=0; iKey < SERVER_REGKEY_ARR_SIZE; iKey++)
  1227. {
  1228. if (dwRegKeyOptionsErrorArr[iKey] != 0)
  1229. {
  1230. bAllFine = FALSE;
  1231. break;
  1232. }
  1233. }
  1234. if (bAllFine)
  1235. return TRUE; // no error condition
  1236. // load the string array to get the option key name
  1237. CString szBuf;
  1238. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1239. VERIFY(szBuf.LoadString(IDS_SERVER_ADV_PP_OPTIONS));
  1240. LPWSTR* lpszArr = (LPWSTR*)malloc(sizeof(LPWSTR*)*SERVER_REGKEY_ARR_SIZE);
  1241. if (!lpszArr)
  1242. {
  1243. return FALSE;
  1244. }
  1245. UINT nArrEntries;
  1246. ParseNewLineSeparatedString(szBuf.GetBuffer(1),lpszArr, &nArrEntries);
  1247. szBuf.ReleaseBuffer();
  1248. ASSERT(nArrEntries == SERVER_REGKEY_ARR_SIZE);
  1249. CString szFmt;
  1250. szFmt.LoadString(IDS_MSG_SERVER_FAIL_ADV_PROP_FMT);
  1251. CString szMsg;
  1252. for (iKey=0; iKey < SERVER_REGKEY_ARR_SIZE; iKey++)
  1253. {
  1254. if (dwRegKeyOptionsErrorArr[iKey] != 0)
  1255. {
  1256. szMsg.Format((LPCWSTR)szFmt, lpszArr[iKey]);
  1257. DNSErrorDialog(dwRegKeyOptionsErrorArr[iKey], szMsg);
  1258. }
  1259. }
  1260. if (lpszArr)
  1261. {
  1262. free(lpszArr);
  1263. lpszArr = 0;
  1264. }
  1265. return FALSE; // we had an error condition
  1266. }
  1267. BOOL CDNSServer_AdvancedPropertyPage::OnApply()
  1268. {
  1269. if (!IsDirty())
  1270. return TRUE;
  1271. CDNSServerPropertyPageHolder* pHolder =
  1272. (CDNSServerPropertyPageHolder*)GetHolder();
  1273. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1274. // get data from the UI
  1275. BOOL bRegKeyOptionsArr[SERVER_REGKEY_ARR_SIZE];
  1276. ZeroMemory(bRegKeyOptionsArr, sizeof(bRegKeyOptionsArr));
  1277. GetAdvancedOptionsListbox(bRegKeyOptionsArr);
  1278. UCHAR fBootMethod = GetBootMethodComboVal();
  1279. DWORD dwNameCheckFlag = GetNameCheckingComboVal();
  1280. BOOL bScavengingState = ((CButton*)GetDlgItem(IDC_CHECK_ENABLE_SCAVENGING))->GetCheck();
  1281. DWORD dwScavengingInterval = m_scavengingIntervalEditGroup.GetVal();
  1282. // write data to the server
  1283. DNS_STATUS dwRegKeyOptionsErrorArr[SERVER_REGKEY_ARR_SIZE];
  1284. ZeroMemory(dwRegKeyOptionsErrorArr, sizeof(dwRegKeyOptionsErrorArr));
  1285. DNS_STATUS dwErr = pServerNode->ResetAdvancedOptions(bRegKeyOptionsArr, dwRegKeyOptionsErrorArr);
  1286. if (dwErr != 0)
  1287. {
  1288. DNSErrorDialog(dwErr, IDS_MSG_SERVER_NO_ADVANCED_OPTIONS);
  1289. return FALSE;
  1290. }
  1291. if (!_HandleAvancedOptionsErrors(dwRegKeyOptionsErrorArr))
  1292. return FALSE;
  1293. dwErr = pServerNode->ResetBootMethod(fBootMethod);
  1294. if (dwErr != 0)
  1295. {
  1296. DNSErrorDialog(dwErr, IDS_MSG_SERVER_NO_BOOT_METHOD);
  1297. return FALSE;
  1298. }
  1299. dwErr = pServerNode->ResetNameCheckFlag(dwNameCheckFlag);
  1300. if (dwErr != 0)
  1301. {
  1302. DNSErrorDialog(dwErr, IDS_MSG_SERVER_NO_NAME_CHECKING);
  1303. return FALSE;
  1304. }
  1305. /*
  1306. dwErr = pServerNode->ResetScavengingState(bScavengingState);
  1307. if (dwErr != 0)
  1308. {
  1309. DNSErrorDialog(dwErr, IDS_MSG_SERVER_SCAVENGING_STATE);
  1310. return FALSE;
  1311. }
  1312. */
  1313. if (bScavengingState)
  1314. {
  1315. dwErr = pServerNode->ResetScavengingInterval(dwScavengingInterval);
  1316. }
  1317. else
  1318. {
  1319. dwErr = pServerNode->ResetScavengingInterval(0);
  1320. }
  1321. if (dwErr != 0)
  1322. {
  1323. DNSErrorDialog(dwErr, IDS_MSG_SERVER_SCAVENGING_INTERVAL);
  1324. return FALSE;
  1325. }
  1326. // all is fine
  1327. SetDirty(FALSE);
  1328. return TRUE;
  1329. }
  1330. void CDNSServer_AdvancedPropertyPage::OnResetButton()
  1331. {
  1332. BOOL bRegKeyOptArrDef[SERVER_REGKEY_ARR_SIZE];
  1333. bRegKeyOptArrDef[SERVER_REGKEY_ARR_INDEX_NO_RECURSION] = DNS_DEFAULT_NO_RECURSION;
  1334. bRegKeyOptArrDef[SERVER_REGKEY_ARR_INDEX_BIND_SECONDARIES] = DNS_DEFAULT_BIND_SECONDARIES;
  1335. bRegKeyOptArrDef[SERVER_REGKEY_ARR_INDEX_STRICT_FILE_PARSING] = DNS_DEFAULT_STRICT_FILE_PARSING;
  1336. bRegKeyOptArrDef[SERVER_REGKEY_ARR_INDEX_ROUND_ROBIN] = DNS_DEFAULT_ROUND_ROBIN;
  1337. bRegKeyOptArrDef[SERVER_REGKEY_ARR_LOCAL_NET_PRIORITY] = DNS_DEFAULT_LOCAL_NET_PRIORITY;
  1338. bRegKeyOptArrDef[SERVER_REGKEY_ARR_CACHE_POLLUTION] = FALSE;
  1339. UCHAR fBootMethod = BOOT_METHOD_DIRECTORY;
  1340. SetAdvancedOptionsListbox(bRegKeyOptArrDef);
  1341. SetBootMethodComboVal(fBootMethod);
  1342. SetNameCheckingComboVal(DNS_DEFAULT_NAME_CHECK_FLAG);
  1343. BOOL bDefaultScavengingState = DNS_DEFAULT_SCAVENGING_INTERVAL > 0;
  1344. ((CButton*)GetDlgItem(IDC_CHECK_ENABLE_SCAVENGING))->SetCheck(bDefaultScavengingState);
  1345. GetDlgItem(IDC_STATIC_SCAVENGE)->EnableWindow(bDefaultScavengingState);
  1346. GetDlgItem(IDC_REFR_INT_EDIT)->EnableWindow(bDefaultScavengingState);
  1347. GetDlgItem(IDC_REFR_INT_COMBO)->EnableWindow(bDefaultScavengingState);
  1348. m_scavengingIntervalEditGroup.SetVal(DNS_DEFAULT_SCAVENGING_INTERVAL);
  1349. SetDirty(TRUE);
  1350. }
  1351. ///////////////////////////////////////////////////////////////////////////////
  1352. // CIPFilterDialog
  1353. class CIPFilterDialog : public CHelpDialog
  1354. {
  1355. public:
  1356. CIPFilterDialog(PIP_ARRAY pIpArray, CComponentDataObject* pComponentData)
  1357. : CHelpDialog(IDD_IP_FILTER_DIALOG, pComponentData),
  1358. m_pIPFilterList(pIpArray),
  1359. m_pComponentData(pComponentData)
  1360. {}
  1361. ~CIPFilterDialog() {}
  1362. virtual BOOL OnInitDialog();
  1363. virtual void OnOK();
  1364. PIP_ARRAY GetIPFilter() { return m_pIPFilterList; }
  1365. virtual void SetDirty(BOOL bDirty = TRUE);
  1366. private:
  1367. class CFilterAddressesIPEditor : public CIPEditor
  1368. {
  1369. public:
  1370. CFilterAddressesIPEditor() : CIPEditor(TRUE) {}
  1371. virtual void OnChangeData();
  1372. };
  1373. CFilterAddressesIPEditor m_filterAddressesEditor;
  1374. PIP_ARRAY m_pIPFilterList;
  1375. CComponentDataObject* m_pComponentData;
  1376. DECLARE_MESSAGE_MAP()
  1377. };
  1378. void CIPFilterDialog::CFilterAddressesIPEditor::OnChangeData()
  1379. {
  1380. //
  1381. // Set the dialog dirty
  1382. //
  1383. CIPFilterDialog* pDialog = (CIPFilterDialog*)GetParentWnd();
  1384. pDialog->SetDirty(TRUE);
  1385. }
  1386. BEGIN_MESSAGE_MAP(CIPFilterDialog, CHelpDialog)
  1387. END_MESSAGE_MAP()
  1388. BOOL CIPFilterDialog::OnInitDialog()
  1389. {
  1390. CHelpDialog::OnInitDialog();
  1391. //
  1392. // initialize controls
  1393. //
  1394. VERIFY(m_filterAddressesEditor.Initialize(this,
  1395. this,
  1396. IDC_BUTTON_UP,
  1397. IDC_BUTTON_DOWN,
  1398. IDC_BUTTON_ADD,
  1399. IDC_BUTTON_REMOVE,
  1400. IDC_IPEDIT,
  1401. IDC_LIST));
  1402. if (m_pIPFilterList != NULL)
  1403. {
  1404. m_filterAddressesEditor.AddAddresses(m_pIPFilterList->AddrArray, m_pIPFilterList->AddrCount);
  1405. }
  1406. SetDirty(FALSE);
  1407. return TRUE;
  1408. }
  1409. void CIPFilterDialog::SetDirty(BOOL bDirty)
  1410. {
  1411. GetDlgItem(IDOK)->EnableWindow(bDirty);
  1412. }
  1413. void CIPFilterDialog::OnOK()
  1414. {
  1415. ULONG cAddress = m_filterAddressesEditor.GetCount();
  1416. PIP_ARRAY aipAddresses = (cAddress > 0) ? (PIP_ARRAY) malloc(sizeof(DWORD)*(cAddress + 1)) : NULL;
  1417. if (aipAddresses != NULL && cAddress > 0)
  1418. {
  1419. int nFilled = 0;
  1420. aipAddresses->AddrCount = cAddress;
  1421. m_filterAddressesEditor.GetAddresses(aipAddresses->AddrArray, cAddress, &nFilled);
  1422. ASSERT(nFilled == (int)cAddress);
  1423. }
  1424. m_pIPFilterList = aipAddresses;
  1425. CHelpDialog::OnOK();
  1426. }
  1427. ///////////////////////////////////////////////////////////////////////////////
  1428. // CDNSServer_DebugLoggingPropertyPage
  1429. BEGIN_MESSAGE_MAP(CDNSServer_DebugLoggingPropertyPage, CPropertyPageBase)
  1430. ON_BN_CLICKED(IDC_DEBUG_LOGGING_CHECK, OnLoggingCheck)
  1431. ON_BN_CLICKED(IDC_SEND_CHECK, OnSendCheck)
  1432. ON_BN_CLICKED(IDC_RECEIVE_CHECK, OnReceiveCheck)
  1433. ON_BN_CLICKED(IDC_QUERIES_CHECK, OnQueriesCheck)
  1434. ON_BN_CLICKED(IDC_NOTIFIES_CHECK, OnNotifiesCheck)
  1435. ON_BN_CLICKED(IDC_UPDATES_CHECK, OnUpdatesCheck)
  1436. ON_BN_CLICKED(IDC_REQUEST_CHECK, OnRequestCheck)
  1437. ON_BN_CLICKED(IDC_RESPONSE_CHECK, OnResponseCheck)
  1438. ON_BN_CLICKED(IDC_UDP_CHECK, OnUDPCheck)
  1439. ON_BN_CLICKED(IDC_TCP_CHECK, OnTCPCheck)
  1440. ON_BN_CLICKED(IDC_DETAIL_CHECK, OnDetailCheck)
  1441. ON_BN_CLICKED(IDC_FILTERING_CHECK, OnFilterCheck)
  1442. ON_BN_CLICKED(IDC_FILTER_BUTTON, OnFilterButton)
  1443. ON_EN_CHANGE(IDC_LOGFILE_EDIT, OnLogFileChange)
  1444. ON_EN_CHANGE(IDC_MAX_SIZE_EDIT, OnMaxSizeChange)
  1445. END_MESSAGE_MAP()
  1446. CDNSServer_DebugLoggingPropertyPage::CDNSServer_DebugLoggingPropertyPage()
  1447. : CPropertyPageBase(IDD_SERVER_DEBUG_LOGGING_PAGE),
  1448. m_dwLogLevel(0),
  1449. m_pIPFilterList(NULL),
  1450. m_dwMaxSize(0),
  1451. m_bOnSetUIData(FALSE),
  1452. m_bMaxSizeDirty(FALSE),
  1453. m_bLogFileDirty(FALSE),
  1454. m_bFilterDirty(FALSE),
  1455. m_bOwnIPListMemory(FALSE),
  1456. m_bNotWhistler(FALSE),
  1457. m_bOptionsDirty(FALSE)
  1458. {
  1459. m_szLogFileName = L"";
  1460. }
  1461. CDNSServer_DebugLoggingPropertyPage::~CDNSServer_DebugLoggingPropertyPage()
  1462. {
  1463. if (m_bOwnIPListMemory && m_pIPFilterList != NULL)
  1464. {
  1465. free(m_pIPFilterList);
  1466. m_pIPFilterList = NULL;
  1467. }
  1468. }
  1469. typedef struct _LoggingOption
  1470. {
  1471. DWORD dwOption;
  1472. UINT nControlID;
  1473. } LOGGING_OPTION, *PLOGGING_OPTION;
  1474. //
  1475. // NOTE: if the resource IDs of the checkboxes are changed,
  1476. // then the IDs in the table below need to be changed too.
  1477. //
  1478. LOGGING_OPTION g_loggingOptions[] =
  1479. {
  1480. { DNS_LOG_LEVEL_QUERY, IDC_QUERIES_CHECK },
  1481. { DNS_LOG_LEVEL_NOTIFY, IDC_NOTIFIES_CHECK },
  1482. { DNS_LOG_LEVEL_UPDATE, IDC_UPDATES_CHECK },
  1483. { DNS_LOG_LEVEL_QUESTIONS, IDC_REQUEST_CHECK },
  1484. { DNS_LOG_LEVEL_ANSWERS, IDC_RESPONSE_CHECK },
  1485. { DNS_LOG_LEVEL_SEND, IDC_SEND_CHECK },
  1486. { DNS_LOG_LEVEL_RECV, IDC_RECEIVE_CHECK },
  1487. { DNS_LOG_LEVEL_UDP, IDC_UDP_CHECK },
  1488. { DNS_LOG_LEVEL_TCP, IDC_TCP_CHECK },
  1489. { DNS_LOG_LEVEL_FULL_PACKETS, IDC_DETAIL_CHECK }
  1490. };
  1491. #define DEFAULT_LOGGING_OPTIONS (DNS_LOG_LEVEL_SEND | \
  1492. DNS_LOG_LEVEL_RECV | \
  1493. DNS_LOG_LEVEL_UDP | \
  1494. DNS_LOG_LEVEL_TCP | \
  1495. DNS_LOG_LEVEL_QUERY | \
  1496. DNS_LOG_LEVEL_UPDATE | \
  1497. DNS_LOG_LEVEL_QUESTIONS | \
  1498. DNS_LOG_LEVEL_ANSWERS )
  1499. void CDNSServer_DebugLoggingPropertyPage::OnLoggingCheck()
  1500. {
  1501. BOOL bLogging = SendDlgItemMessage(IDC_DEBUG_LOGGING_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1502. EnableLogging(bLogging);
  1503. if (bLogging &&
  1504. m_dwLogLevel == 0 &&
  1505. !AreOptionsDirty())
  1506. {
  1507. ResetToDefaults();
  1508. }
  1509. SetDirty(TRUE);
  1510. }
  1511. void CDNSServer_DebugLoggingPropertyPage::OnSendCheck()
  1512. {
  1513. BOOL bOutgoing = SendDlgItemMessage(IDC_SEND_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1514. BOOL bIncoming = SendDlgItemMessage(IDC_RECEIVE_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1515. if (!bOutgoing && !bIncoming)
  1516. {
  1517. SendDlgItemMessage(IDC_RECEIVE_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1518. GetDlgItem(IDC_RECEIVE_CHECK)->SetFocus();
  1519. }
  1520. SetOptionsDirty();
  1521. SetDirty(TRUE);
  1522. }
  1523. void CDNSServer_DebugLoggingPropertyPage::OnReceiveCheck()
  1524. {
  1525. BOOL bOutgoing = SendDlgItemMessage(IDC_SEND_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1526. BOOL bIncoming = SendDlgItemMessage(IDC_RECEIVE_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1527. if (!bOutgoing && !bIncoming)
  1528. {
  1529. SendDlgItemMessage(IDC_SEND_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1530. GetDlgItem(IDC_SEND_CHECK)->SetFocus();
  1531. }
  1532. SetOptionsDirty();
  1533. SetDirty(TRUE);
  1534. }
  1535. void CDNSServer_DebugLoggingPropertyPage::OnQueriesCheck()
  1536. {
  1537. BOOL bQueries = SendDlgItemMessage(IDC_QUERIES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1538. BOOL bNotifies = SendDlgItemMessage(IDC_NOTIFIES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1539. BOOL bUpdates = SendDlgItemMessage(IDC_UPDATES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1540. if (!bQueries && !bNotifies && !bUpdates)
  1541. {
  1542. SendDlgItemMessage(IDC_UPDATES_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1543. GetDlgItem(IDC_UPDATES_CHECK)->SetFocus();
  1544. }
  1545. SetOptionsDirty();
  1546. SetDirty(TRUE);
  1547. }
  1548. void CDNSServer_DebugLoggingPropertyPage::OnUpdatesCheck()
  1549. {
  1550. BOOL bQueries = SendDlgItemMessage(IDC_QUERIES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1551. BOOL bNotifies = SendDlgItemMessage(IDC_NOTIFIES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1552. BOOL bUpdates = SendDlgItemMessage(IDC_UPDATES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1553. if (!bQueries && !bNotifies && !bUpdates)
  1554. {
  1555. SendDlgItemMessage(IDC_NOTIFIES_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1556. GetDlgItem(IDC_NOTIFIES_CHECK)->SetFocus();
  1557. }
  1558. SetOptionsDirty();
  1559. SetDirty(TRUE);
  1560. }
  1561. void CDNSServer_DebugLoggingPropertyPage::OnNotifiesCheck()
  1562. {
  1563. BOOL bQueries = SendDlgItemMessage(IDC_QUERIES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1564. BOOL bNotifies = SendDlgItemMessage(IDC_NOTIFIES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1565. BOOL bUpdates = SendDlgItemMessage(IDC_UPDATES_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1566. if (!bQueries && !bNotifies && !bUpdates)
  1567. {
  1568. SendDlgItemMessage(IDC_QUERIES_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1569. GetDlgItem(IDC_QUERIES_CHECK)->SetFocus();
  1570. }
  1571. SetOptionsDirty();
  1572. SetDirty(TRUE);
  1573. }
  1574. void CDNSServer_DebugLoggingPropertyPage::OnRequestCheck()
  1575. {
  1576. BOOL bRequest = SendDlgItemMessage(IDC_REQUEST_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1577. BOOL bResponse = SendDlgItemMessage(IDC_RESPONSE_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1578. if (!bRequest && !bResponse)
  1579. {
  1580. SendDlgItemMessage(IDC_RESPONSE_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1581. GetDlgItem(IDC_RESPONSE_CHECK)->SetFocus();
  1582. }
  1583. SetOptionsDirty();
  1584. SetDirty(TRUE);
  1585. }
  1586. void CDNSServer_DebugLoggingPropertyPage::OnResponseCheck()
  1587. {
  1588. BOOL bRequest = SendDlgItemMessage(IDC_REQUEST_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1589. BOOL bResponse = SendDlgItemMessage(IDC_RESPONSE_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1590. if (!bRequest && !bResponse)
  1591. {
  1592. SendDlgItemMessage(IDC_REQUEST_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1593. GetDlgItem(IDC_REQUEST_CHECK)->SetFocus();
  1594. }
  1595. SetOptionsDirty();
  1596. SetDirty(TRUE);
  1597. }
  1598. void CDNSServer_DebugLoggingPropertyPage::OnUDPCheck()
  1599. {
  1600. BOOL bUDP = SendDlgItemMessage(IDC_UDP_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1601. BOOL bTCP = SendDlgItemMessage(IDC_TCP_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1602. if (!bUDP && !bTCP)
  1603. {
  1604. SendDlgItemMessage(IDC_TCP_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1605. GetDlgItem(IDC_TCP_CHECK)->SetFocus();
  1606. }
  1607. SetOptionsDirty();
  1608. SetDirty(TRUE);
  1609. }
  1610. void CDNSServer_DebugLoggingPropertyPage::OnTCPCheck()
  1611. {
  1612. BOOL bUDP = SendDlgItemMessage(IDC_UDP_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1613. BOOL bTCP = SendDlgItemMessage(IDC_TCP_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED;
  1614. if (!bUDP && !bTCP)
  1615. {
  1616. SendDlgItemMessage(IDC_UDP_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1617. GetDlgItem(IDC_UDP_CHECK)->SetFocus();
  1618. }
  1619. SetOptionsDirty();
  1620. SetDirty(TRUE);
  1621. }
  1622. void CDNSServer_DebugLoggingPropertyPage::OnDetailCheck()
  1623. {
  1624. SetOptionsDirty();
  1625. SetDirty(TRUE);
  1626. }
  1627. void CDNSServer_DebugLoggingPropertyPage::SetOptionsDirty(BOOL bDirty)
  1628. {
  1629. m_bOptionsDirty = bDirty;
  1630. }
  1631. BOOL CDNSServer_DebugLoggingPropertyPage::AreOptionsDirty()
  1632. {
  1633. return m_bOptionsDirty;
  1634. }
  1635. void CDNSServer_DebugLoggingPropertyPage::EnableLogging(BOOL bEnable)
  1636. {
  1637. //
  1638. // NOTE: the curly brace icons must be enabled before
  1639. // the other controls so that they get painted first
  1640. // and the other controls can paint over top of them
  1641. // If not, the text of the controls gets cut off
  1642. //
  1643. GetDlgItem(IDC_BRACE1_STATIC)->EnableWindow(bEnable);
  1644. GetDlgItem(IDC_SELECT1_STATIC)->EnableWindow(bEnable);
  1645. GetDlgItem(IDC_BRACE2_STATIC)->EnableWindow(bEnable);
  1646. GetDlgItem(IDC_SELECT2_STATIC)->EnableWindow(bEnable);
  1647. GetDlgItem(IDC_BRACE3_STATIC)->EnableWindow(bEnable);
  1648. GetDlgItem(IDC_SELECT3_STATIC)->EnableWindow(bEnable);
  1649. GetDlgItem(IDC_BRACE4_STATIC)->EnableWindow(bEnable);
  1650. GetDlgItem(IDC_SELECT4_STATIC)->EnableWindow(bEnable);
  1651. GetDlgItem(IDC_DIRECTION_STATIC)->EnableWindow(bEnable);
  1652. GetDlgItem(IDC_SEND_CHECK)->EnableWindow(bEnable);
  1653. GetDlgItem(IDC_RECEIVE_CHECK)->EnableWindow(bEnable);
  1654. GetDlgItem(IDC_CONTENTS_STATIC)->EnableWindow(bEnable);
  1655. GetDlgItem(IDC_QUERIES_CHECK)->EnableWindow(bEnable);
  1656. GetDlgItem(IDC_NOTIFIES_CHECK)->EnableWindow(bEnable);
  1657. GetDlgItem(IDC_UPDATES_CHECK)->EnableWindow(bEnable);
  1658. GetDlgItem(IDC_TRANSPORT_STATIC)->EnableWindow(bEnable);
  1659. GetDlgItem(IDC_UDP_CHECK)->EnableWindow(bEnable);
  1660. GetDlgItem(IDC_TCP_CHECK)->EnableWindow(bEnable);
  1661. GetDlgItem(IDC_TYPE_STATIC)->EnableWindow(bEnable);
  1662. GetDlgItem(IDC_REQUEST_CHECK)->EnableWindow(bEnable);
  1663. GetDlgItem(IDC_RESPONSE_CHECK)->EnableWindow(bEnable);
  1664. GetDlgItem(IDC_OPTIONS_STATIC)->EnableWindow(bEnable);
  1665. GetDlgItem(IDC_DETAIL_CHECK)->EnableWindow(bEnable);
  1666. //
  1667. // All controls after this point will be disabled no matter
  1668. // what the input if we are not targetting a Whistler or greater
  1669. // server
  1670. //
  1671. if (m_bNotWhistler)
  1672. {
  1673. bEnable = FALSE;
  1674. }
  1675. GetDlgItem(IDC_FILTERING_CHECK)->EnableWindow(bEnable);
  1676. GetDlgItem(IDC_FILTER_BUTTON)->EnableWindow(
  1677. SendDlgItemMessage(IDC_FILTERING_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED
  1678. && bEnable);
  1679. GetDlgItem(IDC_LOG_STATIC)->EnableWindow(bEnable);
  1680. GetDlgItem(IDC_FILENAME_STATIC)->EnableWindow(bEnable);
  1681. GetDlgItem(IDC_LOGFILE_EDIT)->EnableWindow(bEnable);
  1682. GetDlgItem(IDC_MAXSIZE_STATIC)->EnableWindow(bEnable);
  1683. GetDlgItem(IDC_MAX_SIZE_EDIT)->EnableWindow(bEnable);
  1684. }
  1685. void CDNSServer_DebugLoggingPropertyPage::ResetToDefaults()
  1686. {
  1687. SetUIFromOptions(DEFAULT_LOGGING_OPTIONS);
  1688. }
  1689. void CDNSServer_DebugLoggingPropertyPage::OnFilterCheck()
  1690. {
  1691. LRESULT lRes = SendDlgItemMessage(IDC_FILTERING_CHECK, BM_GETCHECK, 0, 0);
  1692. GetDlgItem(IDC_FILTER_BUTTON)->EnableWindow(lRes == BST_CHECKED);
  1693. if (!m_bOnSetUIData)
  1694. {
  1695. m_bFilterDirty = TRUE;
  1696. SetDirty(TRUE);
  1697. }
  1698. }
  1699. void CDNSServer_DebugLoggingPropertyPage::OnFilterButton()
  1700. {
  1701. CIPFilterDialog filterDialog(m_pIPFilterList, GetHolder()->GetComponentData());
  1702. if (filterDialog.DoModal() == IDOK)
  1703. {
  1704. if (m_bOwnIPListMemory && m_pIPFilterList != NULL)
  1705. {
  1706. free(m_pIPFilterList);
  1707. m_pIPFilterList = NULL;
  1708. }
  1709. m_pIPFilterList = filterDialog.GetIPFilter();
  1710. m_bOwnIPListMemory = TRUE;
  1711. m_bFilterDirty = TRUE;
  1712. SetDirty(TRUE);
  1713. }
  1714. }
  1715. void CDNSServer_DebugLoggingPropertyPage::OnLogFileChange()
  1716. {
  1717. if (!m_bOnSetUIData)
  1718. {
  1719. m_bLogFileDirty = TRUE;
  1720. SetDirty(TRUE);
  1721. }
  1722. }
  1723. void CDNSServer_DebugLoggingPropertyPage::OnMaxSizeChange()
  1724. {
  1725. if (!m_bOnSetUIData)
  1726. {
  1727. m_bMaxSizeDirty = TRUE;
  1728. SetDirty(TRUE);
  1729. }
  1730. }
  1731. void CDNSServer_DebugLoggingPropertyPage::SetUIData()
  1732. {
  1733. m_bOnSetUIData = TRUE;
  1734. CPropertyPageBase::OnInitDialog();
  1735. CDNSServerPropertyPageHolder* pHolder =
  1736. (CDNSServerPropertyPageHolder*)GetHolder();
  1737. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1738. m_dwLogLevel = pServerNode->GetLogLevelFlag();
  1739. m_dwMaxSize = pServerNode->GetDebugLogFileMaxSize();
  1740. if (m_bOwnIPListMemory && m_pIPFilterList)
  1741. {
  1742. free(m_pIPFilterList);
  1743. m_pIPFilterList = NULL;
  1744. m_bOwnIPListMemory = FALSE;
  1745. }
  1746. m_pIPFilterList = pServerNode->GetDebugLogFilterList();
  1747. m_szLogFileName = pServerNode->GetDebugLogFileName();
  1748. if (m_dwLogLevel)
  1749. {
  1750. SendDlgItemMessage(IDC_DEBUG_LOGGING_CHECK, BM_SETCHECK, BST_CHECKED, 0);
  1751. SetUIFromOptions(m_dwLogLevel);
  1752. }
  1753. else
  1754. {
  1755. SendDlgItemMessage(IDC_DEBUG_LOGGING_CHECK, BM_SETCHECK, BST_UNCHECKED, 0);
  1756. ResetToDefaults();
  1757. }
  1758. //
  1759. // Set log file name
  1760. //
  1761. SetDlgItemText(IDC_LOGFILE_EDIT, m_szLogFileName);
  1762. //
  1763. // Set max file size
  1764. //
  1765. SetDlgItemInt(IDC_MAX_SIZE_EDIT, m_dwMaxSize);
  1766. //
  1767. // Set filter check
  1768. //
  1769. if (m_pIPFilterList != NULL)
  1770. {
  1771. SendDlgItemMessage(IDC_FILTERING_CHECK, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
  1772. GetDlgItem(IDC_FILTER_BUTTON)->EnableWindow(TRUE);
  1773. }
  1774. else
  1775. {
  1776. SendDlgItemMessage(IDC_FILTERING_CHECK, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
  1777. GetDlgItem(IDC_FILTER_BUTTON)->EnableWindow(FALSE);
  1778. }
  1779. //
  1780. // Now enable/disable the controls based on the options
  1781. //
  1782. EnableLogging(m_dwLogLevel > 0);
  1783. m_bOnSetUIData = FALSE;
  1784. }
  1785. void CDNSServer_DebugLoggingPropertyPage::SetUIFromOptions(DWORD dwOptions)
  1786. {
  1787. //
  1788. // Set logging options
  1789. //
  1790. for (UINT idx = 0; idx < ARRAYLENGTH(g_loggingOptions); idx++)
  1791. {
  1792. if (g_loggingOptions[idx].dwOption & dwOptions)
  1793. {
  1794. SendDlgItemMessage(g_loggingOptions[idx].nControlID, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
  1795. }
  1796. else
  1797. {
  1798. SendDlgItemMessage(g_loggingOptions[idx].nControlID, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
  1799. }
  1800. }
  1801. }
  1802. void CDNSServer_DebugLoggingPropertyPage::GetUIData(BOOL)
  1803. {
  1804. if (SendDlgItemMessage(IDC_DEBUG_LOGGING_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED)
  1805. {
  1806. //
  1807. // Get logging options
  1808. //
  1809. for (UINT idx = 0; idx < ARRAYLENGTH(g_loggingOptions); idx++)
  1810. {
  1811. LRESULT lCheck = SendDlgItemMessage(g_loggingOptions[idx].nControlID, BM_GETCHECK, 0, 0);
  1812. if (lCheck == BST_CHECKED)
  1813. {
  1814. m_dwLogLevel |= g_loggingOptions[idx].dwOption;
  1815. }
  1816. else
  1817. {
  1818. m_dwLogLevel &= ~(g_loggingOptions[idx].dwOption);
  1819. }
  1820. }
  1821. //
  1822. // Get log file name
  1823. //
  1824. GetDlgItemText(IDC_LOGFILE_EDIT, m_szLogFileName);
  1825. //
  1826. // Get max file size
  1827. //
  1828. BOOL bTrans = FALSE;
  1829. m_dwMaxSize = GetDlgItemInt(IDC_MAX_SIZE_EDIT, &bTrans, FALSE);
  1830. //
  1831. // Note: the filter IP addresses will be set when returning from the filter dialog
  1832. //
  1833. }
  1834. else
  1835. {
  1836. m_dwLogLevel = 0;
  1837. }
  1838. }
  1839. BOOL CDNSServer_DebugLoggingPropertyPage::OnInitDialog()
  1840. {
  1841. CPropertyPageBase::OnInitDialog();
  1842. CDNSServerPropertyPageHolder* pHolder =
  1843. (CDNSServerPropertyPageHolder*)GetHolder();
  1844. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1845. //
  1846. // Retrieve necessary data from server
  1847. //
  1848. if (!pServerNode->HasServerInfo())
  1849. {
  1850. EnableWindow(FALSE);
  1851. return TRUE;
  1852. }
  1853. //
  1854. // Limit the file size to 10 characters (MAX_INT is 10 characters)
  1855. //
  1856. SendDlgItemMessage(IDC_MAX_SIZE_EDIT, EM_SETLIMITTEXT, (WPARAM)10, 0);
  1857. SetUIData();
  1858. m_bMaxSizeDirty = FALSE;
  1859. m_bLogFileDirty = FALSE;
  1860. m_bFilterDirty = FALSE;
  1861. if (pServerNode->GetBuildNumber() < DNS_SRV_BUILD_NUMBER_WHISTLER ||
  1862. (pServerNode->GetMajorVersion() <= DNS_SRV_MAJOR_VERSION_NT_5 &&
  1863. pServerNode->GetMinorVersion() < DNS_SRV_MINOR_VERSION_WHISTLER))
  1864. {
  1865. //
  1866. // These debug options are not available on pre-Whistler servers
  1867. //
  1868. m_bNotWhistler = TRUE;
  1869. GetDlgItem(IDC_FILTERING_CHECK)->EnableWindow(FALSE);
  1870. GetDlgItem(IDC_MAX_SIZE_EDIT)->EnableWindow(FALSE);
  1871. GetDlgItem(IDC_LOGFILE_EDIT)->EnableWindow(FALSE);
  1872. GetDlgItem(IDC_FILENAME_STATIC)->EnableWindow(FALSE);
  1873. GetDlgItem(IDC_MAXSIZE_STATIC)->EnableWindow(FALSE);
  1874. }
  1875. SetDirty(FALSE);
  1876. return TRUE; // return TRUE unless you set the focus to a control
  1877. // EXCEPTION: OCX Property Pages should return FALSE
  1878. }
  1879. BOOL CDNSServer_DebugLoggingPropertyPage::OnApply()
  1880. {
  1881. if (!IsDirty())
  1882. return TRUE;
  1883. CDNSServerPropertyPageHolder* pHolder =
  1884. (CDNSServerPropertyPageHolder*)GetHolder();
  1885. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1886. GetUIData(FALSE);
  1887. DNS_STATUS dwErr = pServerNode->ResetLogLevelFlag(m_dwLogLevel);
  1888. if (dwErr != 0)
  1889. {
  1890. DNSErrorDialog(dwErr, IDS_MSG_SERVER_LOG_LEVEL_OPTIONS_FAILED);
  1891. return FALSE;
  1892. }
  1893. if (m_bMaxSizeDirty && !m_bNotWhistler)
  1894. {
  1895. dwErr = pServerNode->ResetDebugLogFileMaxSize(m_dwMaxSize);
  1896. if (dwErr != 0)
  1897. {
  1898. DNSErrorDialog(dwErr, IDS_MSG_SERVER_LOG_MAX_SIZE_FAILED);
  1899. return FALSE;
  1900. }
  1901. }
  1902. if (m_bLogFileDirty && !m_bNotWhistler)
  1903. {
  1904. dwErr = pServerNode->ResetDebugLogFileName(m_szLogFileName);
  1905. if (dwErr != 0)
  1906. {
  1907. DNSErrorDialog(dwErr, IDS_MSG_SERVER_LOG_FILE_NAME_FAILED);
  1908. return FALSE;
  1909. }
  1910. }
  1911. if (m_bFilterDirty && !m_bNotWhistler)
  1912. {
  1913. LRESULT lCheck = SendDlgItemMessage(IDC_FILTERING_CHECK, BM_GETCHECK, 0, 0);
  1914. if (lCheck == BST_CHECKED)
  1915. {
  1916. dwErr = pServerNode->ResetDebugLogFilterList(m_pIPFilterList);
  1917. }
  1918. else
  1919. {
  1920. dwErr = pServerNode->ResetDebugLogFilterList(NULL);
  1921. }
  1922. if (dwErr != 0)
  1923. {
  1924. DNSErrorDialog(dwErr, IDS_MSG_SERVER_LOG_FILTER_LIST_FAILED);
  1925. return FALSE;
  1926. }
  1927. m_bFilterDirty = FALSE;
  1928. }
  1929. //
  1930. // all is fine
  1931. //
  1932. SetUIData();
  1933. SetDirty(FALSE);
  1934. return TRUE;
  1935. }
  1936. ///////////////////////////////////////////////////////////////////////////////
  1937. // CDNSServer_EventLoggingPropertyPage
  1938. BEGIN_MESSAGE_MAP(CDNSServer_EventLoggingPropertyPage, CPropertyPageBase)
  1939. ON_BN_CLICKED(IDC_NO_EVENTS_RADIO, OnSetDirty)
  1940. ON_BN_CLICKED(IDC_ERRORS_RADIO, OnSetDirty)
  1941. ON_BN_CLICKED(IDC_ERRORS_WARNINGS_RADIO, OnSetDirty)
  1942. ON_BN_CLICKED(IDC_ALL_RADIO, OnSetDirty)
  1943. END_MESSAGE_MAP()
  1944. CDNSServer_EventLoggingPropertyPage::CDNSServer_EventLoggingPropertyPage()
  1945. : CPropertyPageBase(IDD_SERVER_EVENT_LOGGING_PAGE),
  1946. m_dwEventLogLevel(EVENTLOG_INFORMATION_TYPE)
  1947. {
  1948. }
  1949. void CDNSServer_EventLoggingPropertyPage::SetUIData()
  1950. {
  1951. if (m_dwEventLogLevel == 0)
  1952. {
  1953. SendDlgItemMessage(IDC_NO_EVENTS_RADIO, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
  1954. }
  1955. else if (m_dwEventLogLevel == EVENTLOG_ERROR_TYPE)
  1956. {
  1957. SendDlgItemMessage(IDC_ERRORS_RADIO, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
  1958. }
  1959. else if (m_dwEventLogLevel == EVENTLOG_WARNING_TYPE)
  1960. {
  1961. SendDlgItemMessage(IDC_ERRORS_WARNINGS_RADIO, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
  1962. }
  1963. else
  1964. {
  1965. SendDlgItemMessage(IDC_ALL_RADIO, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
  1966. }
  1967. }
  1968. void CDNSServer_EventLoggingPropertyPage::OnSetDirty()
  1969. {
  1970. SetDirty(TRUE);
  1971. }
  1972. BOOL CDNSServer_EventLoggingPropertyPage::OnInitDialog()
  1973. {
  1974. CPropertyPageBase::OnInitDialog();
  1975. CDNSServerPropertyPageHolder* pHolder =
  1976. (CDNSServerPropertyPageHolder*)GetHolder();
  1977. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1978. if (!pServerNode->HasServerInfo())
  1979. {
  1980. EnableWindow(FALSE);
  1981. return TRUE;
  1982. }
  1983. m_dwEventLogLevel = pServerNode->GetEventLogLevelFlag();
  1984. SetUIData();
  1985. return TRUE; // return TRUE unless you set the focus to a control
  1986. // EXCEPTION: OCX Property Pages should return FALSE
  1987. }
  1988. BOOL CDNSServer_EventLoggingPropertyPage::OnApply()
  1989. {
  1990. if (!IsDirty())
  1991. return TRUE;
  1992. CDNSServerPropertyPageHolder* pHolder =
  1993. (CDNSServerPropertyPageHolder*)GetHolder();
  1994. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  1995. //
  1996. // Retrieve UI data
  1997. //
  1998. LRESULT lNoEventsCheck = SendDlgItemMessage(IDC_NO_EVENTS_RADIO, BM_GETCHECK, 0, 0);
  1999. LRESULT lErrorsCheck = SendDlgItemMessage(IDC_ERRORS_RADIO, BM_GETCHECK, 0, 0);
  2000. LRESULT lWarningsCheck = SendDlgItemMessage(IDC_ERRORS_WARNINGS_RADIO, BM_GETCHECK, 0, 0);
  2001. LRESULT lAllCheck = SendDlgItemMessage(IDC_ALL_RADIO, BM_GETCHECK, 0, 0);
  2002. DWORD dwEventLogLevel = 0;
  2003. if (lNoEventsCheck == BST_CHECKED)
  2004. {
  2005. dwEventLogLevel = 0;
  2006. }
  2007. if (lErrorsCheck == BST_CHECKED)
  2008. {
  2009. dwEventLogLevel = EVENTLOG_ERROR_TYPE;
  2010. }
  2011. if (lWarningsCheck == BST_CHECKED)
  2012. {
  2013. dwEventLogLevel = EVENTLOG_WARNING_TYPE;
  2014. }
  2015. if (lAllCheck == BST_CHECKED)
  2016. {
  2017. dwEventLogLevel = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
  2018. }
  2019. //
  2020. // Set new event log level on server
  2021. //
  2022. DNS_STATUS err = 0;
  2023. err = pServerNode->ResetEventLogLevelFlag(dwEventLogLevel);
  2024. if (err != 0)
  2025. {
  2026. ::DNSErrorDialog(err, IDS_MSG_SERVER_FAILED_SET_EVENTLOGLEVEL);
  2027. return FALSE;
  2028. }
  2029. //
  2030. // all is fine
  2031. //
  2032. SetDirty(FALSE);
  2033. return TRUE;
  2034. }
  2035. ///////////////////////////////////////////////////////////////////////////////
  2036. // CDNSServer_CopyRootHintsFromDialog
  2037. BEGIN_MESSAGE_MAP(CDNSServer_CopyRootHintsFromDialog, CHelpDialog)
  2038. ON_EN_CHANGE(IDC_IPEDIT, OnIPv4CtrlChange)
  2039. END_MESSAGE_MAP()
  2040. CDNSServer_CopyRootHintsFromDialog::CDNSServer_CopyRootHintsFromDialog(CComponentDataObject* pComponentData)
  2041. : CHelpDialog(IDD_COPY_ROOTHINTS_DIALOG, pComponentData),
  2042. m_pComponentData(pComponentData)
  2043. {
  2044. m_dwIPVal = 0;
  2045. }
  2046. void CDNSServer_CopyRootHintsFromDialog::OnIPv4CtrlChange()
  2047. {
  2048. GetDlgItem(IDOK)->EnableWindow(!GetIPv4Ctrl()->IsEmpty());
  2049. }
  2050. void CDNSServer_CopyRootHintsFromDialog::OnOK()
  2051. {
  2052. GetIPv4Ctrl()->GetIPv4Val(&m_dwIPVal);
  2053. CDialog::OnOK();
  2054. }
  2055. ///////////////////////////////////////////////////////////////////////////////
  2056. // CDNSServer_RootHintsPropertyPage
  2057. BEGIN_MESSAGE_MAP(CDNSServer_RootHintsPropertyPage, CDNSNameServersPropertyPage)
  2058. ON_BN_CLICKED(IDC_COPY_FROM_BUTTON, OnCopyFrom)
  2059. END_MESSAGE_MAP()
  2060. CDNSServer_RootHintsPropertyPage::CDNSServer_RootHintsPropertyPage()
  2061. : CDNSNameServersPropertyPage(IDD_NAME_SERVERS_PAGE, IDS_NSPAGE_ROOT_HINTS)
  2062. {
  2063. m_bMeaningfulTTL = FALSE; // TTL for root hinst means nothing
  2064. }
  2065. BOOL CDNSServer_RootHintsPropertyPage::OnInitDialog()
  2066. {
  2067. CDNSNameServersPropertyPage::OnInitDialog();
  2068. if (m_bReadOnly)
  2069. {
  2070. GetDlgItem(IDC_COPY_FROM_BUTTON)->ShowWindow(TRUE);
  2071. GetDlgItem(IDC_COPY_FROM_BUTTON)->EnableWindow(FALSE);
  2072. }
  2073. else
  2074. {
  2075. GetDlgItem(IDC_COPY_FROM_BUTTON)->ShowWindow(TRUE);
  2076. GetDlgItem(IDC_COPY_FROM_BUTTON)->EnableWindow(TRUE);
  2077. }
  2078. GetDlgItem(IDC_DNSQUERY_STATIC)->ShowWindow(FALSE);
  2079. GetDlgItem(IDC_DNSQUERY_STATIC)->EnableWindow(FALSE);
  2080. return TRUE;
  2081. }
  2082. void CDNSServer_RootHintsPropertyPage::OnCopyFrom()
  2083. {
  2084. BOOL bSuccess = FALSE;
  2085. while (!bSuccess)
  2086. {
  2087. CDNSServer_CopyRootHintsFromDialog copydlg(GetHolder()->GetComponentData());
  2088. if (copydlg.DoModal() == IDCANCEL)
  2089. {
  2090. return;
  2091. }
  2092. //
  2093. // create a thread object and set the name of servers to query
  2094. //
  2095. CRootHintsQueryThread* pThreadObj = new CRootHintsQueryThread;
  2096. if (pThreadObj == NULL)
  2097. {
  2098. ASSERT(FALSE);
  2099. return;
  2100. }
  2101. //
  2102. // if IP address given, try it
  2103. //
  2104. pThreadObj->LoadIPAddresses(1, &(copydlg.m_dwIPVal));
  2105. //
  2106. // create a dialog and attach the thread to it
  2107. //
  2108. CWnd* pParentWnd = CWnd::FromHandle(GetSafeHwnd());
  2109. if (pParentWnd == NULL)
  2110. {
  2111. ASSERT(FALSE);
  2112. return;
  2113. }
  2114. CLongOperationDialog dlg(pThreadObj, pParentWnd, IDR_SEARCH_AVI);
  2115. VERIFY(dlg.LoadTitleString(IDS_MSG_SERVWIZ_COLLECTINFO));
  2116. dlg.m_bExecuteNoUI = FALSE;
  2117. dlg.DoModal();
  2118. if (!dlg.m_bAbandoned)
  2119. {
  2120. if (pThreadObj->GetError() != 0)
  2121. {
  2122. DNSMessageBox(IDS_MSG_SERVWIZ_FAIL_ROOT_HINTS);
  2123. }
  2124. else
  2125. {
  2126. //
  2127. // success, get the root hints info to the UI
  2128. //
  2129. PDNS_RECORD pRootHintsRecordList = pThreadObj->GetHintsRecordList();
  2130. AddCopiedRootHintsToList(pRootHintsRecordList);
  2131. }
  2132. bSuccess = pThreadObj->GetError() == 0;
  2133. }
  2134. }
  2135. }
  2136. void CDNSServer_RootHintsPropertyPage::AddCopiedRootHintsToList(PDNS_RECORD pRootHintsRecordList)
  2137. {
  2138. CDNSRecordNodeEditInfoList NSRecordList;
  2139. CDNSRecordNodeEditInfoList ARecordList;
  2140. //
  2141. // walk through the list of root hints,
  2142. // convert to C++ format,
  2143. // write to server and add to the folder list (no UI, folder hidden)
  2144. //
  2145. PDNS_RECORD pCurrDnsQueryRecord = pRootHintsRecordList;
  2146. while (pCurrDnsQueryRecord != NULL)
  2147. {
  2148. ASSERT( (pCurrDnsQueryRecord->wType == DNS_TYPE_A) ||
  2149. (pCurrDnsQueryRecord->wType == DNS_TYPE_NS) );
  2150. //
  2151. // create a record node and read data from DnsQuery format
  2152. //
  2153. CDNSRecordNodeBase* pRecordNode =
  2154. CDNSRecordInfo::CreateRecordNode(pCurrDnsQueryRecord->wType);
  2155. pRecordNode->CreateFromDnsQueryRecord(pCurrDnsQueryRecord, DNS_RPC_RECORD_FLAG_ZONE_ROOT);
  2156. //
  2157. // create new data
  2158. //
  2159. CDNSRecordNodeEditInfo* pNewInfo = new CDNSRecordNodeEditInfo;
  2160. pNewInfo->m_action = CDNSRecordNodeEditInfo::add;
  2161. CDNSRootData* pRootData = (CDNSRootData*)(GetHolder()->GetComponentData()->GetRootData());
  2162. ASSERT(pRootData != NULL);
  2163. //
  2164. // create entry into the record info list
  2165. //
  2166. if (pCurrDnsQueryRecord->wType == DNS_TYPE_NS)
  2167. {
  2168. pNewInfo->CreateFromNewRecord(new CDNS_NS_RecordNode);
  2169. //
  2170. // set the record node name
  2171. //
  2172. BOOL bAtTheNode = (pCurrDnsQueryRecord->wType == DNS_TYPE_NS);
  2173. pNewInfo->m_pRecordNode->SetRecordName(pCurrDnsQueryRecord->pName, bAtTheNode);
  2174. //
  2175. // Set the record
  2176. //
  2177. pNewInfo->m_pRecord->ReadDnsQueryData(pCurrDnsQueryRecord);
  2178. //
  2179. // Add to the NS record list
  2180. //
  2181. NSRecordList.AddTail(pNewInfo);
  2182. }
  2183. else // DNS_TYPE_A
  2184. {
  2185. pNewInfo->CreateFromNewRecord(new CDNS_A_RecordNode);
  2186. //
  2187. // set the record node name
  2188. //
  2189. pNewInfo->m_pRecordNode->SetRecordName(pCurrDnsQueryRecord->pName, FALSE);
  2190. //
  2191. // Set the record
  2192. //
  2193. pNewInfo->m_pRecord->ReadDnsQueryData(pCurrDnsQueryRecord);
  2194. ARecordList.AddTail(pNewInfo);
  2195. }
  2196. pCurrDnsQueryRecord = pCurrDnsQueryRecord->pNext;
  2197. }
  2198. //
  2199. // Match the A records to the NS records
  2200. //
  2201. POSITION Apos = ARecordList.GetHeadPosition();
  2202. while (Apos != NULL)
  2203. {
  2204. CDNSRecordNodeEditInfo* pAInfo = ARecordList.GetNext(Apos);
  2205. ASSERT(pAInfo != NULL);
  2206. if (pAInfo == NULL)
  2207. {
  2208. continue;
  2209. }
  2210. CDNS_A_RecordNode* pARecordNode = reinterpret_cast<CDNS_A_RecordNode*>(pAInfo->m_pRecordNode);
  2211. ASSERT(pARecordNode != NULL);
  2212. if (pARecordNode == NULL)
  2213. {
  2214. continue;
  2215. }
  2216. POSITION NSpos = NSRecordList.GetHeadPosition();
  2217. while (NSpos != NULL)
  2218. {
  2219. CDNSRecordNodeEditInfo* pNSInfo = NSRecordList.GetNext(NSpos);
  2220. ASSERT(pNSInfo != NULL);
  2221. if (pNSInfo == NULL)
  2222. {
  2223. continue;
  2224. }
  2225. CDNS_NS_Record* pNSRecord = reinterpret_cast<CDNS_NS_Record*>(pNSInfo->m_pRecord);
  2226. ASSERT(pNSRecord != NULL);
  2227. if (pNSRecord == NULL)
  2228. {
  2229. continue;
  2230. }
  2231. if (_match(pNSRecord->m_szNameNode, pARecordNode))
  2232. {
  2233. pNSInfo->m_pEditInfoList->AddTail(pAInfo);
  2234. }
  2235. }
  2236. }
  2237. //
  2238. // Detach and add the NS records info to the UI
  2239. //
  2240. while (!NSRecordList.IsEmpty())
  2241. {
  2242. CDNSRecordNodeEditInfo* pNewInfo = reinterpret_cast<CDNSRecordNodeEditInfo*>(NSRecordList.RemoveTail());
  2243. ASSERT(pNewInfo != NULL);
  2244. if (pNewInfo == NULL)
  2245. {
  2246. continue;
  2247. }
  2248. //
  2249. // add to the list view (at the end)
  2250. //
  2251. int nCount = m_listCtrl.GetItemCount();
  2252. if (m_listCtrl.InsertNSRecordEntry(pNewInfo, nCount))
  2253. {
  2254. //
  2255. // Add to the clone info list so that changes will be applied
  2256. //
  2257. m_pCloneInfoList->AddTail(pNewInfo);
  2258. //
  2259. // set selection and button state on the last inserted
  2260. //
  2261. m_listCtrl.SetSelection(nCount);
  2262. EnableEditorButtons(nCount);
  2263. //
  2264. // notify count change
  2265. //
  2266. OnCountChange(nCount+1); // added one
  2267. }
  2268. //
  2269. // set dirty flag, it is a new record
  2270. //
  2271. SetDirty(TRUE);
  2272. }
  2273. while (!ARecordList.IsEmpty())
  2274. {
  2275. ARecordList.RemoveTail();
  2276. }
  2277. }
  2278. void CDNSServer_RootHintsPropertyPage::ReadRecordNodesList()
  2279. {
  2280. ASSERT(m_pCloneInfoList != NULL);
  2281. CDNSServerPropertyPageHolder* pHolder = (CDNSServerPropertyPageHolder*)GetHolder();
  2282. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  2283. CString szBuffer;
  2284. szBuffer.LoadString(IDS_ROOT_HINTS_DESCR);
  2285. GetDescription()->EnableWindow(TRUE);
  2286. GetDescription()->ShowWindow(TRUE);
  2287. SetDescription(szBuffer);
  2288. if (!pServerNode->HasServerInfo())
  2289. {
  2290. SetReadOnly();
  2291. return;
  2292. }
  2293. BOOL bRoot = FALSE;
  2294. DNS_STATUS err = ::ServerHasRootZone(pServerNode->GetRPCName(), &bRoot);
  2295. if (err == 0 && bRoot)
  2296. {
  2297. //
  2298. // it is a root server
  2299. //
  2300. szBuffer.LoadString(IDS_ROOT_HINTS_NO);
  2301. SetMessage(szBuffer);
  2302. SetReadOnly();
  2303. EnableDialogControls(m_hWnd, FALSE);
  2304. }
  2305. else
  2306. {
  2307. if (pServerNode->HasRootHints())
  2308. {
  2309. CDNSRootHintsNode* pRootHints = pServerNode->GetRootHints();
  2310. ASSERT(pRootHints != NULL);
  2311. SetDomainNode(pRootHints);
  2312. pRootHints->GetNSRecordNodesInfo(m_pCloneInfoList);
  2313. }
  2314. else
  2315. {
  2316. CDNSRootHintsNode* pRootHints = pServerNode->GetRootHints();
  2317. if (pRootHints != NULL)
  2318. {
  2319. SetDomainNode(pRootHints);
  2320. pRootHints->GetNSRecordNodesInfo(m_pCloneInfoList);
  2321. }
  2322. }
  2323. }
  2324. }
  2325. BOOL CDNSServer_RootHintsPropertyPage::WriteNSRecordNodesList()
  2326. {
  2327. // call base class
  2328. BOOL bRetVal = CDNSNameServersPropertyPage::WriteNSRecordNodesList();
  2329. CDNSServerPropertyPageHolder* pHolder = (CDNSServerPropertyPageHolder*)GetHolder();
  2330. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  2331. if (bRetVal && pServerNode->HasServerInfo())
  2332. {
  2333. DNS_STATUS err = CDNSZoneNode::WriteToDatabase(pServerNode->GetRPCName(), DNS_ZONE_ROOT_HINTS);
  2334. if (err != 0)
  2335. {
  2336. //DNSErrorDialog(err, L"CDNSZoneNode::WriteToDatabase() failed");
  2337. bRetVal = FALSE;
  2338. }
  2339. }
  2340. return bRetVal;
  2341. }
  2342. BOOL CDNSServer_RootHintsPropertyPage::OnApply()
  2343. {
  2344. BOOL bRet = TRUE;
  2345. CDNSServerPropertyPageHolder* pHolder = (CDNSServerPropertyPageHolder*)GetHolder();
  2346. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  2347. if (m_listCtrl.GetItemCount() == 0 && pServerNode->HasRootHints())
  2348. {
  2349. //
  2350. // If there are no forwarders and no root zone then show an error message
  2351. //
  2352. BOOL bServerHasForwarders = FALSE;
  2353. CDNSDomainForwardersNode* pDomainForwardersNode = pServerNode->GetDomainForwardersNode();
  2354. if (pDomainForwardersNode)
  2355. {
  2356. CNodeList* pChildList = pDomainForwardersNode->GetContainerChildList();
  2357. if (pChildList)
  2358. {
  2359. bServerHasForwarders = (pChildList->GetHeadPosition() != NULL);
  2360. }
  2361. }
  2362. DWORD cAddrCount = 0;
  2363. PIP_ADDRESS pipAddrs = 0;
  2364. DWORD dwForwardTimeout = 0;
  2365. DWORD fSlave = 0;
  2366. pServerNode->GetForwardersInfo(&cAddrCount, &pipAddrs, &dwForwardTimeout, &fSlave);
  2367. if (cAddrCount > 0)
  2368. {
  2369. bServerHasForwarders = TRUE;
  2370. }
  2371. BOOL bServerHasRoot = FALSE;
  2372. DNS_STATUS err = ServerHasRootZone(pServerNode->GetRPCName(), &bServerHasRoot);
  2373. if (err == 0 && !bServerHasRoot && !bServerHasForwarders)
  2374. {
  2375. if (IDNO == DNSMessageBox(IDS_NO_ROOTHINTS, MB_YESNO | MB_DEFBUTTON2))
  2376. {
  2377. return FALSE;
  2378. }
  2379. }
  2380. }
  2381. if (bRet)
  2382. {
  2383. bRet = CDNSNameServersPropertyPage::OnApply();
  2384. }
  2385. return bRet;
  2386. }
  2387. ///////////////////////////////////////////////////////////////////////////////
  2388. // CDNSServerPropertyPageHolder
  2389. CDNSServerPropertyPageHolder::CDNSServerPropertyPageHolder(CDNSRootData* pRootDataNode,
  2390. CDNSServerNode* pServerNode, CComponentDataObject* pComponentData)
  2391. : CPropertyPageHolderBase(pRootDataNode, pServerNode, pComponentData)
  2392. {
  2393. ASSERT(pRootDataNode == GetContainerNode());
  2394. m_pAclEditorPage = NULL;
  2395. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  2396. if (pServerNode->HasServerInfo())
  2397. {
  2398. AddPageToList((CPropertyPageBase*)&m_interfacesPage);
  2399. AddPageToList((CPropertyPageBase*)&m_newForwardersPage);
  2400. AddPageToList((CPropertyPageBase*)&m_advancedPage);
  2401. AddPageToList((CPropertyPageBase*)&m_rootHintsPage);
  2402. AddPageToList((CPropertyPageBase*)&m_debugLoggingPage);
  2403. AddPageToList((CPropertyPageBase*)&m_eventLoggingPage);
  2404. // security page added only if needed
  2405. {
  2406. CString szPath;
  2407. pServerNode->CreateDsServerLdapPath(szPath);
  2408. if (!szPath.IsEmpty())
  2409. m_pAclEditorPage = CAclEditorPage::CreateInstance(szPath, this);
  2410. }
  2411. }
  2412. AddPageToList((CPropertyPageBase*)&m_testPage);
  2413. }
  2414. CDNSServerPropertyPageHolder::~CDNSServerPropertyPageHolder()
  2415. {
  2416. if (m_pAclEditorPage != NULL)
  2417. delete m_pAclEditorPage;
  2418. }
  2419. void CDNSServerPropertyPageHolder::OnSheetMessage(WPARAM wParam, LPARAM lParam)
  2420. {
  2421. if (wParam == SHEET_MSG_SERVER_TEST_DATA)
  2422. {
  2423. m_testPage.OnHaveTestData(lParam);
  2424. }
  2425. }
  2426. HRESULT CDNSServerPropertyPageHolder::OnAddPage(int nPage, CPropertyPageBase*)
  2427. {
  2428. // add the ACL editor page after the last, if present
  2429. if ( (nPage != -1) || (m_pAclEditorPage == NULL) )
  2430. return S_OK;
  2431. // add the ACLU page
  2432. HPROPSHEETPAGE hPage = m_pAclEditorPage->CreatePage();
  2433. if (hPage == NULL)
  2434. return E_FAIL;
  2435. // add the raw HPROPSHEETPAGE to sheet, not in the list
  2436. return AddPageToSheetRaw(hPage);
  2437. }