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.

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