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.

417 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. authent.cpp
  5. Abstract:
  6. WWW Authentication Dialog
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "w3scfg.h"
  18. #include "certmap.h"
  19. #include "basdom.h"
  20. #include "anondlg.h"
  21. #include "authent.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. CAuthenticationDlg::CAuthenticationDlg(
  28. IN LPCTSTR lpstrServerName,
  29. IN DWORD dwInstance,
  30. IN CString & strBasicDomain,
  31. IN DWORD & dwAuthFlags,
  32. IN DWORD & dwAccessPermissions,
  33. IN CString & strUserName,
  34. IN CString & strPassword,
  35. IN BOOL & fPasswordSync,
  36. IN BOOL fAdminAccess,
  37. IN BOOL fHasDigest,
  38. IN CWnd * pParent OPTIONAL
  39. )
  40. /*++
  41. Routine Description:
  42. Authentication dialog constructor
  43. Arguments:
  44. LPCTSTR lpstrServerName : Server name
  45. DWORD dwInstance : Instance number
  46. CString & strBasicDomain : Basic domain name
  47. DWORD & dwAuthFlags : Authorization flags
  48. DWORD & dwAccessPermissions : Access permissions
  49. CString & strUserName : Anonymous user name
  50. CString & strPassword : Anonymous user pwd
  51. BOOL & fPasswordSync : Password sync setting
  52. BOOL fAdminAccess : TRUE if user has admin access
  53. BOOL fHasDigest : TRUE if machine supports digest auth.
  54. CWnd * pParent : Optional parent window
  55. Return Value:
  56. N/A
  57. --*/
  58. : CDialog(CAuthenticationDlg::IDD, pParent),
  59. m_strServerName(lpstrServerName),
  60. m_strBasicDomain(strBasicDomain),
  61. m_strUserName(strUserName),
  62. m_strPassword(strPassword),
  63. m_dwInstance(dwInstance),
  64. m_dwAuthFlags(dwAuthFlags),
  65. m_dwAccessPermissions(dwAccessPermissions),
  66. m_fAdminAccess(fAdminAccess),
  67. m_fHasDigest(fHasDigest),
  68. m_fPasswordSync(fPasswordSync)
  69. {
  70. #if 0 // Class Wizard happy
  71. //{{AFX_DATA_INIT(CAuthenticationDlg)
  72. m_fClearText = FALSE;
  73. m_fDigest = FALSE;
  74. m_fChallengeResponse = FALSE;
  75. m_fUUEncoded = FALSE;
  76. //}}AFX_DATA_INIT
  77. #endif // 0
  78. m_fClearText = IS_FLAG_SET(m_dwAuthFlags, MD_AUTH_BASIC);
  79. m_fDigest = IS_FLAG_SET(m_dwAuthFlags, MD_AUTH_MD5);
  80. m_fChallengeResponse = IS_FLAG_SET(m_dwAuthFlags, MD_AUTH_NT);
  81. m_fUUEncoded = IS_FLAG_SET(m_dwAuthFlags, MD_AUTH_ANONYMOUS);
  82. }
  83. void
  84. CAuthenticationDlg::DoDataExchange(
  85. IN CDataExchange * pDX
  86. )
  87. /*++
  88. Routine Description:
  89. Initialise/Store control data
  90. Arguments:
  91. CDataExchange * pDX - DDX/DDV control structure
  92. Return Value:
  93. None
  94. --*/
  95. {
  96. CDialog::DoDataExchange(pDX);
  97. //{{AFX_DATA_MAP(CAuthenticationDlg)
  98. DDX_Check(pDX, IDC_CHECK_CLEAR_TEXT, m_fClearText);
  99. DDX_Check(pDX, IDC_CHECK_DIGEST, m_fDigest);
  100. DDX_Check(pDX, IDC_CHECK_NT_CHALLENGE_RESPONSE, m_fChallengeResponse);
  101. DDX_Check(pDX, IDC_CHECK_UUENCODED, m_fUUEncoded);
  102. DDX_Control(pDX, IDC_CHECK_UUENCODED, m_check_UUEncoded);
  103. DDX_Control(pDX, IDC_CHECK_NT_CHALLENGE_RESPONSE, m_check_ChallengeResponse);
  104. DDX_Control(pDX, IDC_CHECK_DIGEST, m_check_Digest);
  105. DDX_Control(pDX, IDC_CHECK_CLEAR_TEXT, m_check_ClearText);
  106. DDX_Control(pDX, IDC_BUTTON_EDIT_ANONYMOUS, m_button_EditAnonymous);
  107. DDX_Control(pDX, IDC_BUTTON_EDIT, m_button_Edit);
  108. //}}AFX_DATA_MAP
  109. }
  110. //
  111. // Message Map
  112. //
  113. BEGIN_MESSAGE_MAP(CAuthenticationDlg, CDialog)
  114. //{{AFX_MSG_MAP(CAuthenticationDlg)
  115. ON_BN_CLICKED(IDC_CHECK_CLEAR_TEXT, OnCheckClearText)
  116. ON_BN_CLICKED(IDC_CHECK_UUENCODED, OnCheckUuencoded)
  117. ON_BN_CLICKED(IDC_CHECK_DIGEST, OnCheckDigest)
  118. ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
  119. ON_BN_CLICKED(IDC_BUTTON_EDIT_ANONYMOUS, OnButtonEditAnonymous)
  120. //}}AFX_MSG_MAP
  121. END_MESSAGE_MAP()
  122. void
  123. CAuthenticationDlg::SetControlStates()
  124. /*++
  125. Routine Description:
  126. Set control states depending on current data in the dialog
  127. Arguments:
  128. None
  129. Return Value:
  130. None
  131. --*/
  132. {
  133. m_button_Edit.EnableWindow(m_fClearText);
  134. m_button_EditAnonymous.EnableWindow(m_fUUEncoded && m_fAdminAccess);
  135. }
  136. BOOL
  137. CAuthenticationDlg::OnInitDialog()
  138. /*++
  139. Routine Description:
  140. WM_INITDIALOG handler. Initialize the dialog.
  141. Arguments:
  142. None.
  143. Return Value:
  144. TRUE if no focus is to be set automatically, FALSE if the focus
  145. is already set.
  146. --*/
  147. {
  148. CDialog::OnInitDialog();
  149. SetControlStates();
  150. //
  151. // Ensure compatibility with downlevel
  152. //
  153. m_check_Digest.EnableWindow(m_fHasDigest);
  154. return TRUE;
  155. }
  156. void
  157. CAuthenticationDlg::OnCheckClearText()
  158. /*++
  159. Routine Description:
  160. Clear text checkbox handler
  161. Arguments:
  162. None
  163. Return Value:
  164. None
  165. --*/
  166. {
  167. if (m_check_ClearText.GetCheck() == 1)
  168. {
  169. CClearTxtDlg dlg;
  170. if (dlg.DoModal() != IDOK)
  171. {
  172. m_check_ClearText.SetCheck(0);
  173. return;
  174. }
  175. }
  176. m_fClearText = !m_fClearText;
  177. SetControlStates();
  178. }
  179. void
  180. CAuthenticationDlg::OnCheckDigest()
  181. /*++
  182. Routine Description:
  183. 'Digest' checkbox handler
  184. Arguments:
  185. None
  186. Return Value:
  187. None
  188. --*/
  189. {
  190. ASSERT(m_fHasDigest);
  191. if (m_check_Digest.GetCheck() == 1)
  192. {
  193. if (!NoYesMessageBox(IDS_WRN_DIGEST))
  194. {
  195. m_check_Digest.SetCheck(0);
  196. return;
  197. }
  198. }
  199. m_fDigest = !m_fDigest;
  200. SetControlStates();
  201. }
  202. void
  203. CAuthenticationDlg::OnCheckUuencoded()
  204. /*++
  205. Routine Description:
  206. UU Encoding checkbox been pressed.
  207. Arguments:
  208. None
  209. Return Value:
  210. None
  211. --*/
  212. {
  213. m_fUUEncoded = !m_fUUEncoded;
  214. SetControlStates();
  215. }
  216. void
  217. CAuthenticationDlg::OnButtonEditAnonymous()
  218. /*++
  219. Routine Description:
  220. 'Edit anonymous' button handler
  221. Arguments:
  222. None
  223. Return Value:
  224. None
  225. --*/
  226. {
  227. CAnonymousDlg dlg(
  228. m_strServerName,
  229. m_strUserName,
  230. m_strPassword,
  231. m_fPasswordSync,
  232. this
  233. );
  234. if (dlg.DoModal() == IDOK)
  235. {
  236. m_strUserName = dlg.GetUserName();
  237. m_strPassword = dlg.GetPassword();
  238. m_fPasswordSync = dlg.GetPasswordSync();
  239. }
  240. }
  241. void
  242. CAuthenticationDlg::OnButtonEdit()
  243. /*++
  244. Routine Description:
  245. 'Edit default basic domain dialog' button handler
  246. Arguments:
  247. None
  248. Return Value:
  249. None
  250. --*/
  251. {
  252. CBasDomainDlg dlg(m_strBasicDomain);
  253. if (dlg.DoModal() == IDOK)
  254. {
  255. m_strBasicDomain = dlg.GetBasicDomain();
  256. }
  257. }
  258. void
  259. CAuthenticationDlg::OnOK()
  260. /*++
  261. Routine Description:
  262. OK button handler, save information
  263. Arguments:
  264. None
  265. Return Value:
  266. None
  267. --*/
  268. {
  269. if (UpdateData(TRUE))
  270. {
  271. SET_FLAG_IF(m_fClearText, m_dwAuthFlags, MD_AUTH_BASIC);
  272. SET_FLAG_IF(m_fChallengeResponse, m_dwAuthFlags, MD_AUTH_NT);
  273. SET_FLAG_IF(m_fUUEncoded, m_dwAuthFlags, MD_AUTH_ANONYMOUS);
  274. SET_FLAG_IF(m_fDigest, m_dwAuthFlags, MD_AUTH_MD5);
  275. //
  276. // Provide warning if no authentication is selected
  277. //
  278. if (!m_dwAuthFlags
  279. && !m_dwAccessPermissions
  280. && !NoYesMessageBox(IDS_WRN_NO_AUTH)
  281. )
  282. {
  283. //
  284. // Don't dismiss the dialog
  285. //
  286. return;
  287. }
  288. CDialog::OnOK();
  289. }
  290. }