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.

773 lines
18 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ServBrow.cpp
  7. The server browser dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "ServBrow.h"
  12. #include <windns.H>
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. CAuthServerList::CAuthServerList()
  19. : m_pos(NULL), m_bInitialized(FALSE)
  20. {
  21. }
  22. CAuthServerList::~CAuthServerList()
  23. {
  24. Destroy();
  25. }
  26. HRESULT
  27. CAuthServerList::Destroy()
  28. {
  29. CSingleLock sl( &m_cs );
  30. sl.Lock();
  31. ::DhcpDsCleanup();
  32. m_bInitialized = FALSE;
  33. return S_OK;
  34. }
  35. HRESULT
  36. CAuthServerList::Init()
  37. {
  38. DWORD dwErr = ERROR_SUCCESS;
  39. CSingleLock sl(&m_cs); // only one thread at a time in here
  40. sl.Lock();
  41. dwErr = ::DhcpDsInit();
  42. if ( dwErr == ERROR_SUCCESS ) {
  43. m_bInitialized = TRUE;
  44. m_bQueried = FALSE;
  45. }
  46. return HRESULT_FROM_WIN32(dwErr);
  47. }
  48. HRESULT
  49. CAuthServerList::EnumServers( BOOL force )
  50. {
  51. LPDHCP_SERVER_INFO_ARRAY pServerInfoArray = NULL;
  52. DWORD dwErr = ERROR_SUCCESS;
  53. CSingleLock sl( &m_cs );
  54. sl.Lock();
  55. // DS must be initialized before EnumServers() is called.
  56. if ( !m_bInitialized ) {
  57. dwErr = ERROR_FILE_NOT_FOUND;
  58. return HRESULT_FROM_WIN32( dwErr );
  59. }
  60. // Query only if not previously queried or forced.
  61. if (( !m_bQueried ) || ( force )) {
  62. m_bQueried = FALSE;
  63. dwErr = ::DhcpEnumServers(0, NULL, &pServerInfoArray, NULL, NULL);
  64. }
  65. if (( dwErr != ERROR_SUCCESS ) ||
  66. ( m_bQueried )) {
  67. return HRESULT_FROM_WIN32(dwErr);
  68. }
  69. Assert( NULL != pServerInfoArray );
  70. // Stuff the results in to the authorized servers list
  71. Clear();
  72. if ( NULL != pServerInfoArray ) {
  73. for (UINT i = 0; i < pServerInfoArray->NumElements; i++) {
  74. CServerInfo ServerInfo(pServerInfoArray->Servers[i].ServerAddress,
  75. pServerInfoArray->Servers[i].ServerName);
  76. AddTail(ServerInfo);
  77. } // for
  78. // Cleanup allocated memory
  79. DhcpRpcFreeMemory( pServerInfoArray );
  80. } // if
  81. m_bQueried = TRUE;
  82. return S_OK;
  83. } // CAuthServerList::EnumServers()
  84. BOOL
  85. CAuthServerList::IsAuthorized
  86. (
  87. DWORD dwIpAddress
  88. )
  89. {
  90. BOOL bValid = FALSE;
  91. POSITION pos = GetHeadPosition();
  92. while (pos)
  93. {
  94. if (GetNext(pos).m_dwIp == dwIpAddress)
  95. {
  96. bValid = TRUE;
  97. break;
  98. }
  99. }
  100. return bValid;
  101. }
  102. HRESULT
  103. CAuthServerList::AddServer
  104. (
  105. DWORD dwIpAddress,
  106. LPCTSTR pFQDN
  107. )
  108. {
  109. DWORD dwErr = ERROR_SUCCESS;
  110. DHCP_SERVER_INFO dhcpServerInfo = {0};
  111. dhcpServerInfo.ServerAddress = dwIpAddress;
  112. dhcpServerInfo.ServerName = (LPTSTR) pFQDN;
  113. dwErr = ::DhcpAddServer(0, NULL, &dhcpServerInfo, NULL, NULL);
  114. if (dwErr != ERROR_SUCCESS)
  115. return HRESULT_FROM_WIN32(dwErr);
  116. CServerInfo ServerInfo(dwIpAddress, pFQDN);
  117. CSingleLock sl( &m_cs );
  118. sl.Lock();
  119. AddTail(ServerInfo);
  120. return S_OK;
  121. }
  122. HRESULT
  123. CAuthServerList::RemoveServer
  124. (
  125. DWORD dwIpAddress,
  126. LPCTSTR pFQDN
  127. )
  128. {
  129. DWORD dwErr = ERROR_SUCCESS;
  130. DHCP_SERVER_INFO dhcpServerInfo = {0};
  131. POSITION posCurrent;
  132. POSITION pos = GetHeadPosition();
  133. while (pos)
  134. {
  135. posCurrent = pos;
  136. CServerInfo & ServerInfo = GetNext(pos);
  137. if (( ServerInfo.m_dwIp == dwIpAddress) &&
  138. ( ServerInfo.m_strName == pFQDN ))
  139. {
  140. dhcpServerInfo.ServerAddress = ServerInfo.m_dwIp;
  141. dhcpServerInfo.ServerName = (LPTSTR) ((LPCTSTR)ServerInfo.m_strName);
  142. dwErr = ::DhcpDeleteServer(0, NULL, &dhcpServerInfo, NULL, NULL);
  143. if (dwErr == ERROR_SUCCESS)
  144. {
  145. // success, remove from list
  146. CSingleLock sl( &m_cs );
  147. sl.Lock();
  148. RemoveAt(posCurrent);
  149. }
  150. return HRESULT_FROM_WIN32(dwErr);
  151. }
  152. }
  153. return E_INVALIDARG;
  154. }
  155. void
  156. CAuthServerList::Clear()
  157. {
  158. CSingleLock sl( &m_cs );
  159. sl.Lock();
  160. RemoveAll();
  161. }
  162. /*---------------------------------------------------------------------------
  163. CAuthServerWorker
  164. ---------------------------------------------------------------------------*/
  165. CAuthServerWorker::CAuthServerWorker(CAuthServerList ** ppList)
  166. {
  167. m_ppList = ppList;
  168. }
  169. CAuthServerWorker::~CAuthServerWorker()
  170. {
  171. }
  172. void
  173. CAuthServerWorker::OnDoAction()
  174. {
  175. HRESULT hr = hrOK;
  176. m_pAuthList = &g_AuthServerList;
  177. hr = m_pAuthList->Init();
  178. Trace1("CAuthServerWorker::OnDoAction - Init returned %d\n", hr);
  179. hr = m_pAuthList->EnumServers();
  180. Trace1("CAuthServerWorker::OnDoAction - EnumServers returned %d\n", hr);
  181. if (!IsAbandoned())
  182. {
  183. if (m_ppList)
  184. *m_ppList = m_pAuthList;
  185. }
  186. }
  187. /*---------------------------------------------------------------------------
  188. CStandaloneAuthServerWorker
  189. ---------------------------------------------------------------------------*/
  190. CStandaloneAuthServerWorker::CStandaloneAuthServerWorker()
  191. : CAuthServerWorker(NULL)
  192. {
  193. m_bAutoDelete = TRUE;
  194. }
  195. CStandaloneAuthServerWorker::~CStandaloneAuthServerWorker()
  196. {
  197. }
  198. int
  199. CStandaloneAuthServerWorker::Run()
  200. {
  201. OnDoAction();
  202. return 0;
  203. }
  204. int CALLBACK ServerBrowseCompareFunc
  205. (
  206. LPARAM lParam1,
  207. LPARAM lParam2,
  208. LPARAM lParamSort
  209. )
  210. {
  211. return ((CServerBrowse *) lParamSort)->HandleSort(lParam1, lParam2);
  212. }
  213. /////////////////////////////////////////////////////////////////////////////
  214. // CServerBrowse dialog
  215. CServerBrowse::CServerBrowse(BOOL bMultiselect, CWnd* pParent /*=NULL*/)
  216. : CBaseDialog(CServerBrowse::IDD, pParent)
  217. {
  218. //{{AFX_DATA_INIT(CServerBrowse)
  219. //}}AFX_DATA_INIT
  220. m_bMultiselect = bMultiselect;
  221. ResetSort();
  222. }
  223. void CServerBrowse::DoDataExchange(CDataExchange* pDX)
  224. {
  225. CBaseDialog::DoDataExchange(pDX);
  226. //{{AFX_DATA_MAP(CServerBrowse)
  227. DDX_Control(pDX, IDOK, m_buttonOk);
  228. DDX_Control(pDX, IDC_BUTTON_REMOVE, m_buttonRemove);
  229. DDX_Control(pDX, IDC_LIST_VALID_SERVERS, m_listctrlServers);
  230. //}}AFX_DATA_MAP
  231. }
  232. BEGIN_MESSAGE_MAP(CServerBrowse, CBaseDialog)
  233. //{{AFX_MSG_MAP(CServerBrowse)
  234. ON_BN_CLICKED(IDC_BUTTON_REFRESH, OnButtonRefresh)
  235. ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
  236. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_VALID_SERVERS, OnItemchangedListValidServers)
  237. ON_BN_CLICKED(IDC_BUTTON_AUTHORIZE, OnButtonAuthorize)
  238. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_VALID_SERVERS, OnColumnclickListValidServers)
  239. //}}AFX_MSG_MAP
  240. END_MESSAGE_MAP()
  241. /////////////////////////////////////////////////////////////////////////////
  242. // CServerBrowse message handlers
  243. BOOL CServerBrowse::OnInitDialog()
  244. {
  245. CBaseDialog::OnInitDialog();
  246. LV_COLUMN lvColumn;
  247. CString strText;
  248. strText.LoadString(IDS_NAME);
  249. ListView_SetExtendedListViewStyle(m_listctrlServers.GetSafeHwnd(), LVS_EX_FULLROWSELECT);
  250. lvColumn.mask = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH;
  251. lvColumn.fmt = LVCFMT_LEFT;
  252. lvColumn.cx = 175;
  253. lvColumn.pszText = (LPTSTR) (LPCTSTR) strText;
  254. m_listctrlServers.InsertColumn(0, &lvColumn);
  255. strText.LoadString(IDS_IP_ADDRESS);
  256. lvColumn.pszText = (LPTSTR) (LPCTSTR) strText;
  257. lvColumn.cx = 100;
  258. m_listctrlServers.InsertColumn(1, &lvColumn);
  259. FillListCtrl();
  260. UpdateButtons();
  261. if (m_bMultiselect)
  262. {
  263. DWORD dwStyle = ::GetWindowLong(m_listctrlServers.GetSafeHwnd(), GWL_STYLE);
  264. dwStyle &= ~LVS_SINGLESEL;
  265. ::SetWindowLong(m_listctrlServers.GetSafeHwnd(), GWL_EXSTYLE, dwStyle);
  266. }
  267. return TRUE; // return TRUE unless you set the focus to a control
  268. // EXCEPTION: OCX Property Pages should return FALSE
  269. }
  270. void CServerBrowse::OnOK()
  271. {
  272. int nSelectedItem = m_listctrlServers.GetNextItem(-1, LVNI_SELECTED);
  273. while (nSelectedItem != -1)
  274. {
  275. m_astrName.Add(m_listctrlServers.GetItemText(nSelectedItem, 0));
  276. m_astrIp.Add(m_listctrlServers.GetItemText(nSelectedItem, 1));
  277. nSelectedItem = m_listctrlServers.GetNextItem(nSelectedItem, LVNI_SELECTED);
  278. }
  279. CBaseDialog::OnOK();
  280. }
  281. void CServerBrowse::RefreshData()
  282. {
  283. if (m_pServerList)
  284. {
  285. m_pServerList->Clear();
  286. m_pServerList->EnumServers( TRUE );
  287. ResetSort();
  288. FillListCtrl();
  289. }
  290. }
  291. void CServerBrowse::UpdateButtons()
  292. {
  293. // Find the selected item
  294. int nSelectedItem = m_listctrlServers.GetNextItem(-1, LVNI_SELECTED);
  295. BOOL bEnable = (nSelectedItem != -1) ? TRUE : FALSE;
  296. m_buttonOk.EnableWindow(bEnable);
  297. m_buttonRemove.EnableWindow(bEnable);
  298. }
  299. void CServerBrowse::FillListCtrl()
  300. {
  301. CServerInfo ServerInfo;
  302. CString strIp;
  303. int nItem = 0;
  304. m_listctrlServers.DeleteAllItems();
  305. POSITION pos = m_pServerList->GetHeadPosition();
  306. // walk the list and add items to the list control
  307. while (pos != NULL)
  308. {
  309. POSITION lastpos = pos;
  310. // get the next item
  311. ServerInfo = m_pServerList->GetNext(pos);
  312. UtilCvtIpAddrToWstr(ServerInfo.m_dwIp, &strIp);
  313. nItem = m_listctrlServers.InsertItem(nItem, ServerInfo.m_strName);
  314. m_listctrlServers.SetItemText(nItem, 1, strIp);
  315. // save off the position value for sorting later
  316. m_listctrlServers.SetItemData(nItem, (DWORD_PTR) lastpos);
  317. }
  318. Sort(COLUMN_NAME);
  319. }
  320. void CServerBrowse::OnButtonAuthorize()
  321. {
  322. // put up the dialog to get the name and IP address of the server
  323. DWORD err;
  324. CGetServer dlgGetServer;
  325. if (dlgGetServer.DoModal() == IDOK)
  326. {
  327. BEGIN_WAIT_CURSOR;
  328. err = m_pServerList->AddServer(dlgGetServer.m_dwIpAddress, dlgGetServer.m_strName);
  329. if (err != ERROR_SUCCESS)
  330. {
  331. ::DhcpMessageBox(WIN32_FROM_HRESULT(err));
  332. }
  333. else
  334. {
  335. RefreshData();
  336. UpdateButtons();
  337. }
  338. END_WAIT_CURSOR;
  339. }
  340. }
  341. void CServerBrowse::OnButtonRefresh()
  342. {
  343. BEGIN_WAIT_CURSOR;
  344. RefreshData();
  345. UpdateButtons();
  346. END_WAIT_CURSOR;
  347. }
  348. void CServerBrowse::OnButtonRemove()
  349. {
  350. HRESULT hr;
  351. int nSelectedItem = m_listctrlServers.GetNextItem(-1, LVNI_SELECTED);
  352. if (nSelectedItem != -1)
  353. {
  354. CString strIp = m_listctrlServers.GetItemText(nSelectedItem, 1);
  355. CString strFQDN = m_listctrlServers.GetItemText(nSelectedItem, 0);
  356. DWORD dwIp = UtilCvtWstrToIpAddr(strIp);
  357. BEGIN_WAIT_CURSOR;
  358. hr = m_pServerList->RemoveServer(dwIp, strFQDN);
  359. END_WAIT_CURSOR;
  360. if (FAILED(hr))
  361. {
  362. ::DhcpMessageBox(WIN32_FROM_HRESULT(hr));
  363. }
  364. else
  365. {
  366. BEGIN_WAIT_CURSOR;
  367. RefreshData();
  368. UpdateButtons();
  369. END_WAIT_CURSOR;
  370. }
  371. }
  372. // set the focus back to the remove button
  373. SetFocus();
  374. }
  375. void CServerBrowse::OnItemchangedListValidServers(NMHDR* pNMHDR, LRESULT* pResult)
  376. {
  377. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  378. UpdateButtons();
  379. *pResult = 0;
  380. }
  381. void CServerBrowse::OnColumnclickListValidServers(NMHDR* pNMHDR, LRESULT* pResult)
  382. {
  383. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  384. // sort depending on what column was clicked;
  385. Sort(pNMListView->iSubItem);
  386. *pResult = 0;
  387. }
  388. void CServerBrowse::Sort(int nCol)
  389. {
  390. if (m_nSortColumn == nCol)
  391. {
  392. // if the user is clicking the same column again, reverse the sort order
  393. m_aSortOrder[nCol] = m_aSortOrder[nCol] ? FALSE : TRUE;
  394. }
  395. else
  396. {
  397. m_nSortColumn = nCol;
  398. }
  399. m_listctrlServers.SortItems(ServerBrowseCompareFunc, (LPARAM) this);
  400. }
  401. int CServerBrowse::HandleSort(LPARAM lParam1, LPARAM lParam2)
  402. {
  403. int nCompare = 0;
  404. CServerInfo ServerInfo1, ServerInfo2;
  405. ServerInfo1 = m_pServerList->GetAt((POSITION) lParam1);
  406. ServerInfo2 = m_pServerList->GetAt((POSITION) lParam2);
  407. switch (m_nSortColumn)
  408. {
  409. case COLUMN_NAME:
  410. {
  411. nCompare = ServerInfo1.m_strName.CompareNoCase(ServerInfo2.m_strName);
  412. }
  413. // if the names are the same, fall back to the IP address
  414. if (nCompare != 0)
  415. {
  416. break;
  417. }
  418. case COLUMN_IP:
  419. {
  420. if (ServerInfo1.m_dwIp > ServerInfo2.m_dwIp)
  421. nCompare = 1;
  422. else
  423. if (ServerInfo1.m_dwIp < ServerInfo2.m_dwIp)
  424. nCompare = -1;
  425. }
  426. break;
  427. }
  428. if (m_aSortOrder[m_nSortColumn] == FALSE)
  429. {
  430. // descending
  431. return -nCompare;
  432. }
  433. else
  434. {
  435. // ascending
  436. return nCompare;
  437. }
  438. }
  439. void CServerBrowse::ResetSort()
  440. {
  441. m_nSortColumn = -1;
  442. for (int i = 0; i < COLUMN_MAX; i++)
  443. {
  444. m_aSortOrder[i] = TRUE; // ascending
  445. }
  446. }
  447. /////////////////////////////////////////////////////////////////////////////
  448. // CGetServer dialog
  449. CGetServer::CGetServer(CWnd* pParent /*=NULL*/)
  450. : CBaseDialog(CGetServer::IDD, pParent)
  451. {
  452. //{{AFX_DATA_INIT(CGetServer)
  453. // NOTE: the ClassWizard will add member initialization here
  454. //}}AFX_DATA_INIT
  455. m_dwIpAddress = 0;
  456. }
  457. void CGetServer::DoDataExchange(CDataExchange* pDX)
  458. {
  459. CBaseDialog::DoDataExchange(pDX);
  460. //{{AFX_DATA_MAP(CGetServer)
  461. // NOTE: the ClassWizard will add DDX and DDV calls here
  462. //}}AFX_DATA_MAP
  463. }
  464. BEGIN_MESSAGE_MAP(CGetServer, CBaseDialog)
  465. //{{AFX_MSG_MAP(CGetServer)
  466. ON_EN_CHANGE(IDC_EDIT_SERVER_NAME_IP, OnChangeEditServerNameIp)
  467. //}}AFX_MSG_MAP
  468. END_MESSAGE_MAP()
  469. /////////////////////////////////////////////////////////////////////////////
  470. // CGetServer message handlers
  471. BOOL CGetServer::OnInitDialog()
  472. {
  473. CBaseDialog::OnInitDialog();
  474. GetDlgItem(IDOK)->EnableWindow(FALSE);
  475. return TRUE; // return TRUE unless you set the focus to a control
  476. // EXCEPTION: OCX Property Pages should return FALSE
  477. }
  478. void CGetServer::OnOK()
  479. {
  480. CString strNameOrIp;
  481. DWORD err = 0;
  482. DHC_HOST_INFO_STRUCT dhcHostInfo;
  483. BEGIN_WAIT_CURSOR;
  484. GetDlgItem(IDC_EDIT_SERVER_NAME_IP)->GetWindowText(strNameOrIp);
  485. switch (UtilCategorizeName(strNameOrIp))
  486. {
  487. case HNM_TYPE_IP:
  488. m_dwIpAddress = ::UtilCvtWstrToIpAddr( strNameOrIp ) ;
  489. break ;
  490. case HNM_TYPE_NB:
  491. case HNM_TYPE_DNS:
  492. err = ::UtilGetHostAddress( strNameOrIp, &m_dwIpAddress ) ;
  493. m_strName = strNameOrIp; // default
  494. break ;
  495. default:
  496. err = IDS_ERR_BAD_HOST_NAME ;
  497. break;
  498. }
  499. // now that we have the address, try to get the full host info
  500. // an empty host name is valid here, so if we can't find a host
  501. // name then we'll just leave it blank.
  502. if (err == ERROR_SUCCESS)
  503. {
  504. if ( INADDR_LOOPBACK == m_dwIpAddress ) {
  505. ::UtilGetLocalHostAddress( &m_dwIpAddress );
  506. }
  507. err = UtilGetHostInfo(m_dwIpAddress, &dhcHostInfo);
  508. if (err == ERROR_SUCCESS)
  509. {
  510. m_strName = dhcHostInfo._chHostName;
  511. }
  512. }
  513. END_WAIT_CURSOR;
  514. // confirm choice with user, give them a chance to modify our findings
  515. CConfirmAuthorization dlgConfirm;
  516. dlgConfirm.m_strName = m_strName;
  517. dlgConfirm.m_dwAuthAddress = m_dwIpAddress;
  518. if (dlgConfirm.DoModal() != IDOK)
  519. {
  520. return;
  521. }
  522. // use whatever they selected
  523. m_strName = dlgConfirm.m_strName;
  524. m_dwIpAddress = dlgConfirm.m_dwAuthAddress;
  525. CBaseDialog::OnOK();
  526. }
  527. void CGetServer::OnChangeEditServerNameIp()
  528. {
  529. CString strText;
  530. BOOL fEnable = FALSE;
  531. GetDlgItem(IDC_EDIT_SERVER_NAME_IP)->GetWindowText(strText);
  532. // Trim any white spaces
  533. strText.TrimLeft();
  534. strText.TrimRight();
  535. if (( !strText.IsEmpty()) &&
  536. ( -1 == strText.FindOneOf( _T(" \t")))) {
  537. fEnable = TRUE;
  538. }
  539. GetDlgItem(IDOK)->EnableWindow(fEnable);
  540. }
  541. /////////////////////////////////////////////////////////////////////////////
  542. // CConfirmAuthorization dialog
  543. CConfirmAuthorization::CConfirmAuthorization(CWnd* pParent /*=NULL*/)
  544. : CBaseDialog(CConfirmAuthorization::IDD, pParent)
  545. {
  546. //{{AFX_DATA_INIT(CConfirmAuthorization)
  547. m_strName = _T("");
  548. //}}AFX_DATA_INIT
  549. m_dwAuthAddress = 0;
  550. }
  551. void CConfirmAuthorization::DoDataExchange(CDataExchange* pDX)
  552. {
  553. CBaseDialog::DoDataExchange(pDX);
  554. //{{AFX_DATA_MAP(CConfirmAuthorization)
  555. DDX_Text(pDX, IDC_EDIT_AUTH_NAME, m_strName);
  556. //}}AFX_DATA_MAP
  557. DDX_Control(pDX, IDC_IPADDR_AUTH, m_ipaAuth);
  558. }
  559. BEGIN_MESSAGE_MAP(CConfirmAuthorization, CBaseDialog)
  560. //{{AFX_MSG_MAP(CConfirmAuthorization)
  561. //}}AFX_MSG_MAP
  562. END_MESSAGE_MAP()
  563. /////////////////////////////////////////////////////////////////////////////
  564. // CConfirmAuthorization message handlers
  565. BOOL CConfirmAuthorization::OnInitDialog()
  566. {
  567. CBaseDialog::OnInitDialog();
  568. if (m_dwAuthAddress != 0)
  569. {
  570. m_ipaAuth.SetAddress(m_dwAuthAddress);
  571. }
  572. else
  573. {
  574. m_ipaAuth.ClearAddress();
  575. }
  576. return TRUE; // return TRUE unless you set the focus to a control
  577. // EXCEPTION: OCX Property Pages should return FALSE
  578. }
  579. void CConfirmAuthorization::OnOK()
  580. {
  581. DNS_STATUS dnsResult;
  582. m_ipaAuth.GetAddress(&m_dwAuthAddress);
  583. GetDlgItem( IDC_EDIT_AUTH_NAME )->GetWindowText( m_strName );
  584. UpdateData( FALSE );
  585. // Trim leading and trailing white spaces
  586. m_strName.TrimLeft();
  587. m_strName.TrimRight();
  588. dnsResult = DnsValidateName( m_strName, DnsNameDomain );
  589. if (( m_strName.IsEmpty()) ||
  590. ( ERROR_INVALID_NAME == dnsResult ) ||
  591. ( DNS_ERROR_INVALID_NAME_CHAR == dnsResult )) {
  592. DhcpMessageBox( IDS_ERR_BAD_HOST_NAME );
  593. return;
  594. }
  595. if (m_dwAuthAddress == 0)
  596. {
  597. DhcpMessageBox(IDS_ERR_DLL_INVALID_ADDRESS);
  598. m_ipaAuth.SetFocus();
  599. return;
  600. }
  601. UpdateData( FALSE );
  602. CBaseDialog::OnOK();
  603. } // CConfirmAuthorization::OnOK()