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.

1692 lines
54 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. SetFocus();
  416. }
  417. /*!--------------------------------------------------------------------------
  418. RadiusServerDialog::OnBtnDelete
  419. -
  420. Author: KennT
  421. ---------------------------------------------------------------------------*/
  422. void RadiusServerDialog::OnBtnDelete()
  423. {
  424. // Get the selection and delete it
  425. int iPos;
  426. ULONG_PTR dwUnique;
  427. RADIUSSERVER * pServer = NULL;
  428. BOOL fRemoveLSAEntry = FALSE;
  429. iPos = m_ListServers.GetNextItem(-1, LVNI_SELECTED);
  430. if (iPos == -1)
  431. return;
  432. dwUnique = m_ListServers.GetItemData(iPos);
  433. // Does this server exist in the other list
  434. Verify( m_ServerList.FindServer((DWORD) dwUnique, &pServer) );
  435. Assert(pServer);
  436. // If we find this server in the other list, we can't remove its
  437. // LSA entry
  438. fRemoveLSAEntry = !m_OtherServerList.FindServer(pServer->szName, NULL);
  439. m_ServerList.DeleteServer(dwUnique, fRemoveLSAEntry);
  440. m_ListServers.DeleteItem(iPos);
  441. // See if we can move the selection to the next item in the list
  442. // if that fails, try to set it to the previous item
  443. if (!m_ListServers.SetItemState(iPos, LVIS_SELECTED, LVIS_SELECTED))
  444. m_ListServers.SetItemState(iPos - 1, LVIS_SELECTED, LVIS_SELECTED);
  445. SetFocus();
  446. }
  447. /*!--------------------------------------------------------------------------
  448. RadiusServerDialog::OnBtnEdit
  449. -
  450. Author: KennT
  451. ---------------------------------------------------------------------------*/
  452. void RadiusServerDialog::OnBtnEdit()
  453. {
  454. ServerPropDialog * pServerDlg;
  455. RADIUSSERVER server;
  456. RADIUSSERVER * pServer;
  457. int iOldPos, iPos;
  458. LONG_PTR dwUnique;
  459. ServerPropDialog authDlg(TRUE);
  460. ServerPropAcctDialog acctDlg(TRUE);
  461. if (m_fAuthDialog)
  462. pServerDlg = &authDlg;
  463. else
  464. pServerDlg = &acctDlg;
  465. iOldPos = m_ListServers.GetNextItem(-1, LVNI_SELECTED);
  466. if (iOldPos == -1)
  467. return;
  468. dwUnique = m_ListServers.GetItemData(iOldPos);
  469. // Need to look for server data that matches this one
  470. // Now iterate through the server list and add the servers to the
  471. // list box
  472. for (pServer = m_ServerList.GetNextServer(TRUE); pServer;
  473. pServer = m_ServerList.GetNextServer(FALSE) )
  474. {
  475. if (pServer->dwUnique == (DWORD) dwUnique)
  476. break;
  477. }
  478. if (!pServer)
  479. {
  480. Panic0("We can't find the server in the list (but we should)!");
  481. return;
  482. }
  483. pServerDlg->SetDefault(pServer);
  484. if (pServerDlg->DoModal() == IDOK)
  485. {
  486. ZeroMemory(&server, sizeof(server));
  487. pServerDlg->GetDefault(&server);
  488. // Add to the server list, need to add this at the proper place
  489. m_ServerList.AddServer(&server, dwUnique);
  490. // Delete the old server data
  491. m_ServerList.DeleteServer(dwUnique, FALSE);
  492. m_ListServers.DeleteItem(iOldPos);
  493. pServer = NULL;
  494. // Add to the list control
  495. TCHAR szBuf[SCORE_MAX_DIGITS];
  496. LV_ITEM lvItem;
  497. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  498. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  499. lvItem.state = 0;
  500. lvItem.iItem = iOldPos;
  501. lvItem.iSubItem = 0;
  502. lvItem.pszText = server.szName;
  503. lvItem.lParam = server.dwUnique; //same functionality as SetItemData()
  504. iPos = m_ListServers.InsertItem(&lvItem);
  505. _itot(server.cScore, szBuf, 10);
  506. m_ListServers.SetItemText(iPos, 1, szBuf);
  507. if (iPos != -1)
  508. {
  509. // Reset the current selection
  510. m_ListServers.SetItemState(iPos, LVIS_SELECTED, LVIS_SELECTED);
  511. m_ListServers.SortItems(RadiusScoreCompareProc, (LPARAM)&m_ServerList);
  512. }
  513. ZeroMemory(&server, sizeof(server));
  514. }
  515. SetFocus();
  516. }
  517. /*!--------------------------------------------------------------------------
  518. RadiusServerDialog::OnListDblClk
  519. -
  520. Author: KennT
  521. ---------------------------------------------------------------------------*/
  522. void RadiusServerDialog::OnListDblClk(NMHDR *pNMHdr, LRESULT *pResult)
  523. {
  524. OnBtnEdit();
  525. }
  526. /*!--------------------------------------------------------------------------
  527. RadiusServerDialog::OnNotifyListItemChanged
  528. -
  529. Author: KennT
  530. ---------------------------------------------------------------------------*/
  531. void RadiusServerDialog::OnNotifyListItemChanged(NMHDR *pNMHdr, LRESULT *pResult)
  532. {
  533. NMLISTVIEW * pnmlv = reinterpret_cast<NMLISTVIEW *>(pNMHdr);
  534. int iPos;
  535. if ((pnmlv->uNewState & LVIS_SELECTED) != (pnmlv->uOldState & LVIS_SELECTED))
  536. {
  537. iPos = m_ListServers.GetNextItem(-1, LVNI_SELECTED);
  538. GetDlgItem(IDC_RADAUTH_BTN_DELETE)->EnableWindow(iPos != -1);
  539. GetDlgItem(IDC_RADAUTH_BTN_EDIT)->EnableWindow(iPos != -1);
  540. }
  541. *pResult = 0;
  542. }
  543. //**
  544. //
  545. // Call: LoadRadiusServers
  546. //
  547. // Returns: NO_ERROR - Success
  548. // Non-zero returns - Failure
  549. //
  550. // Description:
  551. //
  552. HRESULT
  553. LoadRadiusServers(
  554. IN LPCTSTR pszServerName,
  555. IN HKEY hkeyMachine,
  556. IN BOOL fAuthentication,
  557. IN CRadiusServers * pRadiusServers,
  558. IN DWORD dwFlags
  559. )
  560. {
  561. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  562. HRESULT hr = hrOK;
  563. DWORD dwErrorCode;
  564. BOOL fValidServer = FALSE;
  565. RegKey regkeyServers;
  566. RegKeyIterator regkeyIter;
  567. HRESULT hrIter;
  568. CString stKey;
  569. RegKey regkeyServer;
  570. DWORD dwData;
  571. WSADATA wsadata;
  572. BOOL fWSInitialized = FALSE;
  573. DWORD wsaerr = 0;
  574. COM_PROTECT_TRY
  575. {
  576. // DWORD dwKeyIndex, cbKeyServer, cbValue;
  577. // TCHAR szKeyServer[MAX_PATH+1];
  578. CHAR szName[MAX_PATH+1];
  579. RADIUSSERVER RadiusServer;
  580. CWaitCursor waitCursor;
  581. ZeroMemory(&RadiusServer, sizeof(RadiusServer));
  582. Assert(pRadiusServers != NULL);
  583. Assert(hkeyMachine);
  584. wsaerr = WSAStartup(0x0101, &wsadata);
  585. if (wsaerr)
  586. {
  587. // Need to setup a winsock error
  588. hr = E_FAIL;
  589. goto Error;
  590. }
  591. // Winsock successfully initialized
  592. fWSInitialized = TRUE;
  593. CWRg( regkeyServers.Open(hkeyMachine,
  594. fAuthentication ?
  595. c_szRadiusAuthServersKey :
  596. c_szRadiusAcctServersKey,
  597. KEY_READ) );
  598. CORg( regkeyIter.Init(&regkeyServers) );
  599. for (hrIter=regkeyIter.Next(&stKey); hrIter == hrOK;
  600. hrIter=regkeyIter.Next(&stKey), regkeyServer.Close())
  601. {
  602. CWRg( regkeyServer.Open(regkeyServers, stKey, KEY_READ) );
  603. ZeroMemory( &RadiusServer, sizeof( RadiusServer ) );
  604. // Copy the name over
  605. StrnCpy(RadiusServer.szName, stKey, MAX_PATH);
  606. // Since we're reading this in from the registry, it's
  607. // been persisted
  608. RadiusServer.fPersisted = TRUE;
  609. // Get the timeout value
  610. dwErrorCode = regkeyServer.QueryValue(c_szTimeout, dwData);
  611. if ( dwErrorCode != NO_ERROR )
  612. RadiusServer.Timeout.tv_sec = DEFTIMEOUT;
  613. else
  614. RadiusServer.Timeout.tv_sec = dwData;
  615. //
  616. // Secret Value is required
  617. //
  618. CWRg( RetrievePrivateData( pszServerName,
  619. RadiusServer.szName,
  620. RadiusServer.wszSecret,
  621. DimensionOf(RadiusServer.wszSecret)) );
  622. RadiusServer.cchSecret = lstrlen(RadiusServer.wszSecret);
  623. // Encode the password, do not store it as plain text
  624. // Decode as needed.
  625. RadiusServer.ucSeed = ENCRYPT_SEED;
  626. RtlEncodeW(&RadiusServer.ucSeed, RadiusServer.wszSecret);
  627. //
  628. // read in port numbers
  629. //
  630. // Get the AuthPort
  631. if (fAuthentication)
  632. {
  633. dwErrorCode = regkeyServer.QueryValue( c_szAuthPort, dwData );
  634. if ( dwErrorCode != NO_ERROR )
  635. RadiusServer.AuthPort = DEFAUTHPORT;
  636. else
  637. RadiusServer.AuthPort = dwData;
  638. // Windows NT Bug : 311398
  639. // Get the Digital Signature data
  640. if (dwErrorCode == NO_ERROR)
  641. dwErrorCode = regkeyServer.QueryValue( c_szRegValSendSignature, dwData );
  642. if (dwErrorCode == NO_ERROR)
  643. RadiusServer.fUseDigitalSignatures = dwData;
  644. else
  645. RadiusServer.fUseDigitalSignatures = FALSE;
  646. }
  647. else
  648. {
  649. // Get the AcctPort
  650. dwErrorCode = regkeyServer.QueryValue(c_szAcctPort, dwData );
  651. if ( dwErrorCode != NO_ERROR )
  652. RadiusServer.AcctPort = DEFACCTPORT;
  653. else
  654. RadiusServer.AcctPort = dwData;
  655. // Get the EnableAccounting On/Off flag
  656. dwErrorCode = regkeyServer.QueryValue( c_szEnableAccountingOnOff,
  657. dwData );
  658. if ( dwErrorCode != NO_ERROR )
  659. RadiusServer.fAccountingOnOff = TRUE;
  660. else
  661. RadiusServer.fAccountingOnOff = dwData;
  662. }
  663. // Get the score
  664. dwErrorCode = regkeyServer.QueryValue( c_szScore, dwData );
  665. if ( dwErrorCode != NO_ERROR )
  666. RadiusServer.cScore = MAXSCORE;
  667. else
  668. RadiusServer.cScore = dwData;
  669. RadiusServer.cRetries = 1;
  670. //
  671. // Convert name to ip address.
  672. //
  673. if ( INET_ADDR( RadiusServer.szName ) == INADDR_NONE )
  674. {
  675. // resolve name
  676. struct hostent * phe = NULL;
  677. if (dwFlags & RADIUS_FLAG_NOIP)
  678. phe = NULL;
  679. else
  680. {
  681. StrnCpyAFromT(szName, RadiusServer.szName,
  682. DimensionOf(szName));
  683. phe = gethostbyname( szName );
  684. }
  685. if ( phe != NULL )
  686. {
  687. // host could have multiple addresses
  688. // BUG#185732 (nsun 11/04/98) We only load the first Ip Address
  689. if( phe->h_addr_list[0] != NULL )
  690. {
  691. RadiusServer.IPAddress.sin_family = AF_INET;
  692. RadiusServer.IPAddress.sin_port =
  693. htons((SHORT) RadiusServer.AuthPort);
  694. RadiusServer.IPAddress.sin_addr.S_un.S_addr =
  695. *((PDWORD) phe->h_addr_list[0]);
  696. }
  697. }
  698. else
  699. {
  700. if ((dwFlags & RADIUS_FLAG_NOUI) == 0)
  701. {
  702. CString stText;
  703. stText.Format(IDS_ERR_RADIUS_INVALID_NAME, RadiusServer.szName);
  704. AfxMessageBox((LPCTSTR)stText, MB_OK | MB_ICONEXCLAMATION);
  705. waitCursor.Restore();
  706. }
  707. }
  708. }
  709. else
  710. {
  711. //
  712. // use specified ip address
  713. //
  714. RadiusServer.IPAddress.sin_family = AF_INET;
  715. RadiusServer.IPAddress.sin_port =
  716. htons((SHORT) RadiusServer.AuthPort);
  717. RadiusServer.IPAddress.sin_addr.S_un.S_addr = INET_ADDR(RadiusServer.szName);
  718. }
  719. if ( pRadiusServers != NULL )
  720. {
  721. fValidServer = (pRadiusServers->AddServer(&RadiusServer, (DWORD) -1)
  722. == NO_ERROR
  723. ? TRUE
  724. : FALSE);
  725. }
  726. }
  727. COM_PROTECT_ERROR_LABEL;
  728. }
  729. COM_PROTECT_CATCH;
  730. if (fWSInitialized)
  731. WSACleanup();
  732. //
  733. // if no servers entries are found in registry return error code.
  734. //
  735. if ( ( fValidServer == FALSE ) && FHrSucceeded(hr) )
  736. {
  737. hr = HRESULT_FROM_WIN32(ERROR_NO_RADIUS_SERVERS);
  738. }
  739. return( hr );
  740. }
  741. //**
  742. //
  743. // Call: SaveRadiusServers
  744. //
  745. // Returns: NO_ERROR - Success
  746. // Non-zero returns - Failure
  747. //
  748. // Description:
  749. //
  750. HRESULT
  751. SaveRadiusServers(LPCTSTR pszServerName,
  752. HKEY hkeyMachine,
  753. IN BOOL fAuthentication,
  754. IN RADIUSSERVER * pServerRoot
  755. )
  756. {
  757. HRESULT hr = hrOK;
  758. RADIUSSERVER *pServer;
  759. DWORD dwErrorCode;
  760. RegKey regkeyMachine;
  761. RegKey regkeyServers, regkeyServer;
  762. DWORD dwData;
  763. pServer = pServerRoot;
  764. COM_PROTECT_TRY
  765. {
  766. regkeyMachine.Attach(hkeyMachine);
  767. regkeyMachine.RecurseDeleteKey(fAuthentication ?
  768. c_szRadiusAuthServersKey :
  769. c_szRadiusAcctServersKey);
  770. CWRg( regkeyServers.Create(hkeyMachine,
  771. fAuthentication ?
  772. c_szRadiusAuthServersKey :
  773. c_szRadiusAcctServersKey) );
  774. while( pServer != NULL )
  775. {
  776. CWRg( regkeyServer.Create(regkeyServers, pServer->szName) );
  777. // Need to unencode the private data
  778. RtlDecodeW(pServer->ucSeed, pServer->wszSecret);
  779. dwErrorCode = StorePrivateData(pszServerName,
  780. pServer->szName,
  781. pServer->wszSecret);
  782. RtlEncodeW(&pServer->ucSeed, pServer->wszSecret);
  783. CWRg( dwErrorCode );
  784. // Ok, we've saved the information
  785. pServer->fPersisted = TRUE;
  786. dwData = pServer->Timeout.tv_sec;
  787. CWRg( regkeyServer.SetValue(c_szTimeout, dwData) );
  788. if (fAuthentication)
  789. {
  790. dwData = pServer->AuthPort;
  791. CWRg( regkeyServer.SetValue(c_szAuthPort, dwData) );
  792. // Windows NT Bug: 311398
  793. // Save the digital signature data
  794. dwData = pServer->fUseDigitalSignatures;
  795. CWRg( regkeyServer.SetValue(c_szRegValSendSignature, dwData) );
  796. }
  797. else
  798. {
  799. dwData = pServer->AcctPort;
  800. CWRg( regkeyServer.SetValue(c_szAcctPort, dwData) );
  801. dwData = pServer->fAccountingOnOff;
  802. CWRg( regkeyServer.SetValue(c_szEnableAccountingOnOff, dwData) );
  803. }
  804. dwData = pServer->cScore;
  805. CWRg( regkeyServer.SetValue(c_szScore, dwData) );
  806. regkeyServer.Close();
  807. pServer = pServer->pNext;
  808. }
  809. COM_PROTECT_ERROR_LABEL;
  810. }
  811. COM_PROTECT_CATCH;
  812. regkeyMachine.Detach();
  813. return hr;
  814. }
  815. /*!--------------------------------------------------------------------------
  816. DeleteRadiusServers
  817. DANGER! Do NOT call this unless you absolutely know this is
  818. what you need. The problem is that there is no way to
  819. distinguish between accouting/authentication entries, thus an
  820. external reference check must be made.
  821. Author: KennT
  822. ---------------------------------------------------------------------------*/
  823. HRESULT
  824. DeleteRadiusServers(LPCTSTR pszServerName,
  825. RADIUSSERVER * pServerRoot
  826. )
  827. {
  828. HRESULT hr = hrOK;
  829. RADIUSSERVER *pServer;
  830. pServer = pServerRoot;
  831. COM_PROTECT_TRY
  832. {
  833. while( pServer != NULL )
  834. {
  835. if (pServer->fPersisted)
  836. DeletePrivateData(pszServerName,
  837. pServer->szName);
  838. pServer = pServer->pNext;
  839. }
  840. }
  841. COM_PROTECT_CATCH;
  842. return hr;
  843. }
  844. /*---------------------------------------------------------------------------
  845. ServerPropDialog implementation
  846. ---------------------------------------------------------------------------*/
  847. ServerPropDialog::ServerPropDialog(BOOL fEdit, CWnd* pParent /*=NULL*/)
  848. : CBaseDialog(ServerPropDialog::IDD, pParent),
  849. m_fEdit(fEdit)
  850. {
  851. //{{AFX_DATA_INIT(ServerPropDialog)
  852. m_uAuthPort = DEFAUTHPORT;
  853. m_uAcctPort = DEFACCTPORT;
  854. m_stSecret.Empty();
  855. m_cchSecret = 0;
  856. m_ucSeed = ENCRYPT_SEED;
  857. m_stServer.Empty();
  858. m_uTimeout = DEFTIMEOUT;
  859. m_iInitScore = MAXSCORE;
  860. m_fAccountingOnOff = FALSE;
  861. m_fUseDigitalSignatures = FALSE;
  862. //}}AFX_DATA_INIT
  863. }
  864. ServerPropDialog::ServerPropDialog(BOOL fEdit, UINT idd, CWnd* pParent /*=NULL*/)
  865. : CBaseDialog(idd, pParent),
  866. m_fEdit(fEdit)
  867. {
  868. //{{AFX_DATA_INIT(ServerPropDialog)
  869. m_uAuthPort = DEFAUTHPORT;
  870. m_uAcctPort = DEFACCTPORT;
  871. m_stSecret.Empty();
  872. m_cchSecret = 0;
  873. m_ucSeed = ENCRYPT_SEED;
  874. m_stServer.Empty();
  875. m_uTimeout = DEFTIMEOUT;
  876. m_iInitScore = MAXSCORE;
  877. m_fAccountingOnOff = FALSE;
  878. m_fUseDigitalSignatures = FALSE;
  879. //}}AFX_DATA_INIT
  880. }
  881. ServerPropDialog::~ServerPropDialog()
  882. {
  883. ::SecureZeroMemory(m_stSecret.GetBuffer(0),
  884. m_stSecret.GetLength() * sizeof(TCHAR));
  885. m_stSecret.ReleaseBuffer(-1);
  886. }
  887. void ServerPropDialog::DoDataExchange(CDataExchange* pDX)
  888. {
  889. CDialog::DoDataExchange(pDX);
  890. //{{AFX_DATA_MAP(ServerPropDialog)
  891. DDX_Control(pDX, IDC_RAC_EDIT_SERVER, m_editServerName);
  892. DDX_Control(pDX, IDC_RAC_EDIT_SECRET, m_editSecret);
  893. DDX_Control(pDX, IDC_RAC_EDIT_PORT, m_editPort);
  894. DDX_Control(pDX, IDC_RAC_SPIN_SCORE, m_spinScore);
  895. DDX_Control(pDX, IDC_RAC_SPIN_TIMEOUT, m_spinTimeout);
  896. DDX_Text(pDX, IDC_RAC_EDIT_PORT, m_uAuthPort);
  897. DDX_Text(pDX, IDC_RAC_EDIT_SERVER, m_stServer);
  898. DDX_Text(pDX, IDC_RAC_EDIT_TIMEOUT, m_uTimeout);
  899. DDX_Text(pDX, IDC_RAC_EDIT_SCORE, m_iInitScore);
  900. //}}AFX_DATA_MAP
  901. }
  902. BEGIN_MESSAGE_MAP(ServerPropDialog, CBaseDialog)
  903. //{{AFX_MSG_MAP(ServerPropDialog)
  904. ON_BN_CLICKED(IDC_RAC_BTN_CHANGE, OnBtnPassword)
  905. // ON_WM_CONTEXTMENU()
  906. // ON_WM_HELPINFO()
  907. //}}AFX_MSG_MAP
  908. END_MESSAGE_MAP()
  909. /////////////////////////////////////////////////////////////////////////////
  910. // ServerPropDialog message handlers
  911. /*!--------------------------------------------------------------------------
  912. ServerPropDialog::SetDefault
  913. -
  914. Author: KennT
  915. ---------------------------------------------------------------------------*/
  916. VOID ServerPropDialog::SetDefault(RADIUSSERVER *pServer)
  917. {
  918. Assert(pServer);
  919. m_stServer = pServer->szName;
  920. m_stSecret = pServer->wszSecret;
  921. m_ucSeed = pServer->ucSeed;
  922. m_cchSecret = pServer->cchSecret;
  923. m_uTimeout = pServer->Timeout.tv_sec;
  924. m_uAcctPort = pServer->AcctPort;
  925. m_uAuthPort = pServer->AuthPort;
  926. m_iInitScore = pServer->cScore;
  927. m_fAccountingOnOff = pServer->fAccountingOnOff;
  928. m_fUseDigitalSignatures = pServer->fUseDigitalSignatures;
  929. } // SetDefault()
  930. /*!--------------------------------------------------------------------------
  931. ServerPropDialog::GetDefault
  932. -
  933. Author: KennT
  934. ---------------------------------------------------------------------------*/
  935. VOID ServerPropDialog::GetDefault(RADIUSSERVER *pServer)
  936. {
  937. Assert(pServer);
  938. lstrcpy(pServer->szName, m_stServer);
  939. lstrcpy(pServer->wszSecret, m_stSecret);
  940. pServer->cchSecret = m_stSecret.GetLength();
  941. pServer->ucSeed = m_ucSeed;
  942. pServer->Timeout.tv_sec = m_uTimeout;
  943. pServer->AcctPort = m_uAcctPort;
  944. pServer->AuthPort = m_uAuthPort;
  945. pServer->cScore = m_iInitScore;
  946. pServer->fAccountingOnOff = m_fAccountingOnOff;
  947. pServer->fUseDigitalSignatures = m_fUseDigitalSignatures;
  948. } // GetDefault()
  949. /*!--------------------------------------------------------------------------
  950. ServerPropDialog::OnInitDialog
  951. -
  952. Author: KennT
  953. ---------------------------------------------------------------------------*/
  954. BOOL ServerPropDialog::OnInitDialog()
  955. {
  956. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  957. CString stTitle;
  958. CBaseDialog::OnInitDialog();
  959. // Set the title of this dialog
  960. stTitle.LoadString(m_fEdit ? IDS_RADIUS_CONFIG_EDIT : IDS_RADIUS_CONFIG_ADD);
  961. SetWindowText(stTitle);
  962. m_editServerName.SetFocus();
  963. // We don't allow editing of the secret from here
  964. m_editSecret.EnableWindow(FALSE);
  965. // Need to send 'cchSecret' backspace characters to the
  966. // edit control. Do this so that it looks as if there are
  967. // the right number of characters
  968. //
  969. // Windows NT Bug : 186649 - we should show the same number of
  970. // characters regardless.
  971. //
  972. // If this is a new server, then we keep the secret text as
  973. // blank, so the user knows that there is no secret. In the
  974. // edit case, we still show the text even if the secret is blank.
  975. // ----------------------------------------------------------------
  976. if (m_fEdit)
  977. m_editSecret.SetWindowText(c_szDisplayedSecret);
  978. m_spinScore.SetBuddy(GetDlgItem(IDC_RAC_EDIT_SCORE));
  979. m_spinScore.SetRange(0, MAXSCORE);
  980. m_spinTimeout.SetBuddy(GetDlgItem(IDC_RAC_EDIT_TIMEOUT));
  981. m_spinTimeout.SetRange(0, 300);
  982. if (GetDlgItem(IDC_RAC_BTN_DIGITALSIG))
  983. CheckDlgButton(IDC_RAC_BTN_DIGITALSIG, m_fUseDigitalSignatures);
  984. return FALSE; // return TRUE unless you set the focus to a control
  985. // EXCEPTION: OCX Property Pages should return FALSE
  986. }
  987. /*!--------------------------------------------------------------------------
  988. ServerPropDialog::OnOK
  989. -
  990. Author: KennT
  991. ---------------------------------------------------------------------------*/
  992. void ServerPropDialog::OnOK()
  993. {
  994. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  995. CString stTemp;
  996. if (!UpdateData(TRUE))
  997. return;
  998. // Do parameter checking
  999. m_editServerName.GetWindowText(stTemp);
  1000. stTemp.TrimLeft();
  1001. stTemp.TrimRight();
  1002. if (stTemp.IsEmpty())
  1003. {
  1004. AfxMessageBox(IDS_ERR_INVALID_SERVER_NAME);
  1005. m_editServerName.SetFocus();
  1006. return;
  1007. }
  1008. // Need to grab the current value of the secret out of the edit
  1009. // control. If there are only backspace characters, then do
  1010. // not change the secret. Otherwise overwrite the current secret.
  1011. // m_editSecret.GetWindowText(stTemp);
  1012. // for (int i=0; i<stTemp.GetLength(); i++)
  1013. // {
  1014. // if (stTemp[i] != _T('\b'))
  1015. // {
  1016. // // Ok, the secret has changed, use the new password instead
  1017. // RtlEncodeW(&m_ucSeed, stTemp.GetBuffer(0));
  1018. // stTemp.ReleaseBuffer(-1);
  1019. //
  1020. // // Get a pointer to the old memory and write 0's into it
  1021. // ::SecureZeroMemory(m_stSecret.GetBuffer(0),
  1022. // m_stSecret.GetLength() * sizeof(TCHAR));
  1023. // m_stSecret.ReleaseBuffer(-1);
  1024. //
  1025. // m_stSecret = stTemp;
  1026. // break;
  1027. // }
  1028. // }
  1029. // m_fAuthentication = IsDlgButtonChecked(IDC_RAC_BTN_ENABLE);
  1030. if (GetDlgItem(IDC_RAC_BTN_DIGITALSIG))
  1031. m_fUseDigitalSignatures = IsDlgButtonChecked(IDC_RAC_BTN_DIGITALSIG);
  1032. if (m_iInitScore > MAXSCORE || m_iInitScore < MINSCORE)
  1033. {
  1034. CString stErrMsg;
  1035. stErrMsg.Format(IDS_ERR_INVALID_RADIUS_SCORE, m_iInitScore, MINSCORE, MAXSCORE);
  1036. AfxMessageBox((LPCTSTR)stErrMsg);
  1037. }
  1038. else
  1039. CBaseDialog::OnOK();
  1040. }
  1041. /*!--------------------------------------------------------------------------
  1042. ServerPropDialog::OnBtnPassword
  1043. -
  1044. Author: KennT
  1045. ---------------------------------------------------------------------------*/
  1046. void ServerPropDialog::OnBtnPassword()
  1047. {
  1048. RADIUSSecretDialog secretdlg;
  1049. // Ask for the new secret
  1050. if (secretdlg.DoModal() == IDOK)
  1051. {
  1052. // Zero out the old value
  1053. ::SecureZeroMemory(m_stSecret.GetBuffer(0),
  1054. m_stSecret.GetLength() * sizeof(TCHAR));
  1055. m_stSecret.ReleaseBuffer(-1);
  1056. // Get the value of the new secret and seed
  1057. secretdlg.GetSecret(&m_stSecret, &m_cchSecret, &m_ucSeed);
  1058. // Windows NT Bug : 186649
  1059. // Must show secrets as constant length.
  1060. m_editSecret.SetWindowText(c_szDisplayedSecret);
  1061. }
  1062. }
  1063. //static const DWORD rgHelpIDs[] =
  1064. // {
  1065. // IDC_EDIT_SERVERNAME, IDH_SERVER_NAME,
  1066. // IDC_EDIT_SECRET, IDH_SECRET,
  1067. // IDC_EDIT_TIMEOUT, IDH_TIMEOUT,
  1068. // IDC_SPIN_TIMEOUT, IDH_TIMEOUT,
  1069. // IDC_EDIT_SCORE, IDH_INITIAL_SCORE,
  1070. // IDC_SPIN_SCORE, IDH_INITIAL_SCORE,
  1071. // IDC_CHECK_ACCT, IDH_ENABLE_ACCOUNTING,
  1072. // IDC_STATIC_ACCTPORT, IDH_ACCOUNTING_PORT,
  1073. // IDC_EDIT_ACCTPORT, IDH_ACCOUNTING_PORT,
  1074. // IDC_CHECK_AUTH, IDH_ENABLE_AUTHENTICATION,
  1075. // IDC_STATIC_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1076. // IDC_EDIT_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1077. // IDC_CHECK_ACCT_ONOFF, IDH_ACCOUNTING_ONOFF,
  1078. // 0, 0
  1079. //};
  1080. /*---------------------------------------------------------------------------
  1081. RADIUSSecretDialog implementation
  1082. ---------------------------------------------------------------------------*/
  1083. RADIUSSecretDialog::RADIUSSecretDialog(CWnd* pParent /*=NULL*/)
  1084. : CBaseDialog(RADIUSSecretDialog::IDD, pParent)
  1085. {
  1086. //{{AFX_DATA_INIT(RADIUSSecretDialog)
  1087. //}}AFX_DATA_INIT
  1088. m_cchNewSecret = 0;
  1089. m_stNewSecret.Empty();
  1090. m_ucNewSeed = 0;
  1091. }
  1092. RADIUSSecretDialog::~RADIUSSecretDialog()
  1093. {
  1094. ::SecureZeroMemory(m_stNewSecret.GetBuffer(0),
  1095. m_stNewSecret.GetLength() * sizeof(TCHAR));
  1096. m_stNewSecret.ReleaseBuffer(-1);
  1097. }
  1098. void RADIUSSecretDialog::DoDataExchange(CDataExchange* pDX)
  1099. {
  1100. CDialog::DoDataExchange(pDX);
  1101. //{{AFX_DATA_MAP(RADIUSSecretDialog)
  1102. DDX_Control(pDX, IDC_SECRET_EDIT_NEW, m_editSecretNew);
  1103. DDX_Control(pDX, IDC_SECRET_EDIT_NEW_CONFIRM, m_editSecretNewConfirm);
  1104. //}}AFX_DATA_MAP
  1105. }
  1106. BEGIN_MESSAGE_MAP(RADIUSSecretDialog, CBaseDialog)
  1107. //{{AFX_MSG_MAP(RADIUSSecretDialog)
  1108. // ON_WM_CONTEXTMENU()
  1109. // ON_WM_HELPINFO()
  1110. //}}AFX_MSG_MAP
  1111. END_MESSAGE_MAP()
  1112. /////////////////////////////////////////////////////////////////////////////
  1113. // RADIUSSecretDialog message handlers
  1114. /*!--------------------------------------------------------------------------
  1115. RADIUSSecretDialog::GetSecret
  1116. -
  1117. Author: KennT
  1118. ---------------------------------------------------------------------------*/
  1119. VOID RADIUSSecretDialog::GetSecret(CString *pst, INT *pcch, UCHAR *pucSeed)
  1120. {
  1121. *pst = m_stNewSecret;
  1122. *pcch = m_cchNewSecret;
  1123. *pucSeed = m_ucNewSeed;
  1124. }
  1125. /*!--------------------------------------------------------------------------
  1126. RADIUSSecretDialog::OnInitDialog
  1127. -
  1128. Author: KennT
  1129. ---------------------------------------------------------------------------*/
  1130. BOOL RADIUSSecretDialog::OnInitDialog()
  1131. {
  1132. CBaseDialog::OnInitDialog();
  1133. m_editSecretNew.SetWindowText(c_szEmpty);
  1134. m_editSecretNewConfirm.SetWindowText(c_szEmpty);
  1135. return FALSE; // return TRUE unless you set the focus to a control
  1136. // EXCEPTION: OCX Property Pages should return FALSE
  1137. }
  1138. /*!--------------------------------------------------------------------------
  1139. RADIUSSecretDialog::OnOK
  1140. -
  1141. Author: KennT
  1142. ---------------------------------------------------------------------------*/
  1143. void RADIUSSecretDialog::OnOK()
  1144. {
  1145. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1146. CString stTemp;
  1147. CString stNew, stNewConfirm, stOld;
  1148. UCHAR ucSeed;
  1149. // Get the text for the new password, compare it to the
  1150. // new confirm passord, if they are the same use that as
  1151. // the password.
  1152. GetDlgItemText(IDC_SECRET_EDIT_NEW, stNew);
  1153. GetDlgItemText(IDC_SECRET_EDIT_NEW_CONFIRM, stNewConfirm);
  1154. if (stNew != stNewConfirm)
  1155. {
  1156. AfxMessageBox(IDS_ERR_SECRETS_MUST_MATCH);
  1157. return;
  1158. }
  1159. // Zero out the old value
  1160. ::SecureZeroMemory(m_stNewSecret.GetBuffer(0),
  1161. m_stNewSecret.GetLength() * sizeof(TCHAR));
  1162. m_stNewSecret.ReleaseBuffer(-1);
  1163. // Get the new values (and encrypt)
  1164. m_stNewSecret = stNew;
  1165. m_ucNewSeed = ENCRYPT_SEED;
  1166. RtlEncodeW(&m_ucNewSeed, m_stNewSecret.GetBuffer(0));
  1167. m_stNewSecret.ReleaseBuffer(-1);
  1168. m_cchNewSecret = m_stNewSecret.GetLength();
  1169. // Zero out the on-stack memory
  1170. ::SecureZeroMemory(stNew.GetBuffer(0),
  1171. stNew.GetLength() * sizeof(TCHAR));
  1172. stNew.ReleaseBuffer(-1);
  1173. ::SecureZeroMemory(stNewConfirm.GetBuffer(0),
  1174. stNewConfirm.GetLength() * sizeof(TCHAR));
  1175. stNewConfirm.ReleaseBuffer(-1);
  1176. // Need to grab the current value of the secret out of the edit
  1177. // control. If there are only backspace characters, then do
  1178. // not change the secret. Otherwise overwrite the current secret.
  1179. // m_editSecret.GetWindowText(stTemp);
  1180. // for (int i=0; i<stTemp.GetLength(); i++)
  1181. // {
  1182. // if (stTemp[i] != _T('\b'))
  1183. // {
  1184. // // Ok, the secret has changed, use the new password instead
  1185. // RtlEncodeW(&m_ucSeed, stTemp.GetBuffer(0));
  1186. // stTemp.ReleaseBuffer(-1);
  1187. //
  1188. // // Get a pointer to the old memory and write 0's into it
  1189. // ::SecureZeroMemory(m_stSecret.GetBuffer(0),
  1190. // m_stSecret.GetLength() * sizeof(TCHAR));
  1191. // m_stSecret.ReleaseBuffer(-1);
  1192. //
  1193. // m_stSecret = stTemp;
  1194. // break;
  1195. // }
  1196. // }
  1197. CBaseDialog::OnOK();
  1198. }
  1199. /*---------------------------------------------------------------------------
  1200. RouterAcctRadiusConfig implementation
  1201. ---------------------------------------------------------------------------*/
  1202. /*!--------------------------------------------------------------------------
  1203. RouterAcctRadiusConfig::Initialize
  1204. -
  1205. Author: KennT
  1206. ---------------------------------------------------------------------------*/
  1207. HRESULT RouterAcctRadiusConfig::Initialize(LPCOLESTR pszMachineName,
  1208. ULONG_PTR *puConnection)
  1209. {
  1210. HRESULT hr = hrOK;
  1211. // Parameter checking
  1212. // ----------------------------------------------------------------
  1213. if (puConnection == NULL)
  1214. return E_INVALIDARG;
  1215. COM_PROTECT_TRY
  1216. {
  1217. // for now, allocate a string and have it point at the string
  1218. // ------------------------------------------------------------
  1219. *puConnection = (ULONG_PTR) StrDupTFromOle(pszMachineName);
  1220. }
  1221. COM_PROTECT_CATCH;
  1222. return hr;
  1223. }
  1224. /*!--------------------------------------------------------------------------
  1225. RouterAcctRadiusConfig::Uninitialize
  1226. -
  1227. Author: KennT
  1228. ---------------------------------------------------------------------------*/
  1229. HRESULT RouterAcctRadiusConfig::Uninitialize(ULONG_PTR uConnection)
  1230. {
  1231. HRESULT hr = hrOK;
  1232. COM_PROTECT_TRY
  1233. {
  1234. delete (TCHAR *) uConnection;
  1235. }
  1236. COM_PROTECT_CATCH;
  1237. return hr;
  1238. }
  1239. /*!--------------------------------------------------------------------------
  1240. RouterAcctRadiusConfig::Configure
  1241. -
  1242. Author: KennT
  1243. ---------------------------------------------------------------------------*/
  1244. HRESULT RouterAcctRadiusConfig::Configure(
  1245. ULONG_PTR uConnection,
  1246. HWND hWnd,
  1247. DWORD dwFlags,
  1248. ULONG_PTR uReserved1,
  1249. ULONG_PTR uReserved2)
  1250. {
  1251. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1252. RadiusServerDialog acctDlg(FALSE, IDS_RADIUS_SERVER_ACCT_TITLE);
  1253. HRESULT hr = hrOK;
  1254. COM_PROTECT_TRY
  1255. {
  1256. acctDlg.SetServer((TCHAR *) uConnection);
  1257. acctDlg.DoModal();
  1258. }
  1259. COM_PROTECT_CATCH;
  1260. return hr;
  1261. }
  1262. /*!--------------------------------------------------------------------------
  1263. RouterAcctRadiusConfig::Activate
  1264. -
  1265. Author: KennT
  1266. ---------------------------------------------------------------------------*/
  1267. HRESULT RouterAcctRadiusConfig::Activate(
  1268. ULONG_PTR uConnection,
  1269. ULONG_PTR uReserved1,
  1270. ULONG_PTR uReserved2)
  1271. {
  1272. HRESULT hr = hrOK;
  1273. COM_PROTECT_TRY
  1274. {
  1275. }
  1276. COM_PROTECT_CATCH;
  1277. return hr;
  1278. }
  1279. /*!--------------------------------------------------------------------------
  1280. RouterAcctRadiusConfig::Deactivate
  1281. -
  1282. Author: KennT
  1283. ---------------------------------------------------------------------------*/
  1284. HRESULT RouterAcctRadiusConfig::Deactivate(
  1285. ULONG_PTR uConnection,
  1286. ULONG_PTR uReserved1,
  1287. ULONG_PTR uReserved2)
  1288. {
  1289. HRESULT hr = hrOK;
  1290. COM_PROTECT_TRY
  1291. {
  1292. }
  1293. COM_PROTECT_CATCH;
  1294. return hr;
  1295. }
  1296. /*---------------------------------------------------------------------------
  1297. ServerPropAcctDialog implementation
  1298. ---------------------------------------------------------------------------*/
  1299. ServerPropAcctDialog::ServerPropAcctDialog(BOOL fEdit, CWnd* pParent /*=NULL*/)
  1300. : ServerPropDialog(fEdit, ServerPropAcctDialog::IDD, pParent)
  1301. {
  1302. //{{AFX_DATA_INIT(ServerPropAcctDialog)
  1303. //}}AFX_DATA_INIT
  1304. }
  1305. ServerPropAcctDialog::~ServerPropAcctDialog()
  1306. {
  1307. }
  1308. void ServerPropAcctDialog::DoDataExchange(CDataExchange* pDX)
  1309. {
  1310. ServerPropDialog::DoDataExchange(pDX);
  1311. //{{AFX_DATA_MAP(ServerPropAcctDialog)
  1312. DDX_Text(pDX, IDC_RAC_EDIT_PORT, m_uAcctPort);
  1313. //}}AFX_DATA_MAP
  1314. }
  1315. BEGIN_MESSAGE_MAP(ServerPropAcctDialog, CBaseDialog)
  1316. //{{AFX_MSG_MAP(ServerPropAcctDialog)
  1317. ON_BN_CLICKED(IDC_RAC_BTN_CHANGE, OnBtnPassword)
  1318. // ON_WM_CONTEXTMENU()
  1319. // ON_WM_HELPINFO()
  1320. //}}AFX_MSG_MAP
  1321. END_MESSAGE_MAP()
  1322. /////////////////////////////////////////////////////////////////////////////
  1323. // ServerPropAcctDialog message handlers
  1324. /*!--------------------------------------------------------------------------
  1325. ServerPropAcctDialog::OnInitDialog
  1326. -
  1327. Author: KennT
  1328. ---------------------------------------------------------------------------*/
  1329. BOOL ServerPropAcctDialog::OnInitDialog()
  1330. {
  1331. ServerPropDialog::OnInitDialog();
  1332. CheckDlgButton(IDC_RAC_BTN_ONOFF, m_fAccountingOnOff);
  1333. return FALSE; // return TRUE unless you set the focus to a control
  1334. // EXCEPTION: OCX Property Pages should return FALSE
  1335. }
  1336. /*!--------------------------------------------------------------------------
  1337. ServerPropAcctDialog::OnOK
  1338. -
  1339. Author: KennT
  1340. ---------------------------------------------------------------------------*/
  1341. void ServerPropAcctDialog::OnOK()
  1342. {
  1343. CString stTemp;
  1344. // Need to grab the current value of the secret out of the edit
  1345. // control. If there are only backspace characters, then do
  1346. // not change the secret. Otherwise overwrite the current secret.
  1347. // m_editSecret.GetWindowText(stTemp);
  1348. // for (int i=0; i<stTemp.GetLength(); i++)
  1349. // {
  1350. // if (stTemp[i] != _T('\b'))
  1351. // {
  1352. // // Ok, the secret has changed, use the new password instead
  1353. // RtlEncodeW(&m_ucSeed, stTemp.GetBuffer(0));
  1354. // stTemp.ReleaseBuffer(-1);
  1355. //
  1356. // // Get a pointer to the old memory and write 0's into it
  1357. // ::SecureZeroMemory(m_stSecret.GetBuffer(0),
  1358. // m_stSecret.GetLength() * sizeof(TCHAR));
  1359. // m_stSecret.ReleaseBuffer(-1);
  1360. //
  1361. // m_stSecret = stTemp;
  1362. // break;
  1363. // }
  1364. // }
  1365. m_fAccountingOnOff = IsDlgButtonChecked(IDC_RAC_BTN_ONOFF);
  1366. ServerPropDialog::OnOK();
  1367. }
  1368. //static const DWORD rgHelpIDs[] =
  1369. // {
  1370. // IDC_EDIT_SERVERNAME, IDH_SERVER_NAME,
  1371. // IDC_EDIT_SECRET, IDH_SECRET,
  1372. // IDC_EDIT_TIMEOUT, IDH_TIMEOUT,
  1373. // IDC_SPIN_TIMEOUT, IDH_TIMEOUT,
  1374. // IDC_EDIT_SCORE, IDH_INITIAL_SCORE,
  1375. // IDC_SPIN_SCORE, IDH_INITIAL_SCORE,
  1376. // IDC_CHECK_ACCT, IDH_ENABLE_ACCOUNTING,
  1377. // IDC_STATIC_ACCTPORT, IDH_ACCOUNTING_PORT,
  1378. // IDC_EDIT_ACCTPORT, IDH_ACCOUNTING_PORT,
  1379. // IDC_CHECK_AUTH, IDH_ENABLE_AUTHENTICATION,
  1380. // IDC_STATIC_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1381. // IDC_EDIT_AUTHPORT, IDH_AUTHENTICATION_PORT,
  1382. // IDC_CHECK_ACCT_ONOFF, IDH_ACCOUNTING_ONOFF,
  1383. // 0, 0
  1384. //};