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.

412 lines
11 KiB

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