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

1244 lines
35 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: T C P D N S . C P P
  7. //
  8. // Contents: CTcpDnsPage, CServerDialog and CSuffixDialog implementation
  9. //
  10. // Notes: The DNS page and related dialogs
  11. //
  12. // Author: tongl 11 Nov 1997
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "tcpipobj.h"
  18. #include "ncatlui.h"
  19. #include "ncstl.h"
  20. #include "tcpconst.h"
  21. #include "dlgaddr.h"
  22. #include "dlgdns.h"
  23. #include "tcphelp.h"
  24. #include "tcpmacro.h"
  25. #include "tcputil.h"
  26. #include "dnslib.h"
  27. #define MAX_RAS_DNS_SERVER 2
  28. #define MAX_HOSTNAME_LENGTH 64
  29. #define MAX_DOMAINNAME_LENGTH 255
  30. CTcpDnsPage::CTcpDnsPage(CTcpAddrPage * pTcpAddrPage,
  31. ADAPTER_INFO * pAdapterDlg,
  32. GLOBAL_INFO * pGlbDlg,
  33. const DWORD* adwHelpIDs)
  34. {
  35. // Save everything passed to us
  36. Assert(pTcpAddrPage != NULL);
  37. m_pParentDlg = pTcpAddrPage;
  38. Assert(pAdapterDlg != NULL);
  39. m_pAdapterInfo = pAdapterDlg;
  40. Assert(pGlbDlg != NULL);
  41. m_pglb = pGlbDlg;
  42. m_adwHelpIDs = adwHelpIDs;
  43. // Initialize internal states
  44. m_fModified = FALSE;
  45. }
  46. CTcpDnsPage::~CTcpDnsPage()
  47. {
  48. }
  49. LRESULT CTcpDnsPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  50. LPARAM lParam, BOOL& fHandled)
  51. {
  52. m_fEditState = FALSE;
  53. // Cache hwnds
  54. // Server
  55. m_hServers.m_hList = GetDlgItem(IDC_DNS_SERVER_LIST);
  56. m_hServers.m_hAdd = GetDlgItem(IDC_DNS_SERVER_ADD);
  57. m_hServers.m_hEdit = GetDlgItem(IDC_DNS_SERVER_EDIT);
  58. m_hServers.m_hRemove = GetDlgItem(IDC_DNS_SERVER_REMOVE);
  59. m_hServers.m_hUp = GetDlgItem(IDC_DNS_SERVER_UP);
  60. m_hServers.m_hDown = GetDlgItem(IDC_DNS_SERVER_DOWN);
  61. // Suffix
  62. m_hSuffix.m_hList = GetDlgItem(IDC_DNS_SUFFIX_LIST);
  63. m_hSuffix.m_hAdd = GetDlgItem(IDC_DNS_SUFFIX_ADD);
  64. m_hSuffix.m_hEdit = GetDlgItem(IDC_DNS_SUFFIX_EDIT);
  65. m_hSuffix.m_hRemove = GetDlgItem(IDC_DNS_SUFFIX_REMOVE);
  66. m_hSuffix.m_hUp = GetDlgItem(IDC_DNS_SUFFIX_UP);
  67. m_hSuffix.m_hDown = GetDlgItem(IDC_DNS_SUFFIX_DOWN);
  68. // Set the up\down arrow icons
  69. SendDlgItemMessage(IDC_DNS_SERVER_UP, BM_SETIMAGE, IMAGE_ICON,
  70. reinterpret_cast<LPARAM>(g_hiconUpArrow));
  71. SendDlgItemMessage(IDC_DNS_SERVER_DOWN, BM_SETIMAGE, IMAGE_ICON,
  72. reinterpret_cast<LPARAM>(g_hiconDownArrow));
  73. SendDlgItemMessage(IDC_DNS_SUFFIX_UP, BM_SETIMAGE, IMAGE_ICON,
  74. reinterpret_cast<LPARAM>(g_hiconUpArrow));
  75. SendDlgItemMessage(IDC_DNS_SUFFIX_DOWN, BM_SETIMAGE, IMAGE_ICON,
  76. reinterpret_cast<LPARAM>(g_hiconDownArrow));
  77. // Get the Service address Add and Edit button Text and remove ellipse
  78. WCHAR szAddServer[16];
  79. WCHAR szAddSuffix[16];
  80. GetDlgItemText(IDC_DNS_SERVER_ADD, szAddServer, celems(szAddServer));
  81. GetDlgItemText(IDC_DNS_SERVER_ADD, szAddSuffix, celems(szAddSuffix));
  82. szAddServer[lstrlenW(szAddServer) - c_cchRemoveCharatersFromEditOrAddButton]= 0;
  83. szAddSuffix[lstrlenW(szAddSuffix) - c_cchRemoveCharatersFromEditOrAddButton]= 0;
  84. m_strAddServer = szAddServer;
  85. m_strAddSuffix = szAddSuffix;
  86. // Initialize controls on this page
  87. // DNS server list box
  88. int nResult= LB_ERR;
  89. for(VSTR_ITER iterNameServer = m_pAdapterInfo->m_vstrDnsServerList.begin() ;
  90. iterNameServer != m_pAdapterInfo->m_vstrDnsServerList.end() ;
  91. ++iterNameServer)
  92. {
  93. nResult = Tcp_ListBox_InsertString(m_hServers.m_hList, -1,
  94. (*iterNameServer)->c_str());
  95. }
  96. // set slection to first item
  97. if (nResult >= 0)
  98. {
  99. Tcp_ListBox_SetCurSel(m_hServers.m_hList, 0);
  100. }
  101. SetButtons(m_hServers, (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_DNS_SERVER : -1);
  102. // DNS domain edit box
  103. ::SendMessage(GetDlgItem(IDC_DNS_DOMAIN), EM_SETLIMITTEXT, DOMAIN_LIMIT, 0);
  104. ::SetWindowText(GetDlgItem(IDC_DNS_DOMAIN),
  105. m_pAdapterInfo->m_strDnsDomain.c_str());
  106. // DNS dynamic registration
  107. CheckDlgButton(IDC_DNS_ADDR_REG, !m_pAdapterInfo->m_fDisableDynamicUpdate);
  108. CheckDlgButton(IDC_DNS_NAME_REG, m_pAdapterInfo->m_fEnableNameRegistration);
  109. // Bug #266461 need disable IDC_DNS_NAME_REG if IDC_DNS_ADDR_REG is unchecked
  110. if(m_pAdapterInfo->m_fDisableDynamicUpdate)
  111. ::EnableWindow(GetDlgItem(IDC_DNS_NAME_REG), FALSE);
  112. // DNS domain serach methods
  113. if (m_pglb->m_vstrDnsSuffixList.size() >0) //If suffix list not empty
  114. {
  115. CheckDlgButton(IDC_DNS_USE_SUFFIX_LIST, TRUE);
  116. CheckDlgButton(IDC_DNS_SEARCH_DOMAIN, FALSE);
  117. CheckDlgButton(IDC_DNS_SEARCH_PARENT_DOMAIN, FALSE);
  118. EnableSuffixGroup(TRUE);
  119. ::EnableWindow(GetDlgItem(IDC_DNS_SEARCH_PARENT_DOMAIN), FALSE);
  120. // DNS suffix list box
  121. nResult= LB_ERR;
  122. for(VSTR_CONST_ITER iterSearchList = (m_pglb->m_vstrDnsSuffixList).begin() ;
  123. iterSearchList != (m_pglb->m_vstrDnsSuffixList).end() ;
  124. ++iterSearchList)
  125. {
  126. nResult = Tcp_ListBox_InsertString(m_hSuffix.m_hList, -1,
  127. (*iterSearchList)->c_str());
  128. }
  129. // set slection to first item
  130. if (nResult >= 0)
  131. {
  132. Tcp_ListBox_SetCurSel(m_hSuffix.m_hList, 0);
  133. }
  134. SetButtons(m_hSuffix, DNS_MAX_SEARCH_LIST_ENTRIES);
  135. }
  136. else
  137. {
  138. CheckDlgButton(IDC_DNS_USE_SUFFIX_LIST, FALSE);
  139. CheckDlgButton(IDC_DNS_SEARCH_DOMAIN, TRUE);
  140. CheckDlgButton(IDC_DNS_SEARCH_PARENT_DOMAIN, m_pglb->m_fUseDomainNameDevolution);
  141. EnableSuffixGroup(FALSE);
  142. }
  143. //this is a ras connection and a non-admin user, disable all the controls
  144. //for globl settings
  145. if (m_pAdapterInfo->m_fIsRasFakeAdapter && m_pParentDlg->m_fRasNotAdmin)
  146. {
  147. ::EnableWindow(GetDlgItem(IDC_DNS_STATIC_GLOBAL), FALSE);
  148. ::EnableWindow(GetDlgItem(IDC_DNS_SEARCH_DOMAIN), FALSE);
  149. ::EnableWindow(GetDlgItem(IDC_DNS_SEARCH_PARENT_DOMAIN), FALSE);
  150. ::EnableWindow(GetDlgItem(IDC_DNS_USE_SUFFIX_LIST), FALSE);
  151. EnableSuffixGroup(FALSE);
  152. }
  153. return 0;
  154. }
  155. LRESULT CTcpDnsPage::OnContextMenu(UINT uMsg, WPARAM wParam,
  156. LPARAM lParam, BOOL& fHandled)
  157. {
  158. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  159. return 0;
  160. }
  161. LRESULT CTcpDnsPage::OnHelp(UINT uMsg, WPARAM wParam,
  162. LPARAM lParam, BOOL& fHandled)
  163. {
  164. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  165. Assert(lphi);
  166. if (HELPINFO_WINDOW == lphi->iContextType)
  167. {
  168. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  169. m_adwHelpIDs);
  170. }
  171. return 0;
  172. }
  173. LRESULT CTcpDnsPage::OnActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  174. {
  175. return 0;
  176. }
  177. LRESULT CTcpDnsPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  178. {
  179. BOOL nResult = PSNRET_NOERROR;
  180. if (!IsModified())
  181. {
  182. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  183. return nResult;
  184. }
  185. // server list
  186. FreeCollectionAndItem(m_pAdapterInfo->m_vstrDnsServerList);
  187. WCHAR szServer[IP_LIMIT];
  188. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  189. for (int i = 0; i < nCount; i++)
  190. {
  191. #ifdef DBG
  192. int len = Tcp_ListBox_GetTextLen(m_hServers.m_hList, i);
  193. Assert(len != LB_ERR && len < IP_LIMIT);
  194. #endif
  195. Tcp_ListBox_GetText(m_hServers.m_hList, i, szServer);
  196. m_pAdapterInfo->m_vstrDnsServerList.push_back(new tstring(szServer));
  197. }
  198. // DNS domain
  199. // update second memory with what's in the controls
  200. WCHAR szDomain[DOMAIN_LIMIT + 1];
  201. ::GetWindowText(GetDlgItem(IDC_DNS_DOMAIN), szDomain, celems(szDomain));
  202. m_pAdapterInfo->m_strDnsDomain = szDomain;
  203. m_pAdapterInfo->m_fDisableDynamicUpdate = !IsDlgButtonChecked(IDC_DNS_ADDR_REG);
  204. m_pAdapterInfo->m_fEnableNameRegistration = IsDlgButtonChecked(IDC_DNS_NAME_REG);
  205. // suffix list and radio button options
  206. FreeCollectionAndItem(m_pglb->m_vstrDnsSuffixList);
  207. WCHAR szSuffix[SUFFIX_LIMIT];
  208. if (IsDlgButtonChecked(IDC_DNS_USE_SUFFIX_LIST))
  209. {
  210. int nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList);
  211. AssertSz(nCount > 0, "Why isn't the error caught by OnKillActive?");
  212. for (int i = 0; i < nCount; i++)
  213. {
  214. #ifdef DBG
  215. int len = Tcp_ListBox_GetTextLen(m_hSuffix.m_hList, i);
  216. Assert(len != LB_ERR && len < SUFFIX_LIMIT);
  217. #endif
  218. Tcp_ListBox_GetText(m_hSuffix.m_hList, i, szSuffix);
  219. m_pglb->m_vstrDnsSuffixList.push_back(new tstring(szSuffix));
  220. }
  221. }
  222. else
  223. {
  224. m_pglb->m_fUseDomainNameDevolution =
  225. IsDlgButtonChecked(IDC_DNS_SEARCH_PARENT_DOMAIN);
  226. }
  227. // pass the info back to its parent dialog
  228. m_pParentDlg->m_fPropShtOk = TRUE;
  229. if(!m_pParentDlg->m_fPropShtModified)
  230. m_pParentDlg->m_fPropShtModified = IsModified();
  231. SetModifiedTo(FALSE); // this page is no longer modified
  232. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  233. return nResult;
  234. }
  235. LRESULT CTcpDnsPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  236. {
  237. return 0;
  238. }
  239. LRESULT CTcpDnsPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  240. {
  241. BOOL fErr = FALSE;
  242. if (IsDlgButtonChecked(IDC_DNS_USE_SUFFIX_LIST))
  243. {
  244. int nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList);
  245. if (0 == nCount)
  246. {
  247. // If the list is empty
  248. NcMsgBox(m_hWnd, IDS_MSFT_TCP_TEXT, IDS_INVALID_NO_SUFFIX,
  249. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  250. fErr = TRUE;
  251. }
  252. }
  253. WCHAR szDomain[DOMAIN_LIMIT + 1];
  254. ::GetWindowText(GetDlgItem(IDC_DNS_DOMAIN), szDomain, celems(szDomain));
  255. if (lstrlenW(szDomain) > 0 && lstrcmpiW(m_pAdapterInfo->m_strDnsDomain.c_str(), szDomain) != 0)
  256. {
  257. DNS_STATUS status;
  258. status = DnsValidateName(szDomain, DnsNameDomain);
  259. if (ERROR_INVALID_NAME == status ||
  260. DNS_ERROR_INVALID_NAME_CHAR == status)
  261. {
  262. NcMsgBox(m_hWnd,
  263. IDS_MSFT_TCP_TEXT,
  264. IDS_INVALID_DOMAIN_NAME,
  265. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK,
  266. szDomain);
  267. ::SetFocus(GetDlgItem(IDC_DNS_DOMAIN));
  268. fErr = TRUE;
  269. }
  270. else if (DNS_ERROR_NON_RFC_NAME == status)
  271. {
  272. //the dns domain name is not RFC compaliant, should we give a warning here?
  273. }
  274. }
  275. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, fErr);
  276. return fErr;
  277. }
  278. // DNS server related controls
  279. LRESULT CTcpDnsPage::OnAddServer(WORD wNotifyCode, WORD wID,
  280. HWND hWndCtl, BOOL& fHandled)
  281. {
  282. m_fEditState = FALSE;
  283. CServerDialog * pDlgSrv = new CServerDialog(this, g_aHelpIDs_IDD_DNS_SERVER);
  284. if (pDlgSrv->DoModal() == IDOK)
  285. {
  286. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  287. int idx = Tcp_ListBox_InsertString(m_hServers.m_hList,
  288. -1,
  289. m_strNewIpAddress.c_str());
  290. Assert(idx>=0);
  291. if (idx >= 0)
  292. {
  293. PageModified();
  294. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  295. SetButtons(m_hServers, (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_DNS_SERVER : -1);
  296. // empty strings, this removes the saved address from RemoveIP
  297. m_strNewIpAddress = L"";
  298. }
  299. }
  300. // release dialog object
  301. delete pDlgSrv;
  302. return 0;
  303. }
  304. LRESULT CTcpDnsPage::OnEditServer(WORD wNotifyCode, WORD wID,
  305. HWND hWndCtl, BOOL& fHandled)
  306. {
  307. m_fEditState = TRUE;
  308. Assert(Tcp_ListBox_GetCount(m_hServers.m_hList));
  309. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  310. Assert(idx >= 0);
  311. CServerDialog * pDlgSrv = new CServerDialog(this,
  312. g_aHelpIDs_IDD_DNS_SERVER,
  313. idx);
  314. // save off the removed address and delete if from the listbox
  315. if (idx >= 0)
  316. {
  317. WCHAR buf[IP_LIMIT];
  318. Assert(Tcp_ListBox_GetTextLen(m_hServers.m_hList, idx) < celems(buf));
  319. Tcp_ListBox_GetText(m_hServers.m_hList, idx, buf);
  320. m_strNewIpAddress = buf; // used by dialog to display what to edit
  321. if (pDlgSrv->DoModal() == IDOK)
  322. {
  323. // replace the item in the listview with the new information
  324. Tcp_ListBox_DeleteString(m_hServers.m_hList, idx);
  325. PageModified();
  326. m_strMovingEntry = m_strNewIpAddress;
  327. ListBoxInsertAfter(m_hServers.m_hList, idx, m_strMovingEntry.c_str());
  328. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  329. m_strNewIpAddress = buf; // restore the original removed address
  330. }
  331. else
  332. {
  333. // empty strings, this removes the saved address from RemoveIP
  334. m_strNewIpAddress = L"";
  335. }
  336. }
  337. delete pDlgSrv;
  338. return 0;
  339. }
  340. LRESULT CTcpDnsPage::OnRemoveServer(WORD wNotifyCode, WORD wID,
  341. HWND hWndCtl, BOOL& fHandled)
  342. {
  343. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  344. Assert(idx >=0);
  345. if (idx >=0)
  346. {
  347. WCHAR buf[IP_LIMIT];
  348. Assert(Tcp_ListBox_GetTextLen(m_hServers.m_hList, idx) < celems(buf));
  349. Tcp_ListBox_GetText(m_hServers.m_hList, idx, buf);
  350. m_strNewIpAddress = buf;
  351. Tcp_ListBox_DeleteString(m_hServers.m_hList, idx);
  352. PageModified();
  353. // select a new item
  354. int nCount;
  355. if ((nCount = Tcp_ListBox_GetCount(m_hServers.m_hList)) != LB_ERR)
  356. {
  357. // select the previous item in the list
  358. if (idx)
  359. --idx;
  360. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  361. }
  362. SetButtons(m_hServers, (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_DNS_SERVER : -1);
  363. }
  364. return 0;
  365. }
  366. LRESULT CTcpDnsPage::OnServerUp(WORD wNotifyCode, WORD wID,
  367. HWND hWndCtl, BOOL& fHandled)
  368. {
  369. Assert(m_hServers.m_hList);
  370. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  371. Assert(nCount);
  372. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  373. Assert(idx != 0);
  374. if (ListBoxRemoveAt(m_hServers.m_hList, idx, &m_strMovingEntry) == FALSE)
  375. {
  376. Assert(FALSE);
  377. return 0;
  378. }
  379. --idx;
  380. PageModified();
  381. ListBoxInsertAfter(m_hServers.m_hList, idx, m_strMovingEntry.c_str());
  382. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  383. SetButtons(m_hServers, (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_DNS_SERVER : -1);
  384. return 0;
  385. }
  386. LRESULT CTcpDnsPage::OnDnsDomain(WORD wNotifyCode, WORD wID,
  387. HWND hWndCtl, BOOL& fHandled)
  388. {
  389. switch (wNotifyCode)
  390. {
  391. case EN_CHANGE:
  392. // update second memory with what's in the controls
  393. WCHAR szBuf[DOMAIN_LIMIT + 1];
  394. ::GetWindowText(GetDlgItem(IDC_DNS_DOMAIN), szBuf, celems(szBuf));
  395. if (m_pAdapterInfo->m_strDnsDomain != szBuf)
  396. PageModified();
  397. break;
  398. default:
  399. break;
  400. }
  401. return 0;
  402. }
  403. LRESULT CTcpDnsPage::OnServerDown(WORD wNotifyCode, WORD wID,
  404. HWND hWndCtl, BOOL& fHandled)
  405. {
  406. Assert(m_hServers.m_hList);
  407. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  408. Assert(nCount);
  409. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  410. --nCount;
  411. Assert(idx != nCount);
  412. if (ListBoxRemoveAt(m_hServers.m_hList, idx, &m_strMovingEntry) == FALSE)
  413. {
  414. Assert(FALSE);
  415. return 0;
  416. }
  417. ++idx;
  418. PageModified();
  419. ListBoxInsertAfter(m_hServers.m_hList, idx, m_strMovingEntry.c_str());
  420. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  421. SetButtons(m_hServers, (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_DNS_SERVER : -1);
  422. return 0;
  423. }
  424. // DNS domain search related controls
  425. LRESULT CTcpDnsPage::OnSearchDomain(WORD wNotifyCode, WORD wID,
  426. HWND hWndCtl, BOOL& fHandled)
  427. {
  428. switch(wNotifyCode)
  429. {
  430. case BN_CLICKED:
  431. case BN_DOUBLECLICKED:
  432. if (::IsWindowEnabled(m_hSuffix.m_hList))
  433. {
  434. PageModified();
  435. // Update in memory structure
  436. FreeCollectionAndItem(m_pglb->m_vstrDnsSuffixList);
  437. // delete all items from the list
  438. int nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList);
  439. while (nCount>0)
  440. {
  441. Tcp_ListBox_DeleteString(m_hSuffix.m_hList, 0);
  442. nCount --;
  443. }
  444. EnableSuffixGroup(FALSE);
  445. ::EnableWindow(GetDlgItem(IDC_DNS_SEARCH_PARENT_DOMAIN), TRUE);
  446. }
  447. break;
  448. } // switch
  449. return 0;
  450. }
  451. LRESULT CTcpDnsPage::OnSearchParentDomain(WORD wNotifyCode, WORD wID,
  452. HWND hWndCtl, BOOL& fHandled)
  453. {
  454. switch(wNotifyCode)
  455. {
  456. case BN_CLICKED:
  457. case BN_DOUBLECLICKED:
  458. PageModified();
  459. break;
  460. } // switch
  461. return 0;
  462. }
  463. LRESULT CTcpDnsPage::OnAddressRegister(WORD wNotifyCode, WORD wID,
  464. HWND hWndCtl, BOOL& fHandled)
  465. {
  466. switch(wNotifyCode)
  467. {
  468. case BN_CLICKED:
  469. case BN_DOUBLECLICKED:
  470. // Bug #266461 need disable and uncheck IDC_DNS_NAME_REG
  471. // if IDC_DNS_ADDR_REG is unchecked
  472. if(!IsDlgButtonChecked(IDC_DNS_ADDR_REG))
  473. {
  474. CheckDlgButton(IDC_DNS_NAME_REG, FALSE);
  475. ::EnableWindow(GetDlgItem(IDC_DNS_NAME_REG), FALSE);
  476. }
  477. else
  478. ::EnableWindow(GetDlgItem(IDC_DNS_NAME_REG), TRUE);
  479. PageModified();
  480. break;
  481. }
  482. return 0;
  483. }
  484. LRESULT CTcpDnsPage::OnDomainNameRegister(WORD wNotifyCode, WORD wID,
  485. HWND hWndCtl, BOOL& fHandled)
  486. {
  487. switch(wNotifyCode)
  488. {
  489. case BN_CLICKED:
  490. case BN_DOUBLECLICKED:
  491. PageModified();
  492. break;
  493. }
  494. return 0;
  495. }
  496. LRESULT CTcpDnsPage::OnUseSuffix(WORD wNotifyCode, WORD wID,
  497. HWND hWndCtl, BOOL& fHandled)
  498. {
  499. switch(wNotifyCode)
  500. {
  501. case BN_CLICKED:
  502. case BN_DOUBLECLICKED:
  503. if (!::IsWindowEnabled(m_hSuffix.m_hList))
  504. {
  505. PageModified();
  506. EnableSuffixGroup(TRUE);
  507. CheckDlgButton(IDC_DNS_SEARCH_PARENT_DOMAIN, FALSE);
  508. ::EnableWindow(GetDlgItem(IDC_DNS_SEARCH_PARENT_DOMAIN), FALSE);
  509. }
  510. break;
  511. } // switch
  512. return 0;
  513. }
  514. LRESULT CTcpDnsPage::OnAddSuffix(WORD wNotifyCode, WORD wID,
  515. HWND hWndCtl, BOOL& fHandled)
  516. {
  517. m_fEditState = FALSE;
  518. CSuffixDialog * pDlgSuffix = new CSuffixDialog(this, g_aHelpIDs_IDD_DNS_SUFFIX);
  519. int nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList);
  520. if (pDlgSuffix->DoModal() == IDOK)
  521. {
  522. nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList);
  523. int idx = Tcp_ListBox_InsertString(m_hSuffix.m_hList,
  524. -1,
  525. m_strNewSuffix.c_str());
  526. PageModified();
  527. Assert(idx >= 0);
  528. if (idx >= 0)
  529. {
  530. Tcp_ListBox_SetCurSel(m_hSuffix.m_hList, idx);
  531. SetButtons(m_hSuffix, DNS_MAX_SEARCH_LIST_ENTRIES);
  532. m_strNewSuffix =L"";
  533. }
  534. }
  535. delete pDlgSuffix;
  536. return 0;
  537. }
  538. LRESULT CTcpDnsPage::OnEditSuffix(WORD wNotifyCode, WORD wID,
  539. HWND hWndCtl, BOOL& fHandled)
  540. {
  541. m_fEditState = TRUE;
  542. Assert(Tcp_ListBox_GetCount(m_hSuffix.m_hList));
  543. int idx = Tcp_ListBox_GetCurSel(m_hSuffix.m_hList);
  544. Assert(idx >= 0);
  545. CSuffixDialog * pDlgSuffix = new CSuffixDialog(this,
  546. g_aHelpIDs_IDD_DNS_SUFFIX,
  547. idx);
  548. // save off the removed address and delete if from the listview
  549. if (idx >= 0)
  550. {
  551. WCHAR buf[SUFFIX_LIMIT];
  552. if (Tcp_ListBox_GetTextLen(m_hSuffix.m_hList, idx) >= celems(buf))
  553. {
  554. Assert(FALSE);
  555. return 0;
  556. }
  557. Tcp_ListBox_GetText(m_hSuffix.m_hList, idx, buf);
  558. m_strNewSuffix = buf;
  559. if (pDlgSuffix->DoModal() == IDOK)
  560. {
  561. // replace the item in the listview with the new information
  562. Tcp_ListBox_DeleteString(m_hSuffix.m_hList, idx);
  563. PageModified();
  564. m_strMovingEntry = m_strNewSuffix;
  565. ListBoxInsertAfter(m_hSuffix.m_hList, idx, m_strMovingEntry.c_str());
  566. Tcp_ListBox_SetCurSel(m_hSuffix.m_hList, idx);
  567. m_strNewSuffix = buf; // save off old address
  568. }
  569. else
  570. {
  571. // empty strings, this removes the saved address from RemoveIP
  572. m_strNewSuffix = L"";
  573. }
  574. }
  575. delete pDlgSuffix;
  576. return 0;
  577. }
  578. LRESULT CTcpDnsPage::OnRemoveSuffix(WORD wNotifyCode, WORD wID,
  579. HWND hWndCtl, BOOL& fHandled)
  580. {
  581. int idx = Tcp_ListBox_GetCurSel(m_hSuffix.m_hList);
  582. Assert(idx >=0);
  583. if (idx >=0)
  584. {
  585. WCHAR buf[SUFFIX_LIMIT];
  586. if(Tcp_ListBox_GetTextLen(m_hSuffix.m_hList, idx) >= celems(buf))
  587. {
  588. Assert(FALSE);
  589. return 0;
  590. }
  591. Tcp_ListBox_GetText(m_hSuffix.m_hList, idx, buf);
  592. m_strNewSuffix = buf;
  593. Tcp_ListBox_DeleteString(m_hSuffix.m_hList, idx);
  594. PageModified();
  595. // select a new item
  596. int nCount;
  597. if ((nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList)) != LB_ERR)
  598. if(nCount != LB_ERR)
  599. {
  600. // select the previous item in the list
  601. if (idx)
  602. --idx;
  603. Tcp_ListBox_SetCurSel(m_hSuffix.m_hList, idx);
  604. }
  605. SetButtons(m_hSuffix, DNS_MAX_SEARCH_LIST_ENTRIES);
  606. }
  607. return 0;
  608. }
  609. LRESULT CTcpDnsPage::OnSuffixUp(WORD wNotifyCode, WORD wID,
  610. HWND hWndCtl, BOOL& fHandled)
  611. {
  612. Assert(m_hSuffix.m_hList);
  613. int nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList);
  614. Assert(nCount);
  615. int idx = Tcp_ListBox_GetCurSel(m_hSuffix.m_hList);
  616. Assert(idx != 0);
  617. if (ListBoxRemoveAt(m_hSuffix.m_hList, idx, &m_strMovingEntry) == FALSE)
  618. {
  619. Assert(FALSE);
  620. return 0;
  621. }
  622. --idx;
  623. PageModified();
  624. ListBoxInsertAfter(m_hSuffix.m_hList, idx, m_strMovingEntry.c_str());
  625. Tcp_ListBox_SetCurSel(m_hSuffix.m_hList, idx);
  626. SetButtons(m_hSuffix, DNS_MAX_SEARCH_LIST_ENTRIES);
  627. return 0;
  628. }
  629. LRESULT CTcpDnsPage::OnSuffixDown(WORD wNotifyCode, WORD wID,
  630. HWND hWndCtl, BOOL& fHandled)
  631. {
  632. Assert(m_hSuffix.m_hList);
  633. int nCount = Tcp_ListBox_GetCount(m_hSuffix.m_hList);
  634. Assert(nCount);
  635. int idx = Tcp_ListBox_GetCurSel(m_hSuffix.m_hList);
  636. --nCount;
  637. Assert(idx != nCount);
  638. if (ListBoxRemoveAt(m_hSuffix.m_hList, idx, &m_strMovingEntry) == FALSE)
  639. {
  640. Assert(FALSE);
  641. return 0;
  642. }
  643. ++idx;
  644. PageModified();
  645. ListBoxInsertAfter(m_hSuffix.m_hList, idx, m_strMovingEntry.c_str());
  646. Tcp_ListBox_SetCurSel(m_hSuffix.m_hList, idx);
  647. SetButtons(m_hSuffix, DNS_MAX_SEARCH_LIST_ENTRIES);
  648. return 0;
  649. }
  650. LRESULT CTcpDnsPage::OnServerList(WORD wNotifyCode, WORD wID,
  651. HWND hWndCtl, BOOL& fHandled)
  652. {
  653. switch (wNotifyCode)
  654. {
  655. case LBN_SELCHANGE:
  656. SetButtons(m_hServers, (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_DNS_SERVER : -1);
  657. break;
  658. default:
  659. break;
  660. }
  661. return 0;
  662. }
  663. LRESULT CTcpDnsPage::OnSuffixList(WORD wNotifyCode, WORD wID,
  664. HWND hWndCtl, BOOL& fHandled)
  665. {
  666. switch (wNotifyCode)
  667. {
  668. case LBN_SELCHANGE:
  669. SetButtons(m_hSuffix, DNS_MAX_SEARCH_LIST_ENTRIES);
  670. break;
  671. default:
  672. break;
  673. }
  674. return 0;
  675. }
  676. void CTcpDnsPage::EnableSuffixGroup(BOOL fEnable)
  677. {
  678. ::EnableWindow(m_hSuffix.m_hList, fEnable);
  679. if (fEnable)
  680. {
  681. SetButtons(m_hSuffix, DNS_MAX_SEARCH_LIST_ENTRIES);
  682. }
  683. else
  684. {
  685. ::EnableWindow(m_hSuffix.m_hAdd, fEnable);
  686. ::EnableWindow(m_hSuffix.m_hEdit, fEnable);
  687. ::EnableWindow(m_hSuffix.m_hRemove, fEnable);
  688. ::EnableWindow(m_hSuffix.m_hUp, fEnable);
  689. ::EnableWindow(m_hSuffix.m_hDown, fEnable);
  690. }
  691. }
  692. //
  693. // CServerDialog
  694. //
  695. CServerDialog::CServerDialog(CTcpDnsPage * pTcpDnsPage,
  696. const DWORD * adwHelpIDs,
  697. int iIndex)
  698. {
  699. m_pParentDlg = pTcpDnsPage;
  700. m_hButton = 0;
  701. m_adwHelpIDs = adwHelpIDs;
  702. m_iIndex = iIndex;
  703. }
  704. LRESULT CServerDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  705. LPARAM lParam, BOOL& fHandled)
  706. {
  707. // change the ok button to add if we are not editing
  708. if (m_pParentDlg->m_fEditState == FALSE)
  709. SetDlgItemText(IDOK, m_pParentDlg->m_strAddServer.c_str());
  710. m_ipAddress.Create(m_hWnd, IDC_DNS_CHANGE_SERVER);
  711. m_ipAddress.SetFieldRange(0, c_iIPADDR_FIELD_1_LOW, c_iIPADDR_FIELD_1_HIGH);
  712. // if editing an ip address fill the controls with the current information
  713. // if removing an ip address save it and fill the add dialog with it next time
  714. HWND hList = ::GetDlgItem(m_pParentDlg->m_hWnd, IDC_DNS_SERVER_LIST);
  715. RECT rect;
  716. ::GetWindowRect(hList, &rect);
  717. SetWindowPos(NULL, rect.left, rect.top, 0,0,
  718. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  719. m_hButton = GetDlgItem(IDOK);
  720. // add the address that was just removed
  721. if (m_pParentDlg->m_strNewIpAddress.size())
  722. {
  723. m_ipAddress.SetAddress(m_pParentDlg->m_strNewIpAddress.c_str());
  724. ::EnableWindow(m_hButton, TRUE);
  725. }
  726. else
  727. {
  728. m_pParentDlg->m_strNewIpAddress = L"";
  729. ::EnableWindow(m_hButton, FALSE);
  730. }
  731. ::SetFocus(m_ipAddress);
  732. return 0;
  733. }
  734. LRESULT CServerDialog::OnContextMenu(UINT uMsg, WPARAM wParam,
  735. LPARAM lParam, BOOL& fHandled)
  736. {
  737. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  738. return 0;
  739. }
  740. LRESULT CServerDialog::OnHelp(UINT uMsg, WPARAM wParam,
  741. LPARAM lParam, BOOL& fHandled)
  742. {
  743. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  744. Assert(lphi);
  745. if (HELPINFO_WINDOW == lphi->iContextType)
  746. {
  747. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  748. m_adwHelpIDs);
  749. }
  750. return 0;
  751. }
  752. LRESULT CServerDialog::OnChange(WORD wNotifyCode, WORD wID,
  753. HWND hWndCtl, BOOL& fHandled)
  754. {
  755. if (m_ipAddress.IsBlank())
  756. ::EnableWindow(m_hButton, FALSE);
  757. else
  758. ::EnableWindow(m_hButton, TRUE);
  759. return 0;
  760. }
  761. LRESULT CServerDialog::OnOk(WORD wNotifyCode, WORD wID,
  762. HWND hWndCtl, BOOL& fHandled)
  763. {
  764. tstring strIp;
  765. m_ipAddress.GetAddress(&strIp);
  766. // Validate
  767. if (!FIsIpInRange(strIp.c_str()))
  768. {
  769. // makes ip address lose focus so the control gets
  770. // IPN_FIELDCHANGED notification
  771. // also makes it consistent for when short-cut is used
  772. ::SetFocus(m_hButton);
  773. return 0;
  774. }
  775. //check whether this is a duplicate
  776. int indexDup = Tcp_ListBox_FindStrExact(m_pParentDlg->m_hServers.m_hList, strIp.c_str());
  777. if (indexDup != LB_ERR && indexDup != m_iIndex)
  778. {
  779. NcMsgBox(m_hWnd,
  780. IDS_MSFT_TCP_TEXT,
  781. IDS_DUP_DNS_SERVER,
  782. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK,
  783. strIp.c_str());
  784. return 0;
  785. }
  786. if (m_pParentDlg->m_fEditState == FALSE)
  787. {
  788. // Get the current address from the control and
  789. // add them to the adapter if valid
  790. m_pParentDlg->m_strNewIpAddress = strIp;
  791. EndDialog(IDOK);
  792. }
  793. else // see if either changed
  794. {
  795. if (strIp != m_pParentDlg->m_strNewIpAddress)
  796. m_pParentDlg->m_strNewIpAddress = strIp; // update save addresses
  797. else
  798. EndDialog(IDCANCEL);
  799. }
  800. EndDialog(IDOK);
  801. return 0;
  802. }
  803. LRESULT CServerDialog::OnCancel(WORD wNotifyCode, WORD wID,
  804. HWND hWndCtl, BOOL& fHandled)
  805. {
  806. EndDialog(IDCANCEL);
  807. return 0;
  808. }
  809. //+---------------------------------------------------------------------------
  810. //
  811. // Purpose: Ensure the mouse cursor over the dialog is an Arrow.
  812. //
  813. LRESULT CServerDialog::OnSetCursor (
  814. UINT uMsg,
  815. WPARAM wParam,
  816. LPARAM lParam,
  817. BOOL& bHandled)
  818. {
  819. if (LOWORD(lParam) == HTCLIENT)
  820. {
  821. SetCursor(LoadCursor(NULL, IDC_ARROW));
  822. }
  823. return 0;
  824. }
  825. LRESULT CServerDialog::OnIpFieldChange(int idCtrl, LPNMHDR pnmh,
  826. BOOL& fHandled)
  827. {
  828. LPNMIPADDRESS lpnmipa = (LPNMIPADDRESS) pnmh;
  829. int iLow = c_iIpLow;
  830. int iHigh = c_iIpHigh;
  831. if (0==lpnmipa->iField)
  832. {
  833. iLow = c_iIPADDR_FIELD_1_LOW;
  834. iHigh = c_iIPADDR_FIELD_1_HIGH;
  835. };
  836. IpCheckRange(lpnmipa, m_hWnd, iLow, iHigh);
  837. return 0;
  838. }
  839. //
  840. // CSuffixDialog
  841. //
  842. // iIndex - the index of the current suffix in the suffix list, default value
  843. // is -1, which means new suffix
  844. CSuffixDialog::CSuffixDialog(CTcpDnsPage * pTcpDnsPage,
  845. const DWORD * adwHelpIDs,
  846. int iIndex)
  847. {
  848. m_pParentDlg = pTcpDnsPage;
  849. m_hButton = 0;
  850. m_adwHelpIDs = adwHelpIDs;
  851. m_iIndex = iIndex;
  852. }
  853. LRESULT CSuffixDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  854. LPARAM lParam, BOOL& fHandled)
  855. {
  856. // change the ok button to add if we are not editing
  857. if (m_pParentDlg->m_fEditState == FALSE)
  858. SetDlgItemText(IDOK, m_pParentDlg->m_strAddSuffix.c_str());
  859. // Set the position of the pop up dialog to be right over the listbox
  860. // on parent dialog
  861. HWND hList = ::GetDlgItem(m_pParentDlg->m_hWnd, IDC_DNS_SUFFIX_LIST);
  862. RECT rect;
  863. ::GetWindowRect(hList, &rect);
  864. SetWindowPos(NULL, rect.left, rect.top, 0,0,
  865. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  866. // Save handles to the "Ok" button and the edit box
  867. m_hButton = GetDlgItem(IDOK);
  868. m_hEdit = GetDlgItem(IDC_DNS_CHANGE_SUFFIX);
  869. // suffixes have a 255 character limit
  870. ::SendMessage(m_hEdit, EM_SETLIMITTEXT, SUFFIX_LIMIT, 0);
  871. // add the address that was just removed
  872. if (m_pParentDlg->m_strNewSuffix.size())
  873. {
  874. ::SetWindowText(m_hEdit, m_pParentDlg->m_strNewSuffix.c_str());
  875. ::SendMessage(m_hEdit, EM_SETSEL, 0, -1);
  876. ::EnableWindow(m_hButton, TRUE);
  877. }
  878. else
  879. {
  880. m_pParentDlg->m_strNewSuffix = L"";
  881. ::EnableWindow(m_hButton, FALSE);
  882. }
  883. ::SetFocus(m_hEdit);
  884. return TRUE;
  885. }
  886. LRESULT CSuffixDialog::OnContextMenu(UINT uMsg, WPARAM wParam,
  887. LPARAM lParam, BOOL& fHandled)
  888. {
  889. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  890. return 0;
  891. }
  892. LRESULT CSuffixDialog::OnHelp(UINT uMsg, WPARAM wParam,
  893. LPARAM lParam, BOOL& fHandled)
  894. {
  895. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  896. Assert(lphi);
  897. if (HELPINFO_WINDOW == lphi->iContextType)
  898. {
  899. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  900. m_adwHelpIDs);
  901. }
  902. return 0;
  903. }
  904. LRESULT CSuffixDialog::OnChange(WORD wNotifyCode, WORD wID,
  905. HWND hWndCtl, BOOL& fHandled)
  906. {
  907. WCHAR buf[2];
  908. // Enable or disable the "Ok" button
  909. // based on whether the edit box is empty
  910. if (::GetWindowText(m_hEdit, buf, celems(buf)) == 0)
  911. ::EnableWindow(m_hButton, FALSE);
  912. else
  913. ::EnableWindow(m_hButton, TRUE);
  914. return 0;
  915. }
  916. LRESULT CSuffixDialog::OnOk(WORD wNotifyCode, WORD wID,
  917. HWND hWndCtl, BOOL& fHandled)
  918. {
  919. WCHAR szSuffix[SUFFIX_LIMIT];
  920. // Get the current address from the control and
  921. // add them to the adapter if valid
  922. ::GetWindowText(m_hEdit, szSuffix, SUFFIX_LIMIT);
  923. DNS_STATUS status;
  924. status = DnsValidateName(szSuffix, DnsNameDomain);
  925. if (ERROR_INVALID_NAME == status ||
  926. DNS_ERROR_INVALID_NAME_CHAR == status)
  927. {
  928. TraceTag(ttidTcpip,"Invalid Domain Suffix");
  929. NcMsgBox(::GetActiveWindow(),
  930. IDS_MSFT_TCP_TEXT,
  931. IDS_INVALID_SUFFIX,
  932. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  933. ::SetFocus(m_hEdit);
  934. return 0;
  935. }
  936. //check whether this is a duplicate
  937. int indexDup = Tcp_ListBox_FindStrExact(m_pParentDlg->m_hSuffix.m_hList, szSuffix);
  938. if (indexDup != LB_ERR && indexDup != m_iIndex)
  939. {
  940. NcMsgBox(m_hWnd,
  941. IDS_MSFT_TCP_TEXT,
  942. IDS_DUP_DNS_SUFFIX,
  943. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK,
  944. szSuffix);
  945. ::SetFocus(m_hEdit);
  946. return 0;
  947. }
  948. if (m_pParentDlg->m_fEditState == FALSE) // Add new address
  949. {
  950. m_pParentDlg->m_strNewSuffix = szSuffix;
  951. }
  952. else // see if either changed
  953. {
  954. if(m_pParentDlg->m_strNewSuffix != szSuffix)
  955. m_pParentDlg->m_strNewSuffix = szSuffix; // update save addresses
  956. else
  957. EndDialog(IDCANCEL);
  958. }
  959. EndDialog(IDOK);
  960. return 0;
  961. }
  962. LRESULT CSuffixDialog::OnCancel(WORD wNotifyCode, WORD wID,
  963. HWND hWndCtl, BOOL& fHandled)
  964. {
  965. EndDialog(IDCANCEL);
  966. return 0;
  967. }
  968. //+---------------------------------------------------------------------------
  969. //
  970. // Purpose: Ensure the mouse cursor over the dialog is an Arrow.
  971. //
  972. LRESULT CSuffixDialog::OnSetCursor (
  973. UINT uMsg,
  974. WPARAM wParam,
  975. LPARAM lParam,
  976. BOOL& bHandled)
  977. {
  978. if (LOWORD(lParam) == HTCLIENT)
  979. {
  980. SetCursor(LoadCursor(NULL, IDC_ARROW));
  981. }
  982. return 0;
  983. }