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.

278 lines
7.1 KiB

  1. // File: passdlg.cpp
  2. #include "precomp.h"
  3. #include "resource.h"
  4. #include "PassDlg.h"
  5. #include "help_ids.h"
  6. #define USERSIZE 20
  7. #define DOMAINSIZE 15
  8. #define PASSWDSIZE 256
  9. static const DWORD aHelpIdsPassword[] = {
  10. IDC_EDIT_PASSWORD, IDH_ADV_PASSWORD,
  11. 0, 0 // terminator
  12. };
  13. /****************************************************************************
  14. *
  15. * CLASS: CPasswordDlg
  16. *
  17. * MEMBER: CPasswordDlg()
  18. *
  19. * PURPOSE: Constructor - initializes variables
  20. *
  21. ****************************************************************************/
  22. CPasswordDlg::CPasswordDlg(HWND hwndParent, LPCTSTR pcszConfName, LPCTSTR pCertText, BOOL fIsService):
  23. m_hwndParent(hwndParent),
  24. m_strConfName((LPCTSTR) pcszConfName),
  25. m_hwnd(NULL),
  26. m_fRemoteIsRDS(fIsService),
  27. m_strCert(pCertText)
  28. {
  29. DebugEntry(CPasswordDlg::CPasswordDlg);
  30. DebugExitVOID(CPasswordDlg::CPasswordDlg);
  31. }
  32. /****************************************************************************
  33. *
  34. * CLASS: CPasswordDlg
  35. *
  36. * MEMBER: DoModal()
  37. *
  38. * PURPOSE: Brings up the modal dialog box
  39. *
  40. ****************************************************************************/
  41. INT_PTR CPasswordDlg::DoModal()
  42. {
  43. DebugEntry(CPasswordDlg::DoModal);
  44. INT_PTR nRet = DialogBoxParam( ::GetInstanceHandle(),
  45. m_fRemoteIsRDS ? MAKEINTRESOURCE(IDD_PASSWORD_RDS): MAKEINTRESOURCE(IDD_PASSWORD),
  46. m_hwndParent,
  47. CPasswordDlg::PasswordDlgProc,
  48. (LPARAM) this);
  49. DebugExitINT_PTR(CPasswordDlg::DoModal, nRet);
  50. return nRet;
  51. }
  52. /****************************************************************************
  53. *
  54. * CLASS: CPasswordDlg
  55. *
  56. * MEMBER: PasswordDlgProc()
  57. *
  58. * PURPOSE: Dialog Proc - handles all messages
  59. *
  60. ****************************************************************************/
  61. INT_PTR CALLBACK CPasswordDlg::PasswordDlgProc(HWND hDlg,
  62. UINT uMsg,
  63. WPARAM wParam,
  64. LPARAM lParam)
  65. {
  66. BOOL bMsgHandled = FALSE;
  67. // uMsg may be any value.
  68. // wparam may be any value.
  69. // lparam may be any value.
  70. ASSERT(IS_VALID_HANDLE(hDlg, WND));
  71. switch (uMsg)
  72. {
  73. case WM_INITDIALOG:
  74. {
  75. if (NULL != lParam)
  76. {
  77. ((CPasswordDlg*) lParam)->m_hwnd = hDlg;
  78. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  79. // Set the conference name
  80. if (((CPasswordDlg*) lParam)->m_fRemoteIsRDS)
  81. {
  82. ::SetDlgItemText( hDlg, IDC_EDIT_RDS_CERT, ((CPasswordDlg*) lParam)->m_strCert);
  83. ::SendDlgItemMessage( hDlg, IDC_EDIT_USERNAME, EM_LIMITTEXT, (WPARAM) USERSIZE, 0);
  84. ::SendDlgItemMessage( hDlg, IDC_EDIT_PASSWORD, EM_LIMITTEXT, (WPARAM) PASSWDSIZE, 0);
  85. ::SendDlgItemMessage( hDlg, IDC_EDIT_DOMAIN, EM_LIMITTEXT, (WPARAM) DOMAINSIZE, 0);
  86. ::SetDlgItemText( hDlg, IDC_EDIT_USERNAME, *(m_pstrUser));
  87. ::SetDlgItemText( hDlg, IDC_EDIT_DOMAIN, *(m_pstrDomain));
  88. }
  89. else
  90. {
  91. ::SetDlgItemText( hDlg, IDC_STATIC_CONFNAME, ((CPasswordDlg*) lParam)->m_strConfName);
  92. }
  93. // Bring it to the foreground
  94. ::SetForegroundWindow(hDlg);
  95. }
  96. bMsgHandled = TRUE;
  97. break;
  98. }
  99. default:
  100. {
  101. CPasswordDlg* ppd = (CPasswordDlg*) GetWindowLongPtr( hDlg,
  102. DWLP_USER);
  103. if (NULL != ppd)
  104. {
  105. bMsgHandled = ppd->ProcessMessage(uMsg, wParam, lParam);
  106. }
  107. }
  108. }
  109. return bMsgHandled;
  110. }
  111. /****************************************************************************
  112. *
  113. * CLASS: CPasswordDlg
  114. *
  115. * MEMBER: ProcessMessage()
  116. *
  117. * PURPOSE: processes all messages except WM_INITDIALOG
  118. *
  119. ****************************************************************************/
  120. BOOL CPasswordDlg::ProcessMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  121. {
  122. BOOL bRet = FALSE;
  123. ASSERT(m_hwnd);
  124. switch (uMsg)
  125. {
  126. case WM_COMMAND:
  127. {
  128. switch (LOWORD(wParam))
  129. {
  130. case IDOK:
  131. {
  132. bRet = OnOk();
  133. break;
  134. }
  135. case IDCANCEL:
  136. {
  137. EndDialog(m_hwnd, LOWORD(wParam));
  138. bRet = TRUE;
  139. break;
  140. }
  141. case IDC_EDIT_PASSWORD:
  142. {
  143. if (!m_fRemoteIsRDS && EN_CHANGE == HIWORD(wParam))
  144. {
  145. BOOL fEnable = 0 != ::GetWindowTextLength(
  146. GetDlgItem(m_hwnd, IDC_EDIT_PASSWORD));
  147. ::EnableWindow(GetDlgItem(m_hwnd, IDOK), fEnable);
  148. }
  149. break;
  150. }
  151. case IDC_EDIT_USERNAME:
  152. {
  153. if (EN_CHANGE == HIWORD(wParam))
  154. {
  155. BOOL fEnable = 0 != ::GetWindowTextLength(
  156. GetDlgItem(m_hwnd, IDC_EDIT_USERNAME));
  157. ::EnableWindow(GetDlgItem(m_hwnd, IDOK), fEnable);
  158. }
  159. break;
  160. }
  161. }
  162. break;
  163. }
  164. case WM_CONTEXTMENU:
  165. DoHelpWhatsThis(wParam, aHelpIdsPassword);
  166. break;
  167. case WM_HELP:
  168. DoHelp(lParam, aHelpIdsPassword);
  169. break;
  170. default:
  171. break;
  172. }
  173. return bRet;
  174. }
  175. BOOL CPasswordDlg::OnOk()
  176. {
  177. // BUGBUG: how long can a password be? - Remember to limit the edit control text
  178. TCHAR szBuf[256];
  179. TCHAR szUser[USERSIZE+1];
  180. TCHAR szDomain[DOMAINSIZE+1];
  181. if (m_fRemoteIsRDS)
  182. {
  183. if ( 0!= GetDlgItemText(m_hwnd, IDC_EDIT_USERNAME, szUser, CCHMAX(szUser)))
  184. {
  185. ASSERT(strlen(szUser));
  186. m_strPassword = szUser; // add user name
  187. m_strPassword += ":";
  188. if ( 0 != GetDlgItemText(m_hwnd, IDC_EDIT_DOMAIN, szDomain, CCHMAX(szDomain)))
  189. {
  190. m_strPassword += szDomain;
  191. }
  192. else
  193. {
  194. m_strPassword += ".";
  195. }
  196. m_strPassword += ":";
  197. }
  198. else
  199. {
  200. ERROR_OUT(("CPasswordDlg::OnOk - unable to get username"));
  201. }
  202. *(CPasswordDlg::m_pstrUser) = szUser;
  203. *(CPasswordDlg::m_pstrDomain) = szDomain;
  204. }
  205. if (0 != GetDlgItemText(m_hwnd, IDC_EDIT_PASSWORD, szBuf, CCHMAX(szBuf)))
  206. {
  207. m_strPassword += szBuf; // add password
  208. }
  209. EndDialog(m_hwnd, IDOK);
  210. return TRUE;
  211. }
  212. BOOL CPasswordDlg::Init()
  213. {
  214. if (0 == m_pstrDomain)
  215. {
  216. m_pstrDomain = new CSTRING;
  217. m_pstrUser = new CSTRING;
  218. if (NULL == m_pstrUser || NULL == m_pstrDomain)
  219. {
  220. ERROR_OUT(("CPassword::Init() -- failed to allocate memory"));
  221. return FALSE;
  222. }
  223. }
  224. return TRUE;
  225. }
  226. VOID CPasswordDlg::Cleanup()
  227. {
  228. if (m_pstrDomain)
  229. delete m_pstrDomain;
  230. if (m_pstrUser)
  231. delete m_pstrUser;
  232. }
  233. CSTRING *CPasswordDlg::m_pstrDomain = NULL;
  234. CSTRING *CPasswordDlg::m_pstrUser = NULL;
  235.