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.

209 lines
6.4 KiB

  1. // ILoginTask.cpp -- Interactive Login Task helper 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. #if defined(_UNICODE)
  8. #if !defined(UNICODE)
  9. #define UNICODE
  10. #endif //!UNICODE
  11. #endif //_UNICODE
  12. #if defined(UNICODE)
  13. #if !defined(_UNICODE)
  14. #define _UNICODE
  15. #endif //!_UNICODE
  16. #endif //UNICODE
  17. #include "stdafx.h"
  18. #include <scuOsExc.h>
  19. #include <iopPriBlob.h>
  20. #include "PromptUser.h"
  21. #include "PswdDlg.h"
  22. #include "ILoginTask.h"
  23. #include "Blob.h"
  24. using namespace std;
  25. using namespace scu;
  26. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  27. /////////////////////////// PUBLIC /////////////////////////////////
  28. // Types
  29. // C'tors/D'tors
  30. InteractiveLoginTask::InteractiveLoginTask(HWND const &rhwnd)
  31. : m_hwnd(rhwnd)
  32. {}
  33. InteractiveLoginTask::~InteractiveLoginTask()
  34. {}
  35. // Operators
  36. // Operations
  37. // Access
  38. // Predicates
  39. // Static Variables
  40. /////////////////////////// PROTECTED /////////////////////////////////
  41. // C'tors/D'tors
  42. // Operators
  43. // Operations
  44. void
  45. InteractiveLoginTask::GetNewPin(Capsule &rcapsule)
  46. {
  47. CChangePINDlg ChgPinDlg(CWnd::FromHandle(m_hwnd));
  48. #ifdef ISOLATION_AWARE_ENABLED
  49. CThemeContextActivator activator;
  50. #endif
  51. DWORD dwStatus = ChgPinDlg.InitDlg();
  52. if (ERROR_SUCCESS != dwStatus)
  53. throw scu::OsException(dwStatus);
  54. SecureArray<BYTE> saBuffer(rcapsule.m_rat.Pin());
  55. saBuffer.append(1,0);
  56. ChgPinDlg.m_csOldPIN = saBuffer.data();
  57. INT_PTR ipResult = ChgPinDlg.DoModal();
  58. AfxGetApp()->DoWaitCursor(0);
  59. switch (ipResult)
  60. {
  61. case IDCANCEL:
  62. throw scu::OsException(ERROR_CANCELLED);
  63. break;
  64. case IDABORT:
  65. throw scu::OsException(NTE_FAIL);
  66. break;
  67. case -1:
  68. throw scu::OsException(ERROR_NOT_ENOUGH_MEMORY);
  69. break;
  70. default:
  71. ; // fall through
  72. };
  73. SecureArray<char> sTemp(StringResource::CheckAsciiFromUnicode((LPCTSTR)ChgPinDlg.m_csNewPIN));
  74. rcapsule.m_rat.Pin(sTemp.data());
  75. }
  76. void
  77. InteractiveLoginTask::GetPin(Capsule &rcapsule)
  78. {
  79. if (!rcapsule.m_rat.PinIsCached())
  80. {
  81. CPasswordDlg PswdDlg(CWnd::FromHandle(m_hwnd));
  82. #ifdef ISOLATION_AWARE_ENABLED
  83. CThemeContextActivator activator;
  84. #endif
  85. DWORD dwStatus = PswdDlg.InitDlg();
  86. if (ERROR_SUCCESS != dwStatus)
  87. throw scu::OsException(dwStatus);
  88. // Tell the password dialog the login ID, so it will
  89. // enable the controls and prompt appropriately.
  90. PswdDlg.m_lid = rcapsule.m_rat.Identity();
  91. INT_PTR ipResult = PswdDlg.DoModal();
  92. AfxGetApp()->DoWaitCursor(0);
  93. switch (ipResult)
  94. {
  95. case IDCANCEL:
  96. throw scu::OsException(ERROR_CANCELLED);
  97. break;
  98. case IDABORT:
  99. throw scu::OsException(NTE_FAIL);
  100. break;
  101. case -1:
  102. throw scu::OsException(ERROR_NOT_ENOUGH_MEMORY);
  103. break;
  104. default:
  105. ; // fall through
  106. };
  107. SecureArray<char> sPin(StringResource::CheckAsciiFromUnicode((LPCTSTR)PswdDlg.m_szPassword));
  108. rcapsule.m_rat.Pin(sPin.data(), 0 != PswdDlg.m_fHexCode);
  109. RequestedToChangePin(0 != PswdDlg.m_bChangePIN);
  110. }
  111. }
  112. void
  113. InteractiveLoginTask::OnChangePinError(Capsule &rcapsule)
  114. {
  115. int iResponse = PromptUser(m_hwnd, IDS_PIN_CHANGE_FAILED,
  116. MB_RETRYCANCEL | MB_ICONSTOP);
  117. if (IDCANCEL == iResponse)
  118. throw scu::OsException(ERROR_CANCELLED);
  119. }
  120. void
  121. InteractiveLoginTask::OnSetPinError(Capsule &rcapsule)
  122. {
  123. scu::Exception const *exc = rcapsule.Exception();
  124. if (scu::Exception::fcSmartCard == exc->Facility())
  125. {
  126. iop::CSmartCard::Exception const &rScExc =
  127. *(static_cast<iop::CSmartCard::Exception const *>(exc));
  128. iop::CSmartCard::CauseCode cc = rScExc.Cause();
  129. if ((iop::CSmartCard::ccChvVerificationFailedMoreAttempts == cc) ||
  130. (iop::CSmartCard::ccKeyBlocked == cc))
  131. {
  132. bool fBadPin =
  133. (iop::CSmartCard::ccChvVerificationFailedMoreAttempts == cc);
  134. UINT uiId;
  135. UINT uiButtons;
  136. if (fBadPin)
  137. {
  138. uiId = IDS_BAD_PIN_ENTERED;
  139. uiButtons = MB_RETRYCANCEL;
  140. }
  141. else
  142. {
  143. uiId = IDS_PIN_BLOCKED;
  144. uiButtons = MB_OK;
  145. }
  146. int iResponse = PromptUser(m_hwnd, uiId,
  147. uiButtons | MB_ICONSTOP);
  148. if (fBadPin)
  149. {
  150. if (IDCANCEL == iResponse)
  151. throw scu::OsException(ERROR_CANCELLED);
  152. else
  153. rcapsule.m_rat.FlushPin();
  154. }
  155. else
  156. throw rScExc;
  157. }
  158. }
  159. else
  160. rcapsule.PropagateException();
  161. }
  162. // Access
  163. // Predicates
  164. // Static Variables
  165. /////////////////////////// PRIVATE /////////////////////////////////
  166. // C'tors/D'tors
  167. // Operators
  168. // Operations
  169. // Access
  170. // Predicates
  171. // Static Variables