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.

531 lines
14 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2000 **/
  4. /**********************************************************************/
  5. /*
  6. pgauthen.cpp
  7. Implementation of CPgAuthentication -- property page to edit
  8. profile attributes related to Authenticaion
  9. FILE HISTORY:
  10. */
  11. // PgAuthen.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include <rrascfg.h>
  15. #include "resource.h"
  16. #include "PgAuthen.h"
  17. #include "hlptable.h"
  18. #include <htmlhelp.h>
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #define NO_OLD_VALUE
  25. // help path
  26. // hh.exe <SystemRoot>\help\RRASconcepts.chm::/sag_RRAS-Ch1_44.htm
  27. #define AUTHEN_WARNING_helppath "\\help\\RRASconcepts.chm::/sag_RRAS-Ch1_44.htm"
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CPgAuthenticationMerge property page
  30. IMPLEMENT_DYNCREATE(CPgAuthenticationMerge, CPropertyPage)
  31. CPgAuthenticationMerge::CPgAuthenticationMerge(CRASProfileMerge* profile)
  32. : CManagedPage(CPgAuthenticationMerge::IDD),
  33. m_pProfile(profile)
  34. {
  35. //{{AFX_DATA_INIT(CPgAuthenticationMerge)
  36. m_bEAP = FALSE;
  37. m_bMD5Chap = FALSE;
  38. m_bMSChap = FALSE;
  39. m_bPAP = FALSE;
  40. m_strEapType = _T("");
  41. m_bMSCHAP2 = FALSE;
  42. m_bUNAUTH = FALSE;
  43. m_bMSChapPass = FALSE;
  44. m_bMSChap2Pass = FALSE;
  45. //}}AFX_DATA_INIT
  46. m_bEAP = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_EAP)!= -1);
  47. m_bMSChap = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAP) != -1);
  48. m_bMD5Chap = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_MD5CHAP) != -1);
  49. m_bPAP = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_PAP_SPAP) != -1);
  50. m_bMSCHAP2 = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAP2) != -1);
  51. m_bUNAUTH = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_UNAUTHEN) != -1);
  52. m_bMSChapPass = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAPPASS) != -1);
  53. m_bMSChap2Pass = (m_pProfile->m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAP2PASS) != -1);
  54. // orginal value before edit
  55. m_bOrgEAP = m_bEAP;
  56. m_bOrgMD5Chap = m_bMD5Chap;
  57. m_bOrgMSChap = m_bMSChap;
  58. m_bOrgPAP = m_bPAP;
  59. m_bOrgMSCHAP2 = m_bMSCHAP2;
  60. m_bOrgUNAUTH = m_bUNAUTH;
  61. m_bOrgChapPass = m_bMSChapPass;
  62. m_bOrgChap2Pass = m_bMSChap2Pass;
  63. m_bAppliedEver = FALSE;
  64. m_pBox = NULL;
  65. SetHelpTable(g_aHelpIDs_IDD_AUTHENTICATION_MERGE);
  66. m_bInited = false;
  67. }
  68. CPgAuthenticationMerge::~CPgAuthenticationMerge()
  69. {
  70. delete m_pBox;
  71. // compare the setting with the original ones,
  72. // if user turned on more authentication type,
  73. // start help
  74. if(
  75. (!m_bOrgEAP && m_bEAP)
  76. || (!m_bOrgMD5Chap && m_bMD5Chap)
  77. || (!m_bOrgMSChap && m_bMSChap)
  78. || (!m_bOrgChapPass && m_bMSChapPass)
  79. || (!m_bOrgPAP && m_bPAP)
  80. || (!m_bOrgMSCHAP2 && m_bMSCHAP2)
  81. || (!m_bOrgChap2Pass && m_bMSChap2Pass)
  82. || (!m_bOrgUNAUTH && m_bUNAUTH))
  83. {
  84. if ( IDYES== AfxMessageBox(IDS_WARN_MORE_STEPS_FOR_AUTHEN, MB_YESNO))
  85. HtmlHelpA(NULL, AUTHEN_WARNING_helppath, HH_DISPLAY_TOPIC, 0);
  86. }
  87. }
  88. void CPgAuthenticationMerge::DoDataExchange(CDataExchange* pDX)
  89. {
  90. ASSERT(m_pProfile);
  91. CPropertyPage::DoDataExchange(pDX);
  92. //{{AFX_DATA_MAP(CPgAuthenticationMerge)
  93. DDX_Check(pDX, IDC_CHECKEAP, m_bEAP);
  94. DDX_Check(pDX, IDC_CHECKMD5CHAP, m_bMD5Chap);
  95. DDX_Check(pDX, IDC_CHECKMSCHAP, m_bMSChap);
  96. DDX_CBString(pDX, IDC_COMBOEAPTYPE, m_strEapType);
  97. DDX_Check(pDX, IDC_CHECKMSCHAP2, m_bMSCHAP2);
  98. DDX_Check(pDX, IDC_CHECKNOAUTHEN, m_bUNAUTH);
  99. DDX_Check(pDX, IDC_CHECKPAP, m_bPAP);
  100. DDX_Check(pDX, IDC_CHECKMSCHAPPASS, m_bMSChapPass);
  101. DDX_Check(pDX, IDC_CHECKMSCHAP2PASS, m_bMSChap2Pass);
  102. //}}AFX_DATA_MAP
  103. if (!m_bMSChap)
  104. {
  105. m_bMSChapPass = false;
  106. }
  107. if (!m_bMSCHAP2)
  108. {
  109. m_bMSChap2Pass = false;
  110. }
  111. }
  112. BEGIN_MESSAGE_MAP(CPgAuthenticationMerge, CPropertyPage)
  113. //{{AFX_MSG_MAP(CPgAuthenticationMerge)
  114. ON_BN_CLICKED(IDC_CHECKEAP, OnCheckeap)
  115. ON_BN_CLICKED(IDC_CHECKMD5CHAP, OnCheckmd5chap)
  116. ON_BN_CLICKED(IDC_CHECKMSCHAP, OnCheckmschap)
  117. ON_BN_CLICKED(IDC_CHECKPAP, OnCheckpap)
  118. ON_CBN_SELCHANGE(IDC_COMBOEAPTYPE, OnSelchangeComboeaptype)
  119. ON_WM_CONTEXTMENU()
  120. ON_WM_HELPINFO()
  121. ON_BN_CLICKED(IDC_AUTH_CONFIG_EAP, OnAuthConfigEap)
  122. ON_BN_CLICKED(IDC_CHECKMSCHAP2, OnCheckmschap2)
  123. ON_BN_CLICKED(IDC_CHECKNOAUTHEN, OnChecknoauthen)
  124. ON_BN_CLICKED(IDC_CHECKMSCHAPPASS, OnCheckmschapPass)
  125. ON_BN_CLICKED(IDC_CHECKMSCHAP2PASS, OnCheckmschap2Pass)
  126. //}}AFX_MSG_MAP
  127. END_MESSAGE_MAP()
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CPgAuthenticationMerge message handlers
  130. BOOL CPgAuthenticationMerge::OnInitDialog()
  131. {
  132. /* BUG 249326, not constrain the standalone server for this
  133. BOOL bStandaloneServer = (HrIsStandaloneServer(m_pProfile->m_strMachineName) == S_OK);
  134. */
  135. BOOL bEnableConfig = FALSE;
  136. // BUG 1170008
  137. // on standalone server, disable MD5Chap option, if it was enabled, need to disabled
  138. /* BUG 249326, not constrain the standalone server for this
  139. if(bStandaloneServer && m_bMD5Chap)
  140. {
  141. SetModified();
  142. m_bMD5Chap = 0;
  143. }
  144. */
  145. CPropertyPage::OnInitDialog();
  146. GetDlgItem(IDC_CHECKMSCHAP2PASS)->EnableWindow(m_bMSCHAP2);
  147. GetDlgItem(IDC_CHECKMSCHAPPASS)->EnableWindow(m_bMSChap);
  148. GetDlgItem(IDC_COMBOEAPTYPE)->EnableWindow(m_bEAP);
  149. // BUG 1170008
  150. // disable the MD5 Chap selection control
  151. //
  152. /* BUG 249326, not constrain the standalone server for this
  153. if(bStandaloneServer)
  154. GetDlgItem(IDC_CHECKMD5CHAP)->EnableWindow(FALSE);
  155. */
  156. // the combobox for eap types
  157. try
  158. {
  159. HRESULT hr = m_pProfile->GetEapTypeList(m_EapTypes, m_EapIds, m_EapTypeKeys, &m_EapInfoArray);
  160. m_pBox = new CStrBox<CComboBox>(this, IDC_COMBOEAPTYPE, m_EapTypes);
  161. if(m_pBox == NULL)
  162. {
  163. AfxMessageBox(IDS_OUTOFMEMORY);
  164. return TRUE;
  165. }
  166. if FAILED(hr)
  167. ReportError(hr, IDS_ERR_EAPTYPELIST, NULL);
  168. else
  169. {
  170. m_pBox->Fill();
  171. GetDlgItem(IDC_COMBOEAPTYPE)->EnableWindow(m_bEAP);
  172. }
  173. }
  174. catch(CMemoryException&)
  175. {
  176. AfxMessageBox(IDS_OUTOFMEMORY);
  177. return TRUE;
  178. }
  179. // if there is a value selected from the list
  180. if(m_EapIds.GetSize())
  181. {
  182. // find index in the list
  183. int i = m_EapIds.Find(m_pProfile->m_dwEapType);
  184. // if in the list, select it
  185. if(i != -1)
  186. {
  187. m_pBox->Select(i);
  188. bEnableConfig = !(m_EapInfoArray.ElementAt(i).m_stConfigCLSID.IsEmpty());
  189. }
  190. else
  191. {
  192. if(m_EapIds.GetSize())
  193. m_pBox->Select(0);
  194. }
  195. }
  196. GetDlgItem(IDC_AUTH_CONFIG_EAP)->EnableWindow(bEnableConfig);
  197. m_bInited = true;
  198. return TRUE; // return TRUE unless you set the focus to a control
  199. // EXCEPTION: OCX Property Pages should return FALSE
  200. }
  201. void CPgAuthenticationMerge::OnCheckeap()
  202. {
  203. BOOL b = ((CButton*)GetDlgItem(IDC_CHECKEAP))->GetCheck();
  204. // enable / disable configure button based on if the type has config clsID
  205. int i = m_pBox->GetSelected();
  206. BOOL bEnableConfig;
  207. if (i != -1)
  208. {
  209. bEnableConfig = !(m_EapInfoArray.ElementAt(i).m_stConfigCLSID.IsEmpty());
  210. }
  211. else
  212. bEnableConfig = FALSE;
  213. GetDlgItem(IDC_COMBOEAPTYPE)->EnableWindow(b);
  214. GetDlgItem(IDC_AUTH_CONFIG_EAP)->EnableWindow(bEnableConfig);
  215. SetModified();
  216. }
  217. void CPgAuthenticationMerge::OnCheckmd5chap()
  218. {
  219. // TODO: Add your control notification handler code here
  220. SetModified();
  221. }
  222. void CPgAuthenticationMerge::OnCheckmschap()
  223. {
  224. CButton *Button = reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECKMSCHAP));
  225. int status = Button->GetCheck();
  226. switch (status)
  227. {
  228. case 1:
  229. {
  230. GetDlgItem(IDC_CHECKMSCHAPPASS)->EnableWindow(TRUE);
  231. break;
  232. }
  233. case 0:
  234. {
  235. GetDlgItem(IDC_CHECKMSCHAPPASS)->EnableWindow(FALSE);
  236. break;
  237. }
  238. default:
  239. {
  240. }
  241. }
  242. SetModified();
  243. }
  244. void CPgAuthenticationMerge::OnCheckmschapPass()
  245. {
  246. // TODO: Add your control notification handler code here
  247. SetModified();
  248. }
  249. void CPgAuthenticationMerge::OnCheckmschap2()
  250. {
  251. CButton *Button = reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECKMSCHAP2));
  252. int status = Button->GetCheck();
  253. switch (status)
  254. {
  255. case 1:
  256. {
  257. GetDlgItem(IDC_CHECKMSCHAP2PASS)->EnableWindow(TRUE);
  258. break;
  259. }
  260. case 0:
  261. {
  262. GetDlgItem(IDC_CHECKMSCHAP2PASS)->EnableWindow(FALSE);
  263. break;
  264. }
  265. default:
  266. {
  267. }
  268. }
  269. SetModified();
  270. }
  271. void CPgAuthenticationMerge::OnCheckmschap2Pass()
  272. {
  273. // TODO: Add your control notification handler code here
  274. SetModified();
  275. }
  276. void CPgAuthenticationMerge::OnCheckpap()
  277. {
  278. // TODO: Add your control notification handler code here
  279. SetModified();
  280. }
  281. void CPgAuthenticationMerge::OnSelchangeComboeaptype()
  282. {
  283. // enable / disable configure button based on if the type has config clsID
  284. int i = m_pBox->GetSelected();
  285. BOOL bEnableConfig;
  286. if (i != -1)
  287. {
  288. bEnableConfig = !(m_EapInfoArray.ElementAt(i).m_stConfigCLSID.IsEmpty());
  289. }
  290. else
  291. bEnableConfig = FALSE;
  292. GetDlgItem(IDC_AUTH_CONFIG_EAP)->EnableWindow(bEnableConfig);
  293. if(m_bInited) SetModified();
  294. }
  295. BOOL CPgAuthenticationMerge::TransferDataToProfile()
  296. {
  297. // clear the string in profile
  298. m_pProfile->m_dwArrayAuthenticationTypes.DeleteAll();
  299. if(m_bEAP || m_bMSChap || m_bMD5Chap || m_bPAP || m_bMSCHAP2 || m_bUNAUTH ||
  300. m_bMSChapPass || m_bMSChap2Pass)
  301. m_pProfile->m_dwAttributeFlags |= PABF_msNPAuthenticationType;
  302. else
  303. {
  304. AfxMessageBox(IDS_DATAENTRY_AUTHENTICATIONTYPE);
  305. return FALSE;
  306. }
  307. // EAP
  308. if(m_bEAP)
  309. {
  310. m_pProfile->m_dwArrayAuthenticationTypes.Add(RAS_AT_EAP);
  311. // get the EAP type
  312. if (m_pBox->GetSelected() != -1)
  313. {
  314. m_pProfile->m_dwAttributeFlags |= PABF_msNPAllowedEapType;
  315. m_pProfile->m_dwEapType = m_EapIds.GetAt(m_pBox->GetSelected());
  316. m_pProfile->m_nEAPTypeKey = m_EapTypeKeys.GetAt(m_pBox->GetSelected());
  317. }
  318. else
  319. {
  320. GotoDlgCtrl( m_pBox->m_pBox );
  321. AfxMessageBox(IDS_DATAENTRY_EAPTYPE);
  322. return FALSE;
  323. }
  324. }
  325. else
  326. {
  327. m_pProfile->m_dwAttributeFlags &= ~PABF_msNPAllowedEapType;
  328. m_pProfile->m_dwEapType = 0;
  329. }
  330. // MS-Chap2
  331. if(m_bMSCHAP2)
  332. m_pProfile->m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP2);
  333. // MS-Chap
  334. if(m_bMSChap)
  335. m_pProfile->m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP);
  336. // MS-Chap2 Password Change
  337. if(m_bMSChap2Pass)
  338. m_pProfile->m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP2_CPW);
  339. // MS-Chap Password Change
  340. if(m_bMSChapPass)
  341. m_pProfile->m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP_CPW);
  342. // Chap
  343. if(m_bMD5Chap)
  344. m_pProfile->m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MD5CHAP);
  345. // PAP
  346. if(m_bPAP)
  347. {
  348. m_pProfile->m_dwArrayAuthenticationTypes.Add(IAS_AUTH_PAP);
  349. }
  350. // UNAUTH
  351. if(m_bUNAUTH)
  352. {
  353. m_pProfile->m_dwArrayAuthenticationTypes.Add(IAS_AUTH_NONE);
  354. }
  355. return TRUE;
  356. }
  357. void CPgAuthenticationMerge::OnOK()
  358. {
  359. CManagedPage::OnOK();
  360. }
  361. BOOL CPgAuthenticationMerge::OnApply()
  362. {
  363. if(!GetModified()) return TRUE;
  364. if(!TransferDataToProfile())
  365. return FALSE;
  366. m_bAppliedEver = TRUE;
  367. return CManagedPage::OnApply();
  368. }
  369. void CPgAuthenticationMerge::OnContextMenu(CWnd* pWnd, CPoint point)
  370. {
  371. CManagedPage::OnContextMenu(pWnd, point);
  372. }
  373. BOOL CPgAuthenticationMerge::OnHelpInfo(HELPINFO* pHelpInfo)
  374. {
  375. return CManagedPage::OnHelpInfo(pHelpInfo);
  376. }
  377. BOOL CPgAuthenticationMerge::OnKillActive()
  378. {
  379. UpdateData();
  380. if(!TransferDataToProfile())
  381. return FALSE;
  382. return CPropertyPage::OnKillActive();
  383. }
  384. const IID IID_IEAPProviderConfig = {0x66A2DB19,0xD706,0x11D0,{0xA3,0x7B,0x00,0xC0,0x4F,0xC9,0xDA,0x04}};
  385. void CPgAuthenticationMerge::OnAuthConfigEap()
  386. {
  387. // enable / disable configure button based on if the type has config clsID
  388. int i = m_pBox->GetSelected();
  389. // Bring up the configuration UI for this EAP
  390. // ----------------------------------------------------------------
  391. AuthProviderData * pData;
  392. CComPtr<IEAPProviderConfig> spEAPConfig;
  393. GUID guid;
  394. HRESULT hr = S_OK;
  395. ULONG_PTR uConnection = 0;
  396. BOOL bEnableConfig;
  397. DWORD dwId;
  398. ASSERT(i != -1); // in case of i == -1; the button should be disabled
  399. if (i != -1)
  400. {
  401. bEnableConfig = !(m_EapInfoArray.ElementAt(i).m_stConfigCLSID.IsEmpty());
  402. }
  403. else
  404. bEnableConfig = FALSE;
  405. CHECK_HR( hr = CLSIDFromString((LPTSTR) (LPCTSTR)(m_EapInfoArray.ElementAt(i).m_stConfigCLSID), &guid) );
  406. // Create the EAP provider object
  407. // ----------------------------------------------------------------
  408. CHECK_HR( hr = CoCreateInstance(guid,
  409. NULL,
  410. CLSCTX_INPROC_SERVER,
  411. IID_IEAPProviderConfig,
  412. (LPVOID *) &spEAPConfig) );
  413. // Configure this EAP provider
  414. // ----------------------------------------------------------------
  415. // EAP configure displays its own error message, so no hr is kept
  416. dwId = _ttol(m_EapInfoArray.ElementAt(i).m_stKey);
  417. if ( !FAILED(spEAPConfig->Initialize(m_pProfile->m_strMachineName, dwId, &uConnection)) )
  418. {
  419. spEAPConfig->ServerInvokeConfigUI(dwId, uConnection, GetSafeHwnd(), 0, 0);
  420. spEAPConfig->Uninitialize(dwId, uConnection);
  421. }
  422. if ( hr == E_NOTIMPL )
  423. hr = S_OK;
  424. L_ERR:
  425. if ( FAILED(hr) )
  426. {
  427. // Bring up an error message
  428. // ------------------------------------------------------------
  429. ReportError(hr, IDS_ERR_CONFIG_EAP, GetSafeHwnd());
  430. }
  431. }
  432. void CPgAuthenticationMerge::OnChecknoauthen()
  433. {
  434. // TODO: Add your control notification handler code here
  435. SetModified();
  436. }