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.

503 lines
13 KiB

  1. // PswdDlg.cpp -- PaSsWorD DiaLoG class definition
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. //
  8. #if defined(_UNICODE)
  9. #if !defined(UNICODE)
  10. #define UNICODE
  11. #endif //!UNICODE
  12. #endif //_UNICODE
  13. #if defined(UNICODE)
  14. #if !defined(_UNICODE)
  15. #define _UNICODE
  16. #endif //!_UNICODE
  17. #endif //UNICODE
  18. #include "stdafx.h"
  19. #include <scuOsExc.h>
  20. #include "slbCsp.h"
  21. #include "LoginId.h"
  22. #include "AccessTok.h"
  23. #include "PswdDlg.h"
  24. #include "PromptUser.h"
  25. #include "StResource.h"
  26. #include "CspProfile.h"
  27. using namespace ProviderProfile;
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. BEGIN_MESSAGE_MAP(CLogoDialog, CDialog)
  34. //{{AFX_MSG_MAP(CLogoDialog)
  35. ON_WM_PAINT()
  36. ON_WM_DESTROY()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CLogoDialog dialog
  41. CLogoDialog::CLogoDialog(CWnd* pParent /*=NULL*/)
  42. : CDialog(),
  43. m_dcMem(),
  44. m_dcMask(),
  45. m_bmpLogo(),
  46. m_bmpMask(),
  47. m_hBmpOld(),
  48. m_hBmpOldM(),
  49. m_pt(0,0),
  50. m_size()
  51. {
  52. m_pParent = pParent;
  53. }
  54. ////////////////////////////////////////////////////////////////////////////
  55. // CLogoDialog message handlers
  56. BOOL CLogoDialog::OnInitDialog()
  57. {
  58. CBitmap * pBmpOld, * pBmpOldM;
  59. HINSTANCE oldHandle = NULL;
  60. BOOL fSuccess = TRUE;
  61. try {
  62. CDialog::OnInitDialog();
  63. // Load bitmap resource - remember to call DeleteObject when done.
  64. oldHandle = AfxGetResourceHandle();
  65. AfxSetResourceHandle(CspProfile::Instance().Resources());
  66. m_bmpLogo.LoadBitmap( MAKEINTRESOURCE( IDB_BITMAP_SLBLOGO ) );
  67. m_bmpMask.LoadBitmap( MAKEINTRESOURCE( IDB_BITMAP_SLBLOGO ) );
  68. // Get bitmap information
  69. m_bmpLogo.GetObject( sizeof(BITMAP), &m_bmInfo );
  70. m_size.cx = m_bmInfo.bmWidth;
  71. m_size.cy = m_bmInfo.bmHeight;
  72. // Get temporary DC for dialog - Will be released in dc destructor
  73. CClientDC dc(this);
  74. // Create compatible memory DC using the dialogs DC
  75. m_dcMem.CreateCompatibleDC( &dc );
  76. m_dcMask.CreateCompatibleDC( &dc );
  77. // Select logo bitmap into DC.
  78. // Get pointer to original bitmap
  79. // NOTE! This is temporary - save the handle instead
  80. pBmpOld = m_dcMem.SelectObject( &m_bmpLogo );
  81. SetBkColor(m_dcMem, RGB(255, 255, 255));
  82. m_dcMask.BitBlt (0, 0, m_size.cx, m_size.cy, &m_dcMem, 0, 0, SRCCOPY);
  83. pBmpOldM = m_dcMask.SelectObject( &m_bmpMask );
  84. m_hBmpOld = (HBITMAP) pBmpOld->GetSafeHandle();
  85. m_hBmpOldM = (HBITMAP) pBmpOldM->GetSafeHandle();
  86. }
  87. catch (...)
  88. {
  89. fSuccess = FALSE;
  90. }
  91. if (oldHandle)
  92. AfxSetResourceHandle(oldHandle);
  93. return fSuccess;
  94. }
  95. //***********************************************************************
  96. // CLogoDialog::OnPaint()
  97. //
  98. // Purpose:
  99. //
  100. // BitBlt() bitmap stored in compatible memory DC into dialogs
  101. // DC to display at hardcoded location.
  102. //
  103. // Parameters:
  104. //
  105. // None.
  106. //
  107. // Returns:
  108. //
  109. // None.
  110. //
  111. // Comments:
  112. //
  113. // History:
  114. //
  115. //***********************************************************************
  116. void CLogoDialog::OnPaint()
  117. {
  118. CPaintDC dc(this); // device context for painting
  119. // BitBlt logo bitmap onto dialog using transparancy masking
  120. dc.SetBkColor(RGB(255, 255, 255)); // 1s --> 0xFFFFFF
  121. dc.SetTextColor(RGB(0, 0, 0)); // 0s --> 0x000000
  122. // Do the real work.
  123. dc.BitBlt(m_pt.x, m_pt.y, m_size.cx, m_size.cy, &m_dcMem, 0, 0, SRCINVERT);
  124. dc.BitBlt(m_pt.x, m_pt.y, m_size.cx, m_size.cy, &m_dcMask, 0, 0, SRCAND);
  125. dc.BitBlt(m_pt.x, m_pt.y, m_size.cx, m_size.cy, &m_dcMem, 0, 0, SRCINVERT);
  126. /*
  127. * First two parameters are upper left position to place bitmap.
  128. * Third and fourth parameters are width and height to copy
  129. * (could be less than actual size of bitmap)
  130. * Sixth and seventh are position in memory dc to start from
  131. * SRCCOPY specifies copy.
  132. * See BitBlt documentation for more details.
  133. */
  134. // Do not call CDialog::OnPaint() for painting messages
  135. }
  136. //***********************************************************************
  137. // CLogoDialog::OnDestroy()
  138. //
  139. // Purpose:
  140. //
  141. // Select old bitmap back into memory DC before it is destroyed
  142. // when CLogoDialog object is.
  143. // DeleteObject() the bitmap which had been loaded.
  144. //
  145. // Parameters:
  146. //
  147. // None.
  148. //
  149. // Returns:
  150. //
  151. // None.
  152. //
  153. // Comments:
  154. //
  155. // History:
  156. //
  157. //
  158. void CLogoDialog::OnDestroy()
  159. {
  160. CDialog::OnDestroy();
  161. // Select old bitmap into memory dc (selecting out logo bitmap)
  162. // Need to create a temporary pointer to pass to do this
  163. if (m_hBmpOld && m_dcMem)
  164. m_dcMem.SelectObject(CBitmap::FromHandle(m_hBmpOld));
  165. if (m_hBmpOldM && m_dcMem)
  166. m_dcMask.SelectObject(CBitmap::FromHandle(m_hBmpOldM));
  167. // Need to DeleteObject() the bitmap that was loaded
  168. m_bmpLogo.DeleteObject();
  169. m_bmpMask.DeleteObject();
  170. // m_dcMem and m_dcMask destructor will handle rest of cleanup
  171. }
  172. /////////////////////////////////////////////////////////////////////////////
  173. // CPasswordDlg dialog
  174. CPasswordDlg::CPasswordDlg(CWnd* pParent /*=NULL*/)
  175. : CLogoDialog(pParent),
  176. m_szPassword(_T("")),
  177. m_szMessage(_T("")),
  178. m_fHexCode(FALSE),
  179. m_bChangePIN(FALSE),
  180. m_lid(User), // the default
  181. m_nPasswordSizeLimit(AccessToken::MaxPinLength)
  182. {
  183. m_pParent = pParent;
  184. m_pt.x = 144;
  185. m_pt.y = 88;
  186. }
  187. BEGIN_MESSAGE_MAP(CPasswordDlg, CLogoDialog)
  188. //{{AFX_MSG_MAP(CPasswordDlg)
  189. ON_BN_CLICKED(IDC_HEXCODE, OnClickHexCode)
  190. ON_BN_CLICKED(IDC_CHANGEPIN, OnChangePINAfterLogin)
  191. ON_WM_SHOWWINDOW()
  192. //}}AFX_MSG_MAP
  193. END_MESSAGE_MAP()
  194. void CPasswordDlg::DoDataExchange(CDataExchange* pDX)
  195. {
  196. CLogoDialog::DoDataExchange(pDX);
  197. //{{AFX_DATA_MAP(CPasswordDlg)
  198. DDX_Control(pDX, IDC_HEXCODE, m_ctlCheckHexCode);
  199. DDX_Control(pDX, IDC_CHANGEPIN, m_ctlCheckChangePIN);
  200. // DDX_Control(pDX, IDC_EDIT_VERNEWPIN, m_ctlVerifyNewPIN);
  201. // DDX_Control(pDX, IDC_EDIT_NEWPIN, m_ctlNewPIN);
  202. // DDX_Control(pDX, IDC_STATIC_VERNEWPIN, m_ctlVerifyPINLabel);
  203. // DDX_Control(pDX, IDC_STATIC_NEWPIN, m_ctlNewPINLabel);
  204. DDX_Text(pDX, IDC_PASSWORD, m_szPassword);
  205. DDV_MaxChars(pDX, m_szPassword, m_nPasswordSizeLimit);
  206. LPCTSTR pBuffer = (LPCTSTR) m_szMessage;
  207. if(!m_szMessage.IsEmpty())
  208. {
  209. DDX_Text(pDX, IDC_MESSAGE, (LPTSTR)pBuffer, m_szMessage.GetLength());
  210. }
  211. DDX_Check(pDX, IDC_CHANGEPIN, m_bChangePIN);
  212. // DDX_Text(pDX, IDC_EDIT_NEWPIN, m_csNewPIN);
  213. // DDX_Text(pDX, IDC_EDIT_VERNEWPIN, m_csVerifyNewPIN);
  214. //}}AFX_DATA_MAP
  215. }
  216. /////////////////////////////////////////////////////////////////////////////
  217. // CPasswordDlg message handlers
  218. BOOL CPasswordDlg::OnInitDialog()
  219. {
  220. CLogoDialog::OnInitDialog();
  221. switch (m_lid)
  222. {
  223. case User:
  224. // Give the user a chance to change the PIN
  225. m_ctlCheckChangePIN.ShowWindow(SW_SHOW);
  226. {
  227. m_szMessage = StringResource(IDS_ENTER_PIN).AsCString();
  228. }
  229. break;
  230. case Manufacturer:
  231. // Allow Hex string entry
  232. m_ctlCheckHexCode.ShowWindow(SW_SHOW);
  233. {
  234. m_szMessage = StringResource(IDS_ENTER_MANUFACTURER_KEY).AsCString();
  235. }
  236. break;
  237. case Administrator:
  238. // Allow Hex string entry
  239. m_ctlCheckHexCode.ShowWindow(SW_SHOW);
  240. {
  241. m_szMessage = StringResource(IDS_ENTER_ADMIN_KEY).AsCString();
  242. }
  243. break;
  244. default:
  245. break;
  246. };
  247. // Update GUI with changes
  248. UpdateData(FALSE);
  249. SetForegroundWindow();
  250. return TRUE; // return TRUE unless you set the focus to a control
  251. // EXCEPTION: OCX Property Pages should return FALSE
  252. }
  253. void CPasswordDlg::OnClickHexCode()
  254. {
  255. m_fHexCode = ~m_fHexCode;
  256. m_nPasswordSizeLimit = (m_fHexCode)
  257. ? AccessToken::MaxPinLength * 2
  258. : AccessToken::MaxPinLength;
  259. UpdateData(FALSE);
  260. }
  261. void CPasswordDlg::OnOK()
  262. {
  263. UpdateData();
  264. CString msg;
  265. bool fPrompt = true;
  266. if (m_fHexCode && m_szPassword.GetLength() != m_nPasswordSizeLimit)
  267. {
  268. msg.Format((LPCTSTR)StringResource(IDS_PIN_NOT_CONFORM).AsCString(),
  269. m_nPasswordSizeLimit);
  270. }
  271. else if ((User == m_lid) && (0 == m_szPassword.GetLength()))
  272. {
  273. msg = (LPCTSTR)StringResource(IDS_PIN_NOT_CONFORM).AsCString();
  274. }
  275. else
  276. fPrompt = false;
  277. if (fPrompt)
  278. {
  279. HWND hWnd = m_pParent
  280. ? m_pParent->m_hWnd
  281. : NULL;
  282. int iResponse = PromptUser(hWnd, msg,
  283. MB_OK | MB_ICONERROR);
  284. if (IDCANCEL == iResponse)
  285. throw scu::OsException(ERROR_CANCELLED);
  286. }
  287. else
  288. CLogoDialog::OnOK();
  289. }
  290. void CPasswordDlg::OnChangePINAfterLogin()
  291. {
  292. UpdateData(); // set m_bChangePIN
  293. int nShowWindow = (m_bChangePIN) ? SW_SHOW : SW_HIDE;
  294. /*
  295. m_ctlVerifyNewPIN.ShowWindow(nShowWindow);
  296. m_ctlNewPIN.ShowWindow(nShowWindow);
  297. m_ctlVerifyPINLabel.ShowWindow(nShowWindow);
  298. m_ctlNewPINLabel.ShowWindow(nShowWindow);
  299. */
  300. }
  301. void CPasswordDlg::OnShowWindow(BOOL bShow, UINT nStatus)
  302. {
  303. CLogoDialog::OnShowWindow(bShow, nStatus);
  304. }
  305. /////////////////////////////////////////////////////////////////////////////
  306. // CChangePINDlg dialog
  307. CChangePINDlg::CChangePINDlg(CWnd* pParent /*=NULL*/)
  308. : CLogoDialog(pParent),
  309. m_csOldPIN(_T("")),
  310. m_csNewPIN(_T("")),
  311. m_csVerifyNewPIN(_T(""))
  312. {
  313. m_pParent = pParent;
  314. m_pt.x = 144; // 132;
  315. m_pt.y = 75; //104;
  316. }
  317. void CChangePINDlg::DoDataExchange(CDataExchange* pDX)
  318. {
  319. CLogoDialog::DoDataExchange(pDX);
  320. //{{AFX_DATA_MAP(CChangePINDlg)
  321. DDX_Control(pDX, IDC_STATIC_CONFIRM_OLDPIN_LABEL, m_ctlConfirmOldPINLabel);
  322. DDX_Control(pDX, IDC_EDIT_OLDPIN, m_ctlOldPIN);
  323. DDX_Text(pDX, IDC_EDIT_OLDPIN, m_csOldPIN);
  324. DDV_MaxChars(pDX, m_csOldPIN, AccessToken::MaxPinLength);
  325. DDX_Text(pDX, IDC_EDIT_NEWPIN, m_csNewPIN);
  326. DDV_MaxChars(pDX, m_csNewPIN, AccessToken::MaxPinLength);
  327. DDX_Text(pDX, IDC_EDIT_VERNEWPIN, m_csVerifyNewPIN);
  328. DDV_MaxChars(pDX, m_csVerifyNewPIN, AccessToken::MaxPinLength);
  329. //}}AFX_DATA_MAP
  330. }
  331. BEGIN_MESSAGE_MAP(CChangePINDlg, CLogoDialog)
  332. //{{AFX_MSG_MAP(CChangePINDlg)
  333. ON_WM_SHOWWINDOW()
  334. //}}AFX_MSG_MAP
  335. END_MESSAGE_MAP()
  336. /////////////////////////////////////////////////////////////////////////////
  337. // CChangePINDlg message handlers
  338. // The purpose of the Change PIN dialog is for changing User Pins.
  339. // It may be invoked after having already authenticated, or prior
  340. // to authentication. In the former case it is recommended that the
  341. // caller will have set the m_csOldPIN data member prior to calling
  342. // DoModal(). This is so the user will not have to reenter a PIN
  343. // that has previously been entered.
  344. BOOL CChangePINDlg::OnInitDialog()
  345. {
  346. CLogoDialog::OnInitDialog();
  347. SetForegroundWindow();
  348. return TRUE; // return TRUE unless you set the focus to a control
  349. // EXCEPTION: OCX Property Pages should return FALSE
  350. }
  351. void CChangePINDlg::OnOK()
  352. {
  353. UpdateData();
  354. UINT uiMsgId;
  355. bool fMsgIdSet = false;
  356. // Verify that the New PIN contains only ASCII characters
  357. if(!StringResource::IsASCII((LPCTSTR)m_csNewPIN))
  358. {
  359. uiMsgId = IDS_PIN_NOT_CONFORM;
  360. fMsgIdSet = true;
  361. }
  362. // Verify that the New PIN and Verify PIN are the same
  363. else if (m_csNewPIN != m_csVerifyNewPIN)
  364. {
  365. uiMsgId = IDS_PIN_VER_NO_MATCH;
  366. fMsgIdSet = true;
  367. }
  368. // Verify that the length of the new PIN is >= 1
  369. else if (0 == m_csNewPIN.GetLength())
  370. {
  371. uiMsgId = IDS_PIN_NOT_CONFORM;
  372. fMsgIdSet = true;
  373. }
  374. // Verify that the length of the old PIN is >= 1
  375. else if (0 == m_csOldPIN.GetLength())
  376. {
  377. uiMsgId = IDS_PIN_NOT_CONFORM;
  378. fMsgIdSet = true;
  379. }
  380. if (fMsgIdSet)
  381. {
  382. HWND hWnd = m_pParent
  383. ? m_pParent->m_hWnd
  384. : NULL;
  385. int iResponse = PromptUser(hWnd, uiMsgId,
  386. MB_OK | MB_ICONSTOP);
  387. if (IDCANCEL == iResponse)
  388. throw scu::OsException(ERROR_CANCELLED);
  389. }
  390. else
  391. CLogoDialog::OnOK();
  392. }
  393. void CChangePINDlg::OnShowWindow(BOOL bShow, UINT nStatus)
  394. {
  395. CLogoDialog::OnShowWindow(bShow, nStatus);
  396. // if the caller placed something in the m_csOldPIN
  397. // prior to DoModal'ing, then don't show that control,
  398. // so that the user won't accidentally erase the preset,
  399. // current PIN
  400. if (m_csOldPIN.GetLength())
  401. {
  402. m_ctlOldPIN.ShowWindow(FALSE);
  403. m_ctlConfirmOldPINLabel.ShowWindow(FALSE);
  404. }
  405. }