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.

1689 lines
44 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1998 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. radcfg.cpp
  7. Implementation file for the RADIUS config object.
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "root.h"
  12. #include "lsa.h"
  13. #include "radcfg.h"
  14. #include "rtrstr.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. // This is used as the seed value for the RtlRunEncodeUnicodeString
  21. // and RtlRunDecodeUnicodeString functions.
  22. #define ENCRYPT_SEED (0xA5)
  23. //max # of digits of the score of a radius server
  24. #define SCORE_MAX_DIGITS 8
  25. //max # of chars in a radius server name
  26. #define MAX_RADIUS_NAME 256
  27. // Const string used when displaying the old secret. It's a fixed length.
  28. const TCHAR c_szDisplayedSecret[] = _T("\b\b\b\b\b\b\b\b");
  29. const int c_nListColumns = 2;
  30. /*!--------------------------------------------------------------------------
  31. RouterAuthRadiusConfig::Initialize
  32. -
  33. Author: KennT
  34. ---------------------------------------------------------------------------*/
  35. HRESULT RouterAuthRadiusConfig::Initialize(LPCOLESTR pszMachineName,
  36. ULONG_PTR *puConnection)
  37. {
  38. HRESULT hr = hrOK;
  39. COM_PROTECT_TRY
  40. {
  41. // for now, allocate a string and have it point at the string
  42. // ------------------------------------------------------------
  43. *puConnection = (ULONG_PTR) StrDupTFromOle(pszMachineName);
  44. }
  45. COM_PROTECT_CATCH;
  46. return hr;
  47. }
  48. /*!--------------------------------------------------------------------------
  49. RouterAuthRadiusConfig::Uninitialize
  50. -
  51. Author: KennT
  52. ---------------------------------------------------------------------------*/
  53. HRESULT RouterAuthRadiusConfig::Uninitialize(ULONG_PTR uConnection)
  54. {
  55. HRESULT hr = hrOK;
  56. COM_PROTECT_TRY
  57. {
  58. delete (TCHAR *) uConnection;
  59. }
  60. COM_PROTECT_CATCH;
  61. return hr;
  62. }
  63. /*!--------------------------------------------------------------------------
  64. RouterAuthRadiusConfig::Configure
  65. -
  66. Author: KennT
  67. ---------------------------------------------------------------------------*/
  68. HRESULT RouterAuthRadiusConfig::Configure(
  69. ULONG_PTR uConnection,
  70. HWND hWnd,
  71. DWORD dwFlags,
  72. ULONG_PTR uReserved1,
  73. ULONG_PTR uReserved2)
  74. {
  75. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  76. RadiusServerDialog authDlg(TRUE, IDS_RADIUS_SERVER_AUTH_TITLE);
  77. // parameter checking
  78. // ----------------------------------------------------------------
  79. if (uConnection == 0)
  80. return E_INVALIDARG;
  81. HRESULT hr = hrOK;
  82. COM_PROTECT_TRY
  83. {
  84. authDlg.SetServer((LPCTSTR) uConnection);
  85. authDlg.DoModal();
  86. }
  87. COM_PROTECT_CATCH;
  88. return hr;
  89. }
  90. /*!--------------------------------------------------------------------------
  91. RouterAuthRadiusConfig::Activate
  92. -
  93. Author: KennT
  94. ---------------------------------------------------------------------------*/
  95. HRESULT RouterAuthRadiusConfig::Activate(
  96. ULONG_PTR uConnection,
  97. ULONG_PTR uReserved1,
  98. ULONG_PTR uReserved2)
  99. {
  100. // parameter checking
  101. // ----------------------------------------------------------------
  102. if (uConnection == 0)
  103. return E_INVALIDARG;
  104. HRESULT hr = hrOK;
  105. COM_PROTECT_TRY
  106. {
  107. }
  108. COM_PROTECT_CATCH;
  109. return hr;
  110. }
  111. /*!--------------------------------------------------------------------------
  112. RouterAuthRadiusConfig::Deactivate
  113. -
  114. Author: KennT
  115. ---------------------------------------------------------------------------*/
  116. HRESULT RouterAuthRadiusConfig::Deactivate(
  117. ULONG_PTR uConnection,
  118. ULONG_PTR uReserved1,
  119. ULONG_PTR uReserved2)
  120. {
  121. // parameter checking
  122. // ----------------------------------------------------------------
  123. if (uConnection == 0)
  124. return E_INVALIDARG;
  125. HRESULT hr = hrOK;
  126. COM_PROTECT_TRY
  127. {
  128. }
  129. COM_PROTECT_CATCH;
  130. return hr;
  131. }
  132. /*---------------------------------------------------------------------------
  133. RadiusServerDialog implementation
  134. ---------------------------------------------------------------------------*/
  135. RadiusServerDialog::RadiusServerDialog(BOOL fAuth, UINT idsTitle)
  136. : CBaseDialog(RadiusServerDialog::IDD),
  137. m_hkeyMachine(NULL),
  138. m_idsTitle(idsTitle),
  139. m_fAuthDialog(fAuth)
  140. {
  141. }
  142. RadiusServerDialog::~RadiusServerDialog()
  143. {
  144. if (m_hkeyMachine)
  145. {
  146. DisconnectRegistry(m_hkeyMachine);
  147. m_hkeyMachine = NULL;
  148. }
  149. }
  150. BEGIN_MESSAGE_MAP(RadiusServerDialog, CBaseDialog)
  151. //{{AFX_MSG_MAP(RadiusServerDialog)
  152. ON_BN_CLICKED(IDC_RADAUTH_BTN_ADD, OnBtnAdd)
  153. ON_BN_CLICKED(IDC_RADAUTH_BTN_EDIT, OnBtnEdit)
  154. ON_BN_CLICKED(IDC_RADAUTH_BTN_DELETE, OnBtnDelete)
  155. ON_NOTIFY(NM_DBLCLK, IDC_RADAUTH_LIST, OnListDblClk)
  156. ON_NOTIFY(LVN_ITEMCHANGED, IDC_RADAUTH_LIST, OnNotifyListItemChanged)
  157. ON_WM_VSCROLL()
  158. //}}AFX_MSG_MAP
  159. END_MESSAGE_MAP()
  160. /*!--------------------------------------------------------------------------
  161. RadiusScoreCompareProc
  162. - The comparison function for sort of radius server list
  163. Author: NSun
  164. ---------------------------------------------------------------------------*/
  165. int CALLBACK RadiusScoreCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lSort)
  166. {
  167. RADIUSSERVER *pServer1 = NULL;
  168. RADIUSSERVER *pServer2 = NULL;
  169. RADIUSSERVER *pServer = NULL;
  170. CRadiusServers *pServerList = (CRadiusServers*)lSort;
  171. for (pServer = pServerList->GetNextServer(TRUE); pServer;
  172. pServer = pServerList->GetNextServer(FALSE) )
  173. {
  174. if (pServer->dwUnique == (DWORD) lParam1)
  175. {
  176. //Server 1 found
  177. pServer1 = pServer;
  178. //if server 2 also found, end search
  179. if (pServer2)
  180. break;
  181. }
  182. else if (pServer->dwUnique == (DWORD) lParam2)
  183. {
  184. //server 2 found
  185. pServer2 = pServer;
  186. //if server 1 also found, end search
  187. if (pServer1)
  188. break;
  189. }
  190. }
  191. if (!pServer1 || !pServer2)
  192. {
  193. Panic0("We can't find the server in the list (but we should)!");
  194. return 0;
  195. }
  196. else
  197. return pServer2->cScore - pServer1->cScore;
  198. }
  199. /*!--------------------------------------------------------------------------
  200. RadiusServerDialog::DoDataExchange
  201. -
  202. Author: KennT
  203. ---------------------------------------------------------------------------*/
  204. void RadiusServerDialog::DoDataExchange(CDataExchange* pDX)
  205. {
  206. CBaseDialog::DoDataExchange(pDX);
  207. //{{AFX_DATA_MAP(RadiusServerDialog)
  208. DDX_Control(pDX, IDC_RADAUTH_LIST, m_ListServers);
  209. //}}AFX_DATA_MAP
  210. }
  211. /*!--------------------------------------------------------------------------
  212. RadiusServerDialog::SetServer
  213. Sets the name of the machine we are looking at.
  214. Author: KennT
  215. ---------------------------------------------------------------------------*/
  216. void RadiusServerDialog::SetServer(LPCTSTR pszServerName)
  217. {
  218. m_stServerName = pszServerName;
  219. }
  220. /*!--------------------------------------------------------------------------
  221. RadiusServerDialog::OnInitDialog
  222. -
  223. Author: KennT
  224. ---------------------------------------------------------------------------*/
  225. BOOL RadiusServerDialog::OnInitDialog()
  226. {
  227. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  228. RADIUSSERVER * pServer;
  229. int iPos;
  230. CString stTitle;
  231. LV_COLUMN lvCol; // list view column struct for radius servers
  232. RECT rect;
  233. CBaseDialog::OnInitDialog();
  234. ListView_SetExtendedListViewStyle(m_ListServers.GetSafeHwnd(),
  235. LVS_EX_FULLROWSELECT);
  236. Assert(m_hkeyMachine == 0);
  237. stTitle.LoadString(m_idsTitle);
  238. SetWindowText(stTitle);
  239. // Connect to the machine (get the registry key)
  240. if (ConnectRegistry(m_stServerName, &m_hkeyMachine) != ERROR_SUCCESS)
  241. {
  242. //$ TODO : put in error messages here
  243. // we failed to connect, error out
  244. OnCancel();
  245. return TRUE;
  246. }
  247. // Get the list of RADIUS servers
  248. LoadRadiusServers(m_stServerName,
  249. m_hkeyMachine,
  250. m_fAuthDialog,
  251. &m_ServerList,
  252. 0);
  253. // Get the other list of RADIUS servers
  254. LoadRadiusServers(m_stServerName,
  255. m_hkeyMachine,
  256. !m_fAuthDialog,
  257. &m_OtherServerList,
  258. RADIUS_FLAG_NOUI | RADIUS_FLAG_NOIP);
  259. m_ListServers.GetClientRect(&rect);
  260. int nColWidth = rect.right / c_nListColumns;
  261. lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
  262. lvCol.fmt = LVCFMT_LEFT;
  263. lvCol.cx = nColWidth;
  264. CString stColCaption;
  265. for(int index = 0; index < c_nListColumns; index++)
  266. {
  267. stColCaption.LoadString((0 == index) ? IDS_RADIUS_CONFIG_RADIUS: IDS_RADIUS_CONFIG_SCORE);
  268. lvCol.pszText = (LPTSTR)((LPCTSTR) stColCaption);
  269. m_ListServers.InsertColumn(index, &lvCol);
  270. }
  271. // Now iterate through the server list and add the servers to the
  272. // list box
  273. LV_ITEM lvItem;
  274. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  275. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  276. lvItem.state = 0;
  277. int nCount = 0;
  278. TCHAR szBufScore[SCORE_MAX_DIGITS];
  279. for (pServer = m_ServerList.GetNextServer(TRUE); pServer;
  280. pServer = m_ServerList.GetNextServer(FALSE) )
  281. {
  282. lvItem.iItem = nCount;
  283. lvItem.iSubItem = 0;
  284. lvItem.pszText = pServer->szName;
  285. lvItem.lParam = pServer->dwUnique; //same functionality as SetItemData()
  286. iPos = m_ListServers.InsertItem(&lvItem);
  287. if (iPos != -1)
  288. {
  289. _itot(pServer->cScore, szBufScore, 10);
  290. m_ListServers.SetItemText(iPos, 1, szBufScore);
  291. nCount++;
  292. }
  293. }
  294. if (m_ListServers.GetItemCount())
  295. {
  296. m_ListServers.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  297. m_ListServers.SortItems(RadiusScoreCompareProc, (LPARAM)&m_ServerList);
  298. }
  299. else
  300. {
  301. GetDlgItem(IDC_RADAUTH_BTN_DELETE)->EnableWindow(FALSE);
  302. GetDlgItem(IDC_RADAUTH_BTN_EDIT)->EnableWindow(FALSE);
  303. }
  304. return TRUE;
  305. }
  306. /*!--------------------------------------------------------------------------
  307. RadiusServerDialog::OnOK
  308. -
  309. Author: KennT
  310. ---------------------------------------------------------------------------*/
  311. void RadiusServerDialog::OnOK()
  312. {
  313. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  314. RADIUSSERVER * pServer;
  315. HRESULT hr = hrOK;
  316. // fix 8155 rajeshp 06/15/1998 RADIUS: Updating of the radius server entries in the snapin requires a restart of remoteaccess.
  317. DWORD dwMajor = 0, dwMinor = 0, dwBuildNo = 0;
  318. GetNTVersion(m_hkeyMachine, &dwMajor, &dwMinor, &dwBuildNo);
  319. DWORD dwVersionCombine = MAKELONG( dwBuildNo, MAKEWORD(dwMinor, dwMajor));
  320. DWORD dwVersionCombineNT50 = MAKELONG ( VER_BUILD_WIN2K, MAKEWORD(VER_MINOR_WIN2K, VER_MAJOR_WIN2K));
  321. // if the version is greater than Win2K release
  322. if(dwVersionCombine > dwVersionCombineNT50)
  323. ; // skip the restart message
  324. else
  325. AfxMessageBox(IDS_WRN_RADIUS_PARAMS_CHANGING);
  326. // Clear out the deleted server list
  327. // Do this before we save the list (otherwise the list
  328. // may have an LSA entry that we will delete).
  329. // ----------------------------------------------------------------
  330. m_ServerList.ClearDeletedServerList(m_stServerName);
  331. pServer = m_ServerList.GetNextServer(TRUE);
  332. hr = SaveRadiusServers(m_stServerName,
  333. m_hkeyMachine,
  334. m_fAuthDialog,
  335. pServer);
  336. if (!FHrSucceeded(hr))
  337. {
  338. DisplayErrorMessage(GetSafeHwnd(), hr);
  339. return;
  340. }
  341. CBaseDialog::OnOK();
  342. }
  343. /*!--------------------------------------------------------------------------
  344. RadiusServerDialog::OnBtnAdd
  345. -
  346. Author: KennT
  347. ---------------------------------------------------------------------------*/
  348. void RadiusServerDialog::OnBtnAdd()
  349. {
  350. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  351. ServerPropDialog * pServerDlg;
  352. RADIUSSERVER server;
  353. int iPos;
  354. ServerPropDialog authDlg(FALSE);
  355. ServerPropAcctDialog acctDlg(FALSE);
  356. if (m_fAuthDialog)
  357. pServerDlg = &authDlg;
  358. else
  359. pServerDlg = &acctDlg;
  360. if (pServerDlg->DoModal() == IDOK)
  361. {
  362. ZeroMemory(&server, sizeof(server));
  363. pServerDlg->GetDefault(&server);
  364. CString stText;
  365. BOOL bFound = FALSE;
  366. int nCount = m_ListServers.GetItemCount();
  367. if(nCount > 0)
  368. {
  369. TCHAR szRadSrvName[MAX_RADIUS_NAME];
  370. //we need case insensitive comparation, so cannot use CListBox::FindStringExact()
  371. for(int iIndex = 0; iIndex < nCount; iIndex++)
  372. {
  373. m_ListServers.GetItemText(iIndex, 0, szRadSrvName, MAX_RADIUS_NAME);
  374. if(lstrcmpi(szRadSrvName, server.szName) == 0)
  375. {
  376. bFound = TRUE;
  377. break;
  378. }
  379. }
  380. }
  381. //if the server is already is the list, we won't add it.
  382. if(bFound)
  383. {
  384. CString stText;
  385. stText.Format(IDS_ERR_RADIUS_DUP_NAME, server.szName);
  386. AfxMessageBox((LPCTSTR)stText, MB_OK | MB_ICONEXCLAMATION);
  387. }
  388. else
  389. {
  390. // Add to the server list
  391. m_ServerList.AddServer(&server, 0);
  392. // Add to the list control
  393. TCHAR szBuf[SCORE_MAX_DIGITS];
  394. LV_ITEM lvItem;
  395. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  396. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  397. lvItem.state = 0;
  398. lvItem.iItem = 0;
  399. lvItem.iSubItem = 0;
  400. lvItem.pszText = server.szName;
  401. lvItem.lParam = server.dwUnique; //same functionality as SetItemData()
  402. iPos = m_ListServers.InsertItem(&lvItem);
  403. _itot(server.cScore, szBuf, 10);
  404. m_ListServers.SetItemText(iPos, 1, szBuf);
  405. if (iPos != -1)
  406. {
  407. //if no radius server in the list previously, select the new added server.
  408. // (and enable "edit" and "delete" buttons in OnNotifyListItemChanged()
  409. if (nCount == 0)
  410. m_ListServers.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  411. m_ListServers.SortItems(RadiusScoreCompareProc, (LPARAM)&m_ServerList);
  412. }
  413. }
  414. }
  415. }
  416. /*!--------------------------------------------------------------------------
  417. RadiusServerDialog::OnBtnDelete
  418. -
  419. Author: KennT
  420. ---------------------------------------------------------------------------*/
  421. void RadiusServerDialog::OnBtnDelete()
  422. {
  423. // Get the selection and delete it
  424. int iPos;
  425. ULONG_PTR dwUnique;
  426. RADIUSSERVER * pServer = NULL;
  427. BOOL fRemoveLSAEntry = FALSE;
  428. iPos = m_ListServers.GetNextItem(-1, LVNI_SELECTED);
  429. if (iPos == -1)
  430. return;
  431. dwUnique = m_ListServers.GetItemData(iPos);
  432. // Does this server exist in the other list
  433. Verify( m_ServerList.FindServer((DWORD) dwUnique, &pServer) );
  434. Assert(pServer);
  435. // If we find this server in the other list, we can't remove its
  436. // LSA entry
  437. fRemoveLSAEntry = !m_OtherServerList.FindServer(pServer->szName, NULL);
  438. m_ServerList.DeleteServer(dwUnique, fRemoveLSAEntry);
  439. m_ListServers.DeleteItem(iPos);
  440. // See if we can move the selection to the next item in the list
  441. // if that fails, try to set it to the previous item
  442. if (!m_ListServers.SetItemState(iPos, LVIS_SELECTED, LVIS_SELECTED))
  443. m_ListServers.SetItemState(iPos - 1, LVIS_SELECTED, LVIS_SELECTED);
  444. }
  445. /*!--------------------------------------------------------------------------
  446. RadiusServerDialog::OnBtnEdit
  447. -
  448. Author: KennT
  449. ---------------------------------------------------------------------------*/
  450. void RadiusServerDialog::OnBtnEdit()
  451. {
  452. ServerPropDialog * pServerDlg;
  453. RADIUSSERVER server;
  454. RADIUSSERVER * pServer;
  455. int iOldPos, iPos;
  456. LONG_PTR dwUnique;
  457. ServerPropDialog authDlg(TRUE);
  458. ServerPropAcctDialog acctDlg(TRUE);
  459. if (m_fAuthDialog)
  460. pServerDlg = &authDlg;
  461. else
  462. pServerDlg = &acctDlg;
  463. iOldPos = m_ListServers.GetNextItem(-1, LVNI_SELECTED);
  464. if (iOldPos == -1)
  465. return;
  466. dwUnique = m_ListServers.GetItemData(iOldPos);
  467. // Need to look for server data that matches this one
  468. // Now iterate through the server list and add the servers to the
  469. // list box
  470. for (pServer = m_ServerList.GetNextServer(TRUE); pServer;
  471. pServer = m_ServerList.GetNextServer(FALSE) )
  472. {
  473. if (pServer->dwUnique == (DWORD) dwUnique)
  474. break;
  475. }
  476. if (!pServer)
  477. {
  478. Panic0("We can't find the server in the list (but we should)!");
  479. return;
  480. }
  481. pServerDlg->SetDefault(pServer);
  482. if (pServerDlg->DoModal() == IDOK)
  483. {
  484. ZeroMemory(&server, sizeof(server));
  485. pServerDlg->GetDefault(&server);
  486. // Add to the server list, need to add this at the proper place
  487. m_ServerList.AddServer(&server, dwUnique);
  488. // Delete the old server data
  489. m_ServerList.DeleteServer(dwUnique, FALSE);
  490. m_ListServers.DeleteItem(iOldPos);
  491. pServer = NULL;
  492. // Add to the list control
  493. TCHAR szBuf[SCORE_MAX_DIGITS];
  494. LV_ITEM lvItem;
  495. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  496. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  497. lvItem.state = 0;
  498. lvItem.iItem = iOldPos;
  499. lvItem.iSubItem = 0;
  500. lvItem.pszText = server.szName;
  501. lvItem.lParam = server.dwUnique; //same functionality as SetItemData()
  502. iPos = m_ListServers.InsertItem(&lvItem);
  503. _itot(server.cScore, szBuf, 10);
  504. m_ListServers.SetItemText(iPos, 1, szBuf);
  505. if (iPos != -1)
  506. {
  507. // Reset the current selection
  508. m_ListServers.SetItemState(iPos, LVIS_SELECTED, LVIS_SELECTED);
  509. m_ListServers.SortItems(RadiusScoreCompareProc, (LPARAM)&m_ServerList);
  510. }
  511. ZeroMemory(&server, sizeof(server));
  512. }
  513. }
  514. /*!--------------------------------------------------------------------------
  515. RadiusServerDialog::OnListDblClk
  516. -
  517. Author: KennT
  518. ---------------------------------------------------------------------------*/
  519. void RadiusServerDialog::OnListDblClk(NMHDR *pNMHdr, LRESULT *pResult)
  520. {
  521. OnBtnEdit();
  522. }
  523. /*!--------------------------------------------------------------------------
  524. RadiusServerDialog::OnNotifyListItemChanged
  525. -
  526. Author: KennT
  527. ---------------------------------------------------------------------------*/
  528. void RadiusServerDialog::OnNotifyListItemChanged(NMHDR *pNMHdr, LRESULT *pResult)
  529. {
  530. NMLISTVIEW * pnmlv = reinterpret_cast<NMLISTVIEW *>(pNMHdr);
  531. int iPos;
  532. if ((pnmlv->uNewState & LVIS_SELECTED) != (pnmlv->uOldState & LVIS_SELECTED))
  533. {
  534. iPos = m_ListServers.GetNextItem(-1, LVNI_SELECTED);
  535. GetDlgItem(IDC_RADAUTH_BTN_DELETE)->EnableWindow(iPos != -1);
  536. GetDlgItem(IDC_RADAUTH_BTN_EDIT)->EnableWindow(iPos != -1);
  537. }
  538. *pResult = 0;
  539. }
  540. //**
  541. //
  542. // Call: LoadRadiusServers
  543. //
  544. // Returns: NO_ERROR - Success
  545. // Non-zero returns - Failure
  546. //
  547. // Description:
  548. //
  549. HRESULT
  550. LoadRadiusServers(
  551. IN LPCTSTR pszServerName,
  552. IN HKEY hkeyMachine,
  553. IN BOOL fAuthentication,
  554. IN CRadiusServers * pRadiusServers,
  555. IN DWORD dwFlags
  556. )
  557. {
  558. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  559. HRESULT hr = hrOK;
  560. DWORD dwErrorCode;
  561. BOOL fValidServer = FALSE;
  562. RegKey regkeyServers;
  563. RegKeyIterator regkeyIter;
  564. HRESULT hrIter;
  565. CString stKey;
  566. RegKey regkeyServer;
  567. DWORD dwData;
  568. WSADATA wsadata;
  569. BOOL fWSInitialized = FALSE;
  570. DWORD wsaerr = 0;
  571. COM_PROTECT_TRY
  572. {
  573. // DWORD dwKeyIndex, cbKeyServer, cbValue;
  574. // TCHAR szKeyServer[MAX_PATH+1];
  575. CHAR szName[MAX_PATH+1];
  576. RADIUSSERVER RadiusServer;
  577. CWaitCursor waitCursor;
  578. ZeroMemory(&RadiusServer, sizeof(RadiusServer));
  579. Assert(pRadiusServers != NULL);
  580. Assert(hkeyMachine);
  581. wsaerr = WSAStartup(0x0101, &wsadata);
  582. if (wsaerr)
  583. {
  584. // Need to setup a winsock error
  585. hr = E_FAIL;
  586. goto Error;
  587. }
  588. // Winsock successfully initialized
  589. fWSInitialized = TRUE;
  590. CWRg( regkeyServers.Open(hkeyMachine,
  591. fAuthentication ?
  592. c_szRadiusAuthServersKey :
  593. c_szRadiusAcctServersKey,
  594. KEY_READ) );
  595. CORg( regkeyIter.Init(&regkeyServers) );
  596. for (hrIter=regkeyIter.Next(&stKey); hrIter == hrOK;
  597. hrIter=regkeyIter.Next(&stKey), regkeyServer.Close())
  598. {
  599. CWRg( regkeyServer.Open(regkeyServers, stKey, KEY_READ) );
  600. ZeroMemory( &RadiusServer, sizeof( RadiusServer ) );
  601. // Copy the name over
  602. StrnCpy(RadiusServer.szName, stKey, MAX_PATH);
  603. // Since we're reading this in from the registry, it's
  604. // been persisted
  605. RadiusServer.fPersisted = TRUE;
  606. // Get the timeout value
  607. dwErrorCode = regkeyServer.QueryValue(c_szTimeout, dwData);
  608. if ( dwErrorCode != NO_ERROR )
  609. RadiusServer.Timeout.tv_sec = DEFTIMEOUT;
  610. else
  611. RadiusServer.Timeout.tv_sec = dwData;
  612. //
  613. // Secret Value is required
  614. //
  615. CWRg( RetrievePrivateData( pszServerName,
  616. RadiusServer.szName,
  617. RadiusServer.wszSecret,
  618. DimensionOf(RadiusServer.wszSecret)) );
  619. RadiusServer.cchSecret = lstrlen(RadiusServer.wszSecret);
  620. // Encode the password, do not store it as plain text
  621. // Decode as needed.
  622. RadiusServer.ucSeed = ENCRYPT_SEED;
  623. RtlEncodeW(&RadiusServer.ucSeed, RadiusServer.wszSecret);
  624. //
  625. // read in port numbers
  626. //
  627. // Get the AuthPort
  628. if (fAuthentication)
  629. {
  630. dwErrorCode = regkeyServer.QueryValue( c_szAuthPort, dwData );
  631. if ( dwErrorCode != NO_ERROR )
  632. RadiusServer.AuthPort = DEFAUTHPORT;
  633. else
  634. RadiusServer.AuthPort = dwData;
  635. // Windows NT Bug : 311398
  636. // Get the Digital Signature data
  637. if (dwErrorCode == NO_ERROR)
  638. dwErrorCode = regkeyServer.QueryValue( c_szRegValSendSignature, dwData );
  639. if (dwErrorCode == NO_ERROR)
  640. RadiusServer.fUseDigitalSignatures = dwData;
  641. else
  642. RadiusServer.fUseDigitalSignatures = FALSE;
  643. }
  644. else
  645. {
  646. // Get the AcctPort
  647. dwErrorCode = regkeyServer.QueryValue(c_szAcctPort, dwData );
  648. if ( dwErrorCode != NO_ERROR )
  649. RadiusServer.AcctPort = DEFACCTPORT;
  650. else
  651. RadiusServer.AcctPort = dwData;
  652. // Get the EnableAccounting On/Off flag
  653. dwErrorCode = regkeyServer.QueryValue( c_szEnableAccountingOnOff,
  654. dwData );
  655. if ( dwErrorCode != NO_ERROR )
  656. RadiusServer.fAccountingOnOff = TRUE;
  657. else
  658. RadiusServer.fAccountingOnOff = dwData;
  659. }
  660. // Get the score
  661. dwErrorCode = regkeyServer.QueryValue( c_szScore, dwData );
  662. if ( dwErrorCode != NO_ERROR )
  663. RadiusServer.cScore = MAXSCORE;
  664. else
  665. RadiusServer.cScore = dwData;
  666. RadiusServer.cRetries = 1;
  667. //
  668. // Convert name to ip address.
  669. //
  670. if ( INET_ADDR( RadiusServer.szName ) == INADDR_NONE )
  671. {
  672. // resolve name
  673. struct hostent * phe = NULL;
  674. if (dwFlags & RADIUS_FLAG_NOIP)
  675. phe = NULL;
  676. else
  677. {
  678. StrnCpyAFromT(szName, RadiusServer.szName,
  679. DimensionOf(szName));
  680. phe = gethostbyname( szName );
  681. }
  682. if ( phe != NULL )
  683. {
  684. // host could have multiple addresses
  685. // BUG#185732 (nsun 11/04/98) We only load the first Ip Address
  686. if( phe->h_addr_list[0] != NULL )
  687. {
  688. RadiusServer.IPAddress.sin_family = AF_INET;
  689. RadiusServer.IPAddress.sin_port =
  690. htons((SHORT) RadiusServer.AuthPort);
  691. RadiusServer.IPAddress.sin_addr.S_un.S_addr =
  692. *((PDWORD) phe->h_addr_list[0]);
  693. }
  694. }
  695. else
  696. {
  697. if ((dwFlags & RADIUS_FLAG_NOUI) == 0)
  698. {
  699. CString stText;
  700. stText.Format(IDS_ERR_RADIUS_INVALID_NAME, RadiusServer.szName);
  701. AfxMessageBox((LPCTSTR)stText, MB_OK | MB_ICONEXCLAMATION);
  702. waitCursor.Restore();
  703. }
  704. }
  705. }
  706. else
  707. {
  708. //
  709. // use specified ip address
  710. //
  711. RadiusServer.IPAddress.sin_family = AF_INET;
  712. RadiusServer.IPAddress.sin_port =
  713. htons((SHORT) RadiusServer.AuthPort);
  714. RadiusServer.IPAddress.sin_addr.S_un.S_addr = INET_ADDR(RadiusServer.szName);
  715. }
  716. if ( pRadiusServers != NULL )
  717. {
  718. fValidServer = (pRadiusServers->AddServer(&RadiusServer, (DWORD) -1)
  719. == NO_ERROR
  720. ? TRUE
  721. : FALSE);
  722. }
  723. }
  724. COM_PROTECT_ERROR_LABEL;
  725. }
  726. COM_PROTECT_CATCH;
  727. if (fWSInitialized)
  728. WSACleanup();
  729. //
  730. // if no servers entries are found in registry return error code.
  731. //
  732. if ( ( fValidServer == FALSE ) && FHrSucceeded(hr) )
  733. {
  734. hr = HRESULT_FROM_WIN32(ERROR_NO_RADIUS_SERVERS);
  735. }
  736. return( hr );
  737. }
  738. //**
  739. //
  740. // Call: SaveRadiusServers
  741. //
  742. // Returns: NO_ERROR - Success
  743. // Non-zero returns - Failure
  744. //
  745. // Description:
  746. //
  747. HRESULT
  748. SaveRadiusServers(LPCTSTR pszServerName,
  749. HKEY hkeyMachine,
  750. IN BOOL fAuthentication,
  751. IN RADIUSSERVER * pServerRoot
  752. )
  753. {
  754. HRESULT hr = hrOK;
  755. RADIUSSERVER *pServer;
  756. DWORD dwErrorCode;
  757. RegKey regkeyMachine;
  758. RegKey regkeyServers, regkeyServer;
  759. DWORD dwData;
  760. pServer = pServerRoot;
  761. COM_PROTECT_TRY
  762. {
  763. regkeyMachine.Attach(hkeyMachine);
  764. regkeyMachine.RecurseDeleteKey(fAuthentication ?
  765. c_szRadiusAuthServersKey :
  766. c_szRadiusAcctServersKey);
  767. CWRg( regkeyServers.Create(hkeyMachine,
  768. fAuthentication ?
  769. c_szRadiusAuthServersKey :
  770. c_szRadiusAcctServersKey) );
  771. while( pServer != NULL )
  772. {
  773. CWRg( regkeyServer.Create(regkeyServers, pServer->szName) );
  774. // Need to unencode the private data
  775. RtlDecodeW(pServer->ucSeed, pServer->wszSecret);
  776. dwErrorCode = StorePrivateData(pszServerName,
  777. pServer->szName,
  778. pServer->wszSecret);
  779. RtlEncodeW(&pServer->ucSeed, pServer->wszSecret);
  780. CWRg( dwErrorCode );
  781. // Ok, we've saved the information
  782. pServer->fPersisted = TRUE;
  783. dwData = pServer->Timeout.tv_sec;
  784. CWRg( regkeyServer.SetValue(c_szTimeout, dwData) );
  785. if (fAuthentication)
  786. {
  787. dwData = pServer->AuthPort;
  788. CWRg( regkeyServer.SetValue(c_szAuthPort, dwData) );
  789. // Windows NT Bug: 311398
  790. // Save the digital signature data
  791. dwData = pServer->fUseDigitalSignatures;
  792. CWRg( regkeyServer.SetValue(c_szRegValSendSignature, dwData) );
  793. }
  794. else
  795. {
  796. dwData = pServer->AcctPort;
  797. CWRg( regkeyServer.SetValue(c_szAcctPort, dwData) );
  798. dwData = pServer->fAccountingOnOff;
  799. CWRg( regkeyServer.SetValue(c_szEnableAccountingOnOff, dwData) );
  800. }
  801. dwData = pServer->cScore;
  802. CWRg( regkeyServer.SetValue(c_szScore, dwData) );
  803. regkeyServer.Close();
  804. pServer = pServer->pNext;
  805. }
  806. COM_PROTECT_ERROR_LABEL;
  807. }
  808. COM_PROTECT_CATCH;
  809. regkeyMachine.Detach();
  810. return hr;
  811. }
  812. /*!--------------------------------------------------------------------------
  813. DeleteRadiusServers
  814. DANGER! Do NOT call this unless you absolutely know this is
  815. what you need. The problem is that there is no way to
  816. distinguish between accouting/authentication entries, thus an
  817. external reference check must be made.
  818. Author: KennT
  819. ---------------------------------------------------------------------------*/
  820. HRESULT
  821. DeleteRadiusServers(LPCTSTR pszServerName,
  822. RADIUSSERVER * pServerRoot
  823. )
  824. {
  825. HRESULT hr = hrOK;
  826. RADIUSSERVER *pServer;
  827. pServer = pServerRoot;
  828. COM_PROTECT_TRY
  829. {
  830. while( pServer != NULL )
  831. {
  832. if (pServer->fPersisted)
  833. DeletePrivateData(pszServerName,
  834. pServer->szName);
  835. pServer = pServer->pNext;
  836. }
  837. }
  838. COM_PROTECT_CATCH;
  839. return hr;
  840. }
  841. /*---------------------------------------------------------------------------
  842. ServerPropDialog implementation
  843. ---------------------------------------------------------------------------*/
  844. ServerPropDialog::ServerPropDialog(BOOL fEdit, CWnd* pParent /*=NULL*/)
  845. : CBaseDialog(ServerPropDialog::IDD, pParent),
  846. m_fEdit(fEdit)
  847. {
  848. //{{AFX_DATA_INIT(ServerPropDialog)
  849. m_uAuthPort = DEFAUTHPORT;
  850. m_uAcctPort = DEFACCTPORT;
  851. m_stSecret.Empty();
  852. m_cchSecret = 0;
  853. m_ucSeed = ENCRYPT_SEED;
  854. m_stServer.Empty();
  855. m_uTimeout = DEFTIMEOUT;
  856. m_iInitScore = MAXSCORE;
  857. m_fAccountingOnOff = FALSE;
  858. m_fUseDigitalSignatures = FALSE;
  859. //}}AFX_DATA_INIT
  860. }
  861. ServerPropDialog::ServerPropDialog(BOOL fEdit, UINT idd, CWnd* pParent /*=NULL*/)
  862. : CBaseDialog(idd, pParent),
  863. m_fEdit(fEdit)
  864. {
  865. //{{AFX_DATA_INIT(ServerPropDialog)
  866. m_uAuthPort = DEFAUTHPORT;
  867. m_uAcctPort = DEFACCTPORT;
  868. m_stSecret.Empty();
  869. m_cchSecret = 0;
  870. m_ucSeed = ENCRYPT_SEED;
  871. m_stServer.Empty();
  872. m_uTimeout = DEFTIMEOUT;
  873. m_iInitScore = MAXSCORE;
  874. m_fAccountingOnOff = FALSE;
  875. m_fUseDigitalSignatures = FALSE;
  876. //}}AFX_DATA_INIT
  877. }
  878. ServerPropDialog::~ServerPropDialog()
  879. {
  880. ZeroMemory(m_stSecret.GetBuffer(0),
  881. m_stSecret.GetLength() * sizeof(TCHAR));
  882. m_stSecret.ReleaseBuffer(-1);
  883. }
  884. void ServerPropDialog::DoDataExchange(CDataExchange* pDX)
  885. {
  886. CDialog::DoDataExchange(pDX);
  887. //{{AFX_DATA_MAP(ServerPropDialog)
  888. DDX_Control(pDX, IDC_RAC_EDIT_SERVER, m_editServerName);
  889. DDX_Control(pDX, IDC_RAC_EDIT_SECRET, m_editSecret);
  890. DDX_Control(pDX, IDC_RAC_EDIT_PORT, m_editPort);
  891. DDX_Control(pDX, IDC_RAC_SPIN_SCORE, m_spinScore);
  892. DDX_Control(pDX, IDC_RAC_SPIN_TIMEOUT, m_spinTimeout);
  893. DDX_Text(pDX, IDC_RAC_EDIT_PORT, m_uAuthPort);
  894. DDX_Text(pDX, IDC_RAC_EDIT_SERVER, m_stServer);
  895. DDX_Text(pDX, IDC_RAC_EDIT_TIMEOUT, m_uTimeout);
  896. DDX_Text(pDX, IDC_RAC_EDIT_SCORE, m_iInitScore);
  897. //}}AFX_DATA_MAP
  898. }
  899. BEGIN_MESSAGE_MAP(ServerPropDialog, CBaseDialog)
  900. //{{AFX_MSG_MAP(ServerPropDialog)
  901. ON_BN_CLICKED(IDC_RAC_BTN_CHANGE, OnBtnPassword)
  902. // ON_WM_CONTEXTMENU()
  903. // ON_WM_HELPINFO()
  904. //}}AFX_MSG_MAP
  905. END_MESSAGE_MAP()
  906. /////////////////////////////////////////////////////////////////////////////
  907. // ServerPropDialog message handlers
  908. /*!--------------------------------------------------------------------------
  909. ServerPropDialog::SetDefault
  910. -
  911. Author: KennT
  912. ---------------------------------------------------------------------------*/
  913. VOID ServerPropDialog::SetDefault(RADIUSSERVER *pServer)
  914. {
  915. Assert(pServer);
  916. m_stServer = pServer->szName;
  917. m_stSecret = pServer->wszSecret;
  918. m_ucSeed = pServer->ucSeed;
  919. m_cchSecret = pServer->cchSecret;
  920. m_uTimeout = pServer->Timeout.tv_sec;
  921. m_uAcctPort = pServer->AcctPort;
  922. m_uAuthPort = pServer->AuthPort;
  923. m_iInitScore = pServer->cScore;
  924. m_fAccountingOnOff = pServer->fAccountingOnOff;
  925. m_fUseDigitalSignatures = pServer->fUseDigitalSignatures;
  926. } // SetDefault()
  927. /*!--------------------------------------------------------------------------
  928. ServerPropDialog::GetDefault
  929. -
  930. Author: KennT
  931. ---------------------------------------------------------------------------*/
  932. VOID ServerPropDialog::GetDefault(RADIUSSERVER *pServer)
  933. {
  934. Assert(pServer);
  935. lstrcpy(pServer->szName, m_stServer);
  936. lstrcpy(pServer->wszSecret, m_stSecret);
  937. pServer->cchSecret = m_stSecret.GetLength();
  938. pServer->ucSeed = m_ucSeed;
  939. pServer->Timeout.tv_sec = m_uTimeout;
  940. pServer->AcctPort = m_uAcctPort;
  941. pServer->AuthPort = m_uAuthPort;
  942. pServer->cScore = m_iInitScore;
  943. pServer->fAccountingOnOff = m_fAccountingOnOff;
  944. pServer->fUseDigitalSignatures = m_fUseDigitalSignatures;
  945. } // GetDefault()
  946. /*!--------------------------------------------------------------------------
  947. ServerPropDialog::OnInitDialog
  948. -
  949. Author: KennT
  950. ---------------------------------------------------------------------------*/
  951. BOOL ServerPropDialog::OnInitDialog()
  952. {
  953. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  954. CString stTitle;
  955. CBaseDialog::OnInitDialog();
  956. // Set the title of this dialog
  957. stTitle.LoadString(m_fEdit ? IDS_RADIUS_CONFIG_EDIT : IDS_RADIUS_CONFIG_ADD);
  958. SetWindowText(stTitle);
  959. m_editServerName.SetFocus();
  960. // We don't allow editing of the secret from here
  961. m_editSecret.EnableWindow(FALSE);
  962. // Need to send 'cchSecret' backspace characters to the
  963. // edit control. Do this so that it looks as if there are
  964. // the right number of characters
  965. //
  966. // Windows NT Bug : 186649 - we should show the same number of
  967. // characters regardless.
  968. //
  969. // If this is a new server, then we keep the secret text as
  970. // blank, so the user knows that there is no secret. In the
  971. // edit case, we still show the text even if the secret is blank.
  972. // ----------------------------------------------------------------
  973. if (m_fEdit)
  974. m_editSecret.SetWindowText(c_szDisplayedSecret);
  975. m_spinScore.SetBuddy(GetDlgItem(IDC_RAC_EDIT_SCORE));
  976. m_spinScore.SetRange(0, MAXSCORE);
  977. m_spinTimeout.SetBuddy(GetDlgItem(IDC_RAC_EDIT_TIMEOUT));
  978. m_spinTimeout.SetRange(0, 300);
  979. if (GetDlgItem(IDC_RAC_BTN_DIGITALSIG))
  980. CheckDlgButton(IDC_RAC_BTN_DIGITALSIG, m_fUseDigitalSignatures);
  981. return FALSE; // return TRUE unless you set the focus to a control
  982. // EXCEPTION: OCX Property Pages should return FALSE
  983. }
  984. /*!--------------------------------------------------------------------------
  985. ServerPropDialog::OnOK
  986. -
  987. Author: KennT
  988. ---------------------------------------------------------------------------*/
  989. void ServerPropDialog::OnOK()
  990. {
  991. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  992. CString stTemp;
  993. if (!UpdateData(TRUE))
  994. return;
  995. // Do parameter checking
  996. m_editServerName.GetWindowText(stTemp);
  997. stTemp.TrimLeft();
  998. stTemp.TrimRight();
  999. if (stTemp.IsEmpty())
  1000. {
  1001. AfxMessageBox(IDS_ERR_INVALID_SERVER_NAME);
  1002. m_editServerName.SetFocus();
  1003. return;
  1004. }
  1005. // Need to grab the current value of the secret out of the edit
  1006. // control. If there are only backspace characters, then do
  1007. // not change the secret. Otherwise overwrite the current secret.
  1008. // m_editSecret.GetWindowText(stTemp);
  1009. // for (int i=0; i<stTemp.GetLength(); i++)
  1010. // {
  1011. // if (stTemp[i] != _T('\b'))
  1012. // {
  1013. // // Ok, the secret has changed, use the new password instead
  1014. // RtlEncodeW(&m_ucSeed, stTemp.GetBuffer(0));
  1015. // stTemp.ReleaseBuffer(-1);
  1016. //
  1017. // // Get a pointer to the old memory and write 0's into it
  1018. // ZeroMemory(m_stSecret.GetBuffer(0),
  1019. // m_stSecret.GetLength() * sizeof(TCHAR));
  1020. // m_stSecret.ReleaseBuffer(-1);
  1021. //
  1022. // m_stSecret = stTemp;
  1023. // break;
  1024. // }
  1025. // }
  1026. // m_fAuthentication = IsDlgButtonChecked(IDC_RAC_BTN_ENABLE);
  1027. if (GetDlgItem(IDC_RAC_BTN_DIGITALSIG))
  1028. m_fUseDigitalSignatures = IsDlgButtonChecked(IDC_RAC_BTN_DIGITALSIG);
  1029. if (m_iInitScore > MAXSCORE || m_iInitScore < MINSCORE)
  1030. {
  1031. CString stErrMsg;
  1032. stErrMsg.Format(IDS_ERR_INVALID_RADIUS_SCORE, m_iInitScore, MINSCORE, MAXSCORE);
  1033. AfxMessageBox((LPCTSTR)stErrMsg);
  1034. }
  1035. else
  1036. CBaseDialog::OnOK();
  1037. }
  1038. /*!--------------------------------------------------------------------------
  1039. ServerPropDialog::OnBtnPassword
  1040. -
  1041. Author: KennT
  1042. ---------------------------------------------------------------------------*/
  1043. void ServerPropDialog::OnBtnPassword()
  1044. {
  1045. RADIUSSecretDialog secretdlg;
  1046. // Ask for the new secret
  1047. if (secretdlg.DoModal() == IDOK)
  1048. {
  1049. // Zero out the old value
  1050. ZeroMemory(m_stSecret.GetBuffer(0),
  1051. m_stSecret.GetLength() * sizeof(TCHAR));
  1052. m_stSecret.ReleaseBuffer(-1);
  1053. // Get the value of the new secret and seed
  1054. secretdlg.GetSecret(&m_stSecret, &m_cchSecret, &m_ucSeed);
  1055. // Windows NT Bug : 186649
  1056. // Must show secrets as constant length.
  1057. m_editSecret.SetWindowText(c_szDisplayedSecret);
  1058. }
  1059. }
  1060. //static const DWORD rgHelpIDs[] =
  1061. // {
  1062. // IDC_EDIT_SERVERNAME, IDH_SERVER_NAME,
  1063. // IDC_EDIT_SECRET, IDH_SECRET,
  1064. // IDC_EDIT_TIMEOUT, IDH_TIMEOUT,
  1065. // IDC_SPIN_TIMEOUT, IDH_TIMEOUT,
  1066. // IDC_EDIT_SCORE, IDH_INITIAL_SCORE,
  1067. // IDC_SPIN_SCORE, IDH_INITIAL_SCORE,
  1068. // IDC_CHECK_ACCT, IDH_ENABLE_ACCOUNTING,
  1069. // IDC_STATIC_ACCTPORT, IDH_ACCOUNTING_PORT,
  1070. // IDC_EDIT_ACCTPORT, IDH_ACCOUNTING_PORT,
  1071. // IDC_CHECK_AUTH, IDH_ENABLE_AUTHENTICATION,
  1072. // IDC_STATIC_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1073. // IDC_EDIT_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1074. // IDC_CHECK_ACCT_ONOFF, IDH_ACCOUNTING_ONOFF,
  1075. // 0, 0
  1076. //};
  1077. /*---------------------------------------------------------------------------
  1078. RADIUSSecretDialog implementation
  1079. ---------------------------------------------------------------------------*/
  1080. RADIUSSecretDialog::RADIUSSecretDialog(CWnd* pParent /*=NULL*/)
  1081. : CBaseDialog(RADIUSSecretDialog::IDD, pParent)
  1082. {
  1083. //{{AFX_DATA_INIT(RADIUSSecretDialog)
  1084. //}}AFX_DATA_INIT
  1085. m_cchNewSecret = 0;
  1086. m_stNewSecret.Empty();
  1087. m_ucNewSeed = 0;
  1088. }
  1089. RADIUSSecretDialog::~RADIUSSecretDialog()
  1090. {
  1091. ZeroMemory(m_stNewSecret.GetBuffer(0),
  1092. m_stNewSecret.GetLength() * sizeof(TCHAR));
  1093. m_stNewSecret.ReleaseBuffer(-1);
  1094. }
  1095. void RADIUSSecretDialog::DoDataExchange(CDataExchange* pDX)
  1096. {
  1097. CDialog::DoDataExchange(pDX);
  1098. //{{AFX_DATA_MAP(RADIUSSecretDialog)
  1099. DDX_Control(pDX, IDC_SECRET_EDIT_NEW, m_editSecretNew);
  1100. DDX_Control(pDX, IDC_SECRET_EDIT_NEW_CONFIRM, m_editSecretNewConfirm);
  1101. //}}AFX_DATA_MAP
  1102. }
  1103. BEGIN_MESSAGE_MAP(RADIUSSecretDialog, CBaseDialog)
  1104. //{{AFX_MSG_MAP(RADIUSSecretDialog)
  1105. // ON_WM_CONTEXTMENU()
  1106. // ON_WM_HELPINFO()
  1107. //}}AFX_MSG_MAP
  1108. END_MESSAGE_MAP()
  1109. /////////////////////////////////////////////////////////////////////////////
  1110. // RADIUSSecretDialog message handlers
  1111. /*!--------------------------------------------------------------------------
  1112. RADIUSSecretDialog::GetSecret
  1113. -
  1114. Author: KennT
  1115. ---------------------------------------------------------------------------*/
  1116. VOID RADIUSSecretDialog::GetSecret(CString *pst, INT *pcch, UCHAR *pucSeed)
  1117. {
  1118. *pst = m_stNewSecret;
  1119. *pcch = m_cchNewSecret;
  1120. *pucSeed = m_ucNewSeed;
  1121. }
  1122. /*!--------------------------------------------------------------------------
  1123. RADIUSSecretDialog::OnInitDialog
  1124. -
  1125. Author: KennT
  1126. ---------------------------------------------------------------------------*/
  1127. BOOL RADIUSSecretDialog::OnInitDialog()
  1128. {
  1129. CBaseDialog::OnInitDialog();
  1130. m_editSecretNew.SetWindowText(c_szEmpty);
  1131. m_editSecretNewConfirm.SetWindowText(c_szEmpty);
  1132. return FALSE; // return TRUE unless you set the focus to a control
  1133. // EXCEPTION: OCX Property Pages should return FALSE
  1134. }
  1135. /*!--------------------------------------------------------------------------
  1136. RADIUSSecretDialog::OnOK
  1137. -
  1138. Author: KennT
  1139. ---------------------------------------------------------------------------*/
  1140. void RADIUSSecretDialog::OnOK()
  1141. {
  1142. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1143. CString stTemp;
  1144. CString stNew, stNewConfirm, stOld;
  1145. UCHAR ucSeed;
  1146. // Get the text for the new password, compare it to the
  1147. // new confirm passord, if they are the same use that as
  1148. // the password.
  1149. GetDlgItemText(IDC_SECRET_EDIT_NEW, stNew);
  1150. GetDlgItemText(IDC_SECRET_EDIT_NEW_CONFIRM, stNewConfirm);
  1151. if (stNew != stNewConfirm)
  1152. {
  1153. AfxMessageBox(IDS_ERR_SECRETS_MUST_MATCH);
  1154. return;
  1155. }
  1156. // Zero out the old value
  1157. ZeroMemory(m_stNewSecret.GetBuffer(0),
  1158. m_stNewSecret.GetLength() * sizeof(TCHAR));
  1159. m_stNewSecret.ReleaseBuffer(-1);
  1160. // Get the new values (and encrypt)
  1161. m_stNewSecret = stNew;
  1162. m_ucNewSeed = ENCRYPT_SEED;
  1163. RtlEncodeW(&m_ucNewSeed, m_stNewSecret.GetBuffer(0));
  1164. m_stNewSecret.ReleaseBuffer(-1);
  1165. m_cchNewSecret = m_stNewSecret.GetLength();
  1166. // Zero out the on-stack memory
  1167. ZeroMemory(stNew.GetBuffer(0),
  1168. stNew.GetLength() * sizeof(TCHAR));
  1169. stNew.ReleaseBuffer(-1);
  1170. ZeroMemory(stNewConfirm.GetBuffer(0),
  1171. stNewConfirm.GetLength() * sizeof(TCHAR));
  1172. stNewConfirm.ReleaseBuffer(-1);
  1173. // Need to grab the current value of the secret out of the edit
  1174. // control. If there are only backspace characters, then do
  1175. // not change the secret. Otherwise overwrite the current secret.
  1176. // m_editSecret.GetWindowText(stTemp);
  1177. // for (int i=0; i<stTemp.GetLength(); i++)
  1178. // {
  1179. // if (stTemp[i] != _T('\b'))
  1180. // {
  1181. // // Ok, the secret has changed, use the new password instead
  1182. // RtlEncodeW(&m_ucSeed, stTemp.GetBuffer(0));
  1183. // stTemp.ReleaseBuffer(-1);
  1184. //
  1185. // // Get a pointer to the old memory and write 0's into it
  1186. // ZeroMemory(m_stSecret.GetBuffer(0),
  1187. // m_stSecret.GetLength() * sizeof(TCHAR));
  1188. // m_stSecret.ReleaseBuffer(-1);
  1189. //
  1190. // m_stSecret = stTemp;
  1191. // break;
  1192. // }
  1193. // }
  1194. CBaseDialog::OnOK();
  1195. }
  1196. /*---------------------------------------------------------------------------
  1197. RouterAcctRadiusConfig implementation
  1198. ---------------------------------------------------------------------------*/
  1199. /*!--------------------------------------------------------------------------
  1200. RouterAcctRadiusConfig::Initialize
  1201. -
  1202. Author: KennT
  1203. ---------------------------------------------------------------------------*/
  1204. HRESULT RouterAcctRadiusConfig::Initialize(LPCOLESTR pszMachineName,
  1205. ULONG_PTR *puConnection)
  1206. {
  1207. HRESULT hr = hrOK;
  1208. // Parameter checking
  1209. // ----------------------------------------------------------------
  1210. if (puConnection == NULL)
  1211. return E_INVALIDARG;
  1212. COM_PROTECT_TRY
  1213. {
  1214. // for now, allocate a string and have it point at the string
  1215. // ------------------------------------------------------------
  1216. *puConnection = (ULONG_PTR) StrDupTFromOle(pszMachineName);
  1217. }
  1218. COM_PROTECT_CATCH;
  1219. return hr;
  1220. }
  1221. /*!--------------------------------------------------------------------------
  1222. RouterAcctRadiusConfig::Uninitialize
  1223. -
  1224. Author: KennT
  1225. ---------------------------------------------------------------------------*/
  1226. HRESULT RouterAcctRadiusConfig::Uninitialize(ULONG_PTR uConnection)
  1227. {
  1228. HRESULT hr = hrOK;
  1229. COM_PROTECT_TRY
  1230. {
  1231. delete (TCHAR *) uConnection;
  1232. }
  1233. COM_PROTECT_CATCH;
  1234. return hr;
  1235. }
  1236. /*!--------------------------------------------------------------------------
  1237. RouterAcctRadiusConfig::Configure
  1238. -
  1239. Author: KennT
  1240. ---------------------------------------------------------------------------*/
  1241. HRESULT RouterAcctRadiusConfig::Configure(
  1242. ULONG_PTR uConnection,
  1243. HWND hWnd,
  1244. DWORD dwFlags,
  1245. ULONG_PTR uReserved1,
  1246. ULONG_PTR uReserved2)
  1247. {
  1248. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1249. RadiusServerDialog acctDlg(FALSE, IDS_RADIUS_SERVER_ACCT_TITLE);
  1250. HRESULT hr = hrOK;
  1251. COM_PROTECT_TRY
  1252. {
  1253. acctDlg.SetServer((TCHAR *) uConnection);
  1254. acctDlg.DoModal();
  1255. }
  1256. COM_PROTECT_CATCH;
  1257. return hr;
  1258. }
  1259. /*!--------------------------------------------------------------------------
  1260. RouterAcctRadiusConfig::Activate
  1261. -
  1262. Author: KennT
  1263. ---------------------------------------------------------------------------*/
  1264. HRESULT RouterAcctRadiusConfig::Activate(
  1265. ULONG_PTR uConnection,
  1266. ULONG_PTR uReserved1,
  1267. ULONG_PTR uReserved2)
  1268. {
  1269. HRESULT hr = hrOK;
  1270. COM_PROTECT_TRY
  1271. {
  1272. }
  1273. COM_PROTECT_CATCH;
  1274. return hr;
  1275. }
  1276. /*!--------------------------------------------------------------------------
  1277. RouterAcctRadiusConfig::Deactivate
  1278. -
  1279. Author: KennT
  1280. ---------------------------------------------------------------------------*/
  1281. HRESULT RouterAcctRadiusConfig::Deactivate(
  1282. ULONG_PTR uConnection,
  1283. ULONG_PTR uReserved1,
  1284. ULONG_PTR uReserved2)
  1285. {
  1286. HRESULT hr = hrOK;
  1287. COM_PROTECT_TRY
  1288. {
  1289. }
  1290. COM_PROTECT_CATCH;
  1291. return hr;
  1292. }
  1293. /*---------------------------------------------------------------------------
  1294. ServerPropAcctDialog implementation
  1295. ---------------------------------------------------------------------------*/
  1296. ServerPropAcctDialog::ServerPropAcctDialog(BOOL fEdit, CWnd* pParent /*=NULL*/)
  1297. : ServerPropDialog(fEdit, ServerPropAcctDialog::IDD, pParent)
  1298. {
  1299. //{{AFX_DATA_INIT(ServerPropAcctDialog)
  1300. //}}AFX_DATA_INIT
  1301. }
  1302. ServerPropAcctDialog::~ServerPropAcctDialog()
  1303. {
  1304. }
  1305. void ServerPropAcctDialog::DoDataExchange(CDataExchange* pDX)
  1306. {
  1307. ServerPropDialog::DoDataExchange(pDX);
  1308. //{{AFX_DATA_MAP(ServerPropAcctDialog)
  1309. DDX_Text(pDX, IDC_RAC_EDIT_PORT, m_uAcctPort);
  1310. //}}AFX_DATA_MAP
  1311. }
  1312. BEGIN_MESSAGE_MAP(ServerPropAcctDialog, CBaseDialog)
  1313. //{{AFX_MSG_MAP(ServerPropAcctDialog)
  1314. ON_BN_CLICKED(IDC_RAC_BTN_CHANGE, OnBtnPassword)
  1315. // ON_WM_CONTEXTMENU()
  1316. // ON_WM_HELPINFO()
  1317. //}}AFX_MSG_MAP
  1318. END_MESSAGE_MAP()
  1319. /////////////////////////////////////////////////////////////////////////////
  1320. // ServerPropAcctDialog message handlers
  1321. /*!--------------------------------------------------------------------------
  1322. ServerPropAcctDialog::OnInitDialog
  1323. -
  1324. Author: KennT
  1325. ---------------------------------------------------------------------------*/
  1326. BOOL ServerPropAcctDialog::OnInitDialog()
  1327. {
  1328. ServerPropDialog::OnInitDialog();
  1329. CheckDlgButton(IDC_RAC_BTN_ONOFF, m_fAccountingOnOff);
  1330. return FALSE; // return TRUE unless you set the focus to a control
  1331. // EXCEPTION: OCX Property Pages should return FALSE
  1332. }
  1333. /*!--------------------------------------------------------------------------
  1334. ServerPropAcctDialog::OnOK
  1335. -
  1336. Author: KennT
  1337. ---------------------------------------------------------------------------*/
  1338. void ServerPropAcctDialog::OnOK()
  1339. {
  1340. CString stTemp;
  1341. // Need to grab the current value of the secret out of the edit
  1342. // control. If there are only backspace characters, then do
  1343. // not change the secret. Otherwise overwrite the current secret.
  1344. // m_editSecret.GetWindowText(stTemp);
  1345. // for (int i=0; i<stTemp.GetLength(); i++)
  1346. // {
  1347. // if (stTemp[i] != _T('\b'))
  1348. // {
  1349. // // Ok, the secret has changed, use the new password instead
  1350. // RtlEncodeW(&m_ucSeed, stTemp.GetBuffer(0));
  1351. // stTemp.ReleaseBuffer(-1);
  1352. //
  1353. // // Get a pointer to the old memory and write 0's into it
  1354. // ZeroMemory(m_stSecret.GetBuffer(0),
  1355. // m_stSecret.GetLength() * sizeof(TCHAR));
  1356. // m_stSecret.ReleaseBuffer(-1);
  1357. //
  1358. // m_stSecret = stTemp;
  1359. // break;
  1360. // }
  1361. // }
  1362. m_fAccountingOnOff = IsDlgButtonChecked(IDC_RAC_BTN_ONOFF);
  1363. ServerPropDialog::OnOK();
  1364. }
  1365. //static const DWORD rgHelpIDs[] =
  1366. // {
  1367. // IDC_EDIT_SERVERNAME, IDH_SERVER_NAME,
  1368. // IDC_EDIT_SECRET, IDH_SECRET,
  1369. // IDC_EDIT_TIMEOUT, IDH_TIMEOUT,
  1370. // IDC_SPIN_TIMEOUT, IDH_TIMEOUT,
  1371. // IDC_EDIT_SCORE, IDH_INITIAL_SCORE,
  1372. // IDC_SPIN_SCORE, IDH_INITIAL_SCORE,
  1373. // IDC_CHECK_ACCT, IDH_ENABLE_ACCOUNTING,
  1374. // IDC_STATIC_ACCTPORT, IDH_ACCOUNTING_PORT,
  1375. // IDC_EDIT_ACCTPORT, IDH_ACCOUNTING_PORT,
  1376. // IDC_CHECK_AUTH, IDH_ENABLE_AUTHENTICATION,
  1377. // IDC_STATIC_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1378. // IDC_EDIT_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1379. // IDC_CHECK_ACCT_ONOFF, IDH_ACCOUNTING_ONOFF,
  1380. // 0, 0
  1381. //};