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.

392 lines
10 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // pgauthen.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Implementation of CPgAuthentication -- property page to edit
  12. // profile attributes related to Authenticaion
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "stdafx.h"
  16. #include "rrascfg.h"
  17. #include "resource.h"
  18. #include "PgAuthen.h"
  19. #include "helptable.h"
  20. #include <htmlhelp.h>
  21. #include "eapnegotiate.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. #define NO_OLD_VALUE
  28. #define AUTHEN_WARNING_helppath "\\help\\RRASconcepts.chm::/sag_RRAS-Ch1_44.htm"
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CPgAuthenticationMerge message handlers
  31. BEGIN_MESSAGE_MAP(CPgAuthenticationMerge, CPropertyPage)
  32. //{{AFX_MSG_MAP(CPgAuthenticationMerge)
  33. ON_BN_CLICKED(IDC_CHECKMD5CHAP, OnCheckmd5chap)
  34. ON_BN_CLICKED(IDC_CHECKMSCHAP, OnCheckmschap)
  35. ON_BN_CLICKED(IDC_CHECKPAP, OnCheckpap)
  36. ON_WM_CONTEXTMENU()
  37. ON_WM_HELPINFO()
  38. ON_BN_CLICKED(IDC_EAP_METHODS, OnAuthConfigEapMethods)
  39. ON_BN_CLICKED(IDC_CHECKMSCHAP2, OnCheckmschap2)
  40. ON_BN_CLICKED(IDC_CHECKNOAUTHEN, OnChecknoauthen)
  41. ON_BN_CLICKED(IDC_CHECKMSCHAPPASS, OnCheckmschapPass)
  42. ON_BN_CLICKED(IDC_CHECKMSCHAP2PASS, OnCheckmschap2Pass)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. CPgAuthenticationMerge::CPgAuthenticationMerge(CRASProfileMerge& profile)
  46. : CManagedPage(CPgAuthenticationMerge::IDD),
  47. m_Profile(profile),
  48. m_fromProfile(true)
  49. {
  50. //{{AFX_DATA_INIT(CPgAuthenticationMerge)
  51. m_bMD5Chap = FALSE;
  52. m_bMSChap = FALSE;
  53. m_bPAP = FALSE;
  54. m_bMSCHAP2 = FALSE;
  55. m_bUNAUTH = FALSE;
  56. m_bMSChapPass = FALSE;
  57. m_bMSChap2Pass = FALSE;
  58. //}}AFX_DATA_INIT
  59. m_bEAP = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_EAP)!= -1);
  60. m_bMSChap = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAP) != -1);
  61. m_bMD5Chap = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_MD5CHAP) != -1);
  62. m_bPAP = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_PAP_SPAP) != -1);
  63. m_bMSCHAP2 = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAP2) != -1);
  64. m_bUNAUTH = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_UNAUTHEN) != -1);
  65. m_bMSChapPass = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAPPASS) != -1);
  66. m_bMSChap2Pass = (m_Profile.m_dwArrayAuthenticationTypes.Find(RAS_AT_MSCHAP2PASS) != -1);
  67. // original values before edit
  68. m_bOrgEAP = m_bEAP;
  69. m_bOrgMD5Chap = m_bMD5Chap;
  70. m_bOrgMSChap = m_bMSChap;
  71. m_bOrgPAP = m_bPAP;
  72. m_bOrgMSCHAP2 = m_bMSCHAP2;
  73. m_bOrgUNAUTH = m_bUNAUTH;
  74. m_bOrgChapPass = m_bMSChapPass;
  75. m_bOrgChap2Pass = m_bMSChap2Pass;
  76. m_bAppliedEver = FALSE;
  77. SetHelpTable(g_aHelpIDs_IDD_AUTHENTICATION_MERGE);
  78. }
  79. CPgAuthenticationMerge::~CPgAuthenticationMerge()
  80. {
  81. // compare the setting with the original ones,
  82. // if user turned on more authentication type,
  83. // start help
  84. if( (!m_bOrgEAP && m_bEAP)
  85. || (!m_bOrgMD5Chap && m_bMD5Chap)
  86. || (!m_bOrgMSChap && m_bMSChap)
  87. || (!m_bOrgChapPass && m_bMSChapPass)
  88. || (!m_bOrgPAP && m_bPAP)
  89. || (!m_bOrgMSCHAP2 && m_bMSCHAP2)
  90. || (!m_bOrgChap2Pass && m_bMSChap2Pass)
  91. || (!m_bOrgUNAUTH && m_bUNAUTH))
  92. {
  93. if ( IDYES== AfxMessageBox(IDS_WARN_MORE_STEPS_FOR_AUTHEN, MB_YESNO))
  94. HtmlHelpA(NULL, AUTHEN_WARNING_helppath, HH_DISPLAY_TOPIC, 0);
  95. }
  96. }
  97. void CPgAuthenticationMerge::DoDataExchange(CDataExchange* pDX)
  98. {
  99. CPropertyPage::DoDataExchange(pDX);
  100. //{{AFX_DATA_MAP(CPgAuthenticationMerge)
  101. DDX_Check(pDX, IDC_CHECKMD5CHAP, m_bMD5Chap);
  102. DDX_Check(pDX, IDC_CHECKMSCHAP, m_bMSChap);
  103. DDX_Check(pDX, IDC_CHECKMSCHAP2, m_bMSCHAP2);
  104. DDX_Check(pDX, IDC_CHECKNOAUTHEN, m_bUNAUTH);
  105. DDX_Check(pDX, IDC_CHECKPAP, m_bPAP);
  106. DDX_Check(pDX, IDC_CHECKMSCHAPPASS, m_bMSChapPass);
  107. DDX_Check(pDX, IDC_CHECKMSCHAP2PASS, m_bMSChap2Pass);
  108. //}}AFX_DATA_MAP
  109. if (!m_bMSChap)
  110. {
  111. m_bMSChapPass = false;
  112. }
  113. if (!m_bMSCHAP2)
  114. {
  115. m_bMSChap2Pass = false;
  116. }
  117. }
  118. BOOL CPgAuthenticationMerge::OnInitDialog()
  119. {
  120. GetDlgItem(IDC_CHECKMSCHAP2PASS)->EnableWindow(m_bMSCHAP2);
  121. GetDlgItem(IDC_CHECKMSCHAPPASS)->EnableWindow(m_bMSChap);
  122. try
  123. {
  124. HRESULT hr = m_Profile.GetEapTypeList(
  125. m_eapConfig.types,
  126. m_eapConfig.ids,
  127. m_eapConfig.typeKeys,
  128. &m_eapConfig.infoArray);
  129. if FAILED(hr)
  130. {
  131. ReportError(hr, IDS_ERR_EAPTYPELIST, NULL);
  132. }
  133. }
  134. catch(CMemoryException *pException)
  135. {
  136. pException->Delete();
  137. AfxMessageBox(IDS_OUTOFMEMORY);
  138. return TRUE;
  139. }
  140. CPropertyPage::OnInitDialog();
  141. return TRUE; // return TRUE unless you set the focus to a control
  142. // EXCEPTION: OCX Property Pages should return FALSE
  143. }
  144. void CPgAuthenticationMerge::OnCheckmd5chap()
  145. {
  146. SetModified();
  147. }
  148. void CPgAuthenticationMerge::OnCheckmschap()
  149. {
  150. CButton *Button = reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECKMSCHAP));
  151. int status = Button->GetCheck();
  152. switch (status)
  153. {
  154. case 1:
  155. {
  156. GetDlgItem(IDC_CHECKMSCHAPPASS)->EnableWindow(TRUE);
  157. break;
  158. }
  159. case 0:
  160. {
  161. GetDlgItem(IDC_CHECKMSCHAPPASS)->EnableWindow(FALSE);
  162. break;
  163. }
  164. default:
  165. {
  166. }
  167. }
  168. SetModified();
  169. }
  170. void CPgAuthenticationMerge::OnCheckmschapPass()
  171. {
  172. SetModified();
  173. }
  174. void CPgAuthenticationMerge::OnCheckmschap2()
  175. {
  176. CButton *Button = reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECKMSCHAP2));
  177. int status = Button->GetCheck();
  178. switch (status)
  179. {
  180. case 1:
  181. {
  182. GetDlgItem(IDC_CHECKMSCHAP2PASS)->EnableWindow(TRUE);
  183. break;
  184. }
  185. case 0:
  186. {
  187. GetDlgItem(IDC_CHECKMSCHAP2PASS)->EnableWindow(FALSE);
  188. break;
  189. }
  190. default:
  191. {
  192. }
  193. }
  194. SetModified();
  195. }
  196. void CPgAuthenticationMerge::OnCheckmschap2Pass()
  197. {
  198. SetModified();
  199. }
  200. void CPgAuthenticationMerge::OnCheckpap()
  201. {
  202. SetModified();
  203. }
  204. BOOL CPgAuthenticationMerge::TransferDataToProfile()
  205. {
  206. // clear the string in profile
  207. m_Profile.m_dwArrayAuthenticationTypes.DeleteAll();
  208. if (m_bEAP || m_bMSChap || m_bMD5Chap || m_bPAP || m_bMSCHAP2 || m_bUNAUTH ||
  209. m_bMSChapPass || m_bMSChap2Pass)
  210. {
  211. m_Profile.m_dwAttributeFlags |= PABF_msNPAuthenticationType;
  212. }
  213. else
  214. {
  215. AfxMessageBox(IDS_DATAENTRY_AUTHENTICATIONTYPE);
  216. return FALSE;
  217. }
  218. // EAP
  219. if (m_bEAP)
  220. {
  221. m_Profile.m_dwArrayAuthenticationTypes.Add(RAS_AT_EAP);
  222. }
  223. else
  224. {
  225. m_Profile.m_dwAttributeFlags &= ~PABF_msNPAllowedEapType;
  226. m_Profile.m_dwArrayEapTypes.DeleteAll();
  227. m_Profile.m_dwArraynEAPTypeKeys.DeleteAll();
  228. }
  229. if (m_eapConfig.typesSelected.GetSize() > 0)
  230. {
  231. // here the button configure eap.. was pressed and some eap types
  232. // were selected. (could be the same as before)
  233. m_Profile.m_dwAttributeFlags |= PABF_msNPAllowedEapType;
  234. CDWArray eapTypesSelected;
  235. CDWArray typeKeysSelected;
  236. for (int i = 0; i < m_eapConfig.typesSelected.GetSize(); ++i)
  237. {
  238. // For each EAP Type Selected (string)
  239. // position = index in the types, ids and typekeys arrays
  240. // corresponding to the EAP type selected
  241. int position = m_eapConfig.types.Find(
  242. *m_eapConfig.typesSelected.GetAt(i));
  243. eapTypesSelected.Add(m_eapConfig.ids.GetAt(position));
  244. typeKeysSelected.Add(m_eapConfig.typeKeys.GetAt(position));
  245. }
  246. m_Profile.m_dwArrayEapTypes = eapTypesSelected;
  247. m_Profile.m_dwArraynEAPTypeKeys = typeKeysSelected;
  248. }
  249. // else: EAP was enabled when the page was opened. Nothing was changed in
  250. // the EAP config. No need to update the list of eap types.
  251. // MS-Chap2
  252. if(m_bMSCHAP2)
  253. m_Profile.m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP2);
  254. // MS-Chap
  255. if(m_bMSChap)
  256. m_Profile.m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP);
  257. // MS-Chap2 Password Change
  258. if(m_bMSChap2Pass)
  259. m_Profile.m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP2_CPW);
  260. // MS-Chap Password Change
  261. if(m_bMSChapPass)
  262. m_Profile.m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MSCHAP_CPW);
  263. // Chap
  264. if(m_bMD5Chap)
  265. m_Profile.m_dwArrayAuthenticationTypes.Add(IAS_AUTH_MD5CHAP);
  266. // PAP
  267. if(m_bPAP)
  268. {
  269. m_Profile.m_dwArrayAuthenticationTypes.Add(IAS_AUTH_PAP);
  270. }
  271. // UNAUTH
  272. if(m_bUNAUTH)
  273. {
  274. m_Profile.m_dwArrayAuthenticationTypes.Add(IAS_AUTH_NONE);
  275. }
  276. return TRUE;
  277. }
  278. void CPgAuthenticationMerge::OnOK()
  279. {
  280. CManagedPage::OnOK();
  281. }
  282. BOOL CPgAuthenticationMerge::OnApply()
  283. {
  284. if (!GetModified())
  285. {
  286. return TRUE;
  287. }
  288. if (!TransferDataToProfile())
  289. {
  290. return FALSE;
  291. }
  292. m_bAppliedEver = TRUE;
  293. return CManagedPage::OnApply();
  294. }
  295. void CPgAuthenticationMerge::OnContextMenu(CWnd* pWnd, CPoint point)
  296. {
  297. CManagedPage::OnContextMenu(pWnd, point);
  298. }
  299. BOOL CPgAuthenticationMerge::OnHelpInfo(HELPINFO* pHelpInfo)
  300. {
  301. return CManagedPage::OnHelpInfo(pHelpInfo);
  302. }
  303. BOOL CPgAuthenticationMerge::OnKillActive()
  304. {
  305. UpdateData();
  306. if (!TransferDataToProfile())
  307. {
  308. return FALSE;
  309. }
  310. return CPropertyPage::OnKillActive();
  311. }
  312. void CPgAuthenticationMerge::OnAuthConfigEapMethods()
  313. {
  314. EapConfig eapConfigBackup;
  315. eapConfigBackup = m_eapConfig;
  316. EapNegotiate eapNegotiate(this, m_eapConfig, m_Profile, m_fromProfile);
  317. HRESULT hr = eapNegotiate.m_eapProfile.Assign(m_Profile.m_eapConfigData);
  318. if (SUCCEEDED(hr))
  319. {
  320. if (eapNegotiate.DoModal() == IDOK)
  321. {
  322. m_Profile.m_eapConfigData.Swap(eapNegotiate.m_eapProfile);
  323. m_bEAP = (m_eapConfig.typesSelected.GetSize() > 0)? TRUE: FALSE;
  324. SetModified();
  325. m_fromProfile = false;
  326. }
  327. }
  328. else
  329. {
  330. m_eapConfig = eapConfigBackup;
  331. }
  332. }
  333. void CPgAuthenticationMerge::OnChecknoauthen()
  334. {
  335. SetModified();
  336. }