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.

250 lines
8.2 KiB

  1. /**MOD+**********************************************************************/
  2. /* Module: password.cpp */
  3. /* */
  4. /* Class : CMsTscAx */
  5. /* */
  6. /* Purpose: Implements password related interfaces of the control */
  7. /* */
  8. /* Copyright(C) Microsoft Corporation 1999 */
  9. /* */
  10. /* Author : Nadim Abdo (nadima) */
  11. /****************************************************************************/
  12. #include "stdafx.h"
  13. #include "atlwarn.h"
  14. BEGIN_EXTERN_C
  15. #define TRC_GROUP TRC_GROUP_UI
  16. #define TRC_FILE "password"
  17. #include <atrcapi.h>
  18. END_EXTERN_C
  19. //Header generated from IDL
  20. #include "mstsax.h"
  21. #include "mstscax.h"
  22. /**PROC+*********************************************************************/
  23. /* Name: ResetNonPortablePassword */
  24. /* */
  25. /* Purpose: Resets the password/salt. */
  26. /* */
  27. /**PROC-*********************************************************************/
  28. DCVOID CMsTscAx::ResetNonPortablePassword()
  29. {
  30. SecureZeroMemory(m_NonPortablePassword, sizeof(m_NonPortablePassword));
  31. SecureZeroMemory(m_NonPortableSalt, sizeof(m_NonPortableSalt));
  32. SetNonPortablePassFlag(FALSE);
  33. SetNonPortableSaltFlag(FALSE);
  34. }
  35. /**PROC+*********************************************************************/
  36. /* Name: ResetPortablePassword */
  37. /* */
  38. /* Purpose: Resets the password/salt. */
  39. /* */
  40. /**PROC-*********************************************************************/
  41. DCVOID CMsTscAx::ResetPortablePassword()
  42. {
  43. SecureZeroMemory(m_PortablePassword, sizeof(m_PortablePassword));
  44. SecureZeroMemory(m_PortableSalt, sizeof(m_PortableSalt));
  45. SetPortablePassFlag(FALSE);
  46. SetPortableSaltFlag(FALSE);
  47. }
  48. /**PROC+*********************************************************************/
  49. /* Name: put_ClearTextPassword */
  50. /* */
  51. /* Purpose: set password from clear text (stored in non-portable */
  52. /* encrypted form). */
  53. /* */
  54. /**PROC-*********************************************************************/
  55. STDMETHODIMP CMsTscAx::put_ClearTextPassword(BSTR newClearTextPassVal)
  56. {
  57. USES_CONVERSION;
  58. if(!newClearTextPassVal) {
  59. return E_INVALIDARG;
  60. }
  61. //Reset both forms of the password
  62. ResetNonPortablePassword();
  63. ResetPortablePassword();
  64. //Password has to be encrypted in widestring format
  65. LPWSTR wszClearPass = (LPWSTR)(newClearTextPassVal);
  66. UINT cbClearTextPass = lstrlenW(wszClearPass) * sizeof(WCHAR);
  67. ATLASSERT( cbClearTextPass < sizeof(m_NonPortablePassword));
  68. if(cbClearTextPass >= sizeof(m_NonPortablePassword))
  69. {
  70. return E_INVALIDARG;
  71. }
  72. //
  73. // Determine if this is a new longer format password
  74. //
  75. if (cbClearTextPass >= UI_MAX_PASSWORD_LENGTH_OLD/sizeof(WCHAR))
  76. {
  77. m_IsLongPassword = TRUE;
  78. }
  79. else
  80. {
  81. m_IsLongPassword = FALSE;
  82. }
  83. DC_MEMCPY(m_NonPortablePassword, wszClearPass, cbClearTextPass);
  84. if(!TSRNG_GenerateRandomBits( m_NonPortableSalt, sizeof(m_NonPortableSalt)))
  85. {
  86. ATLASSERT(0);
  87. ResetNonPortablePassword();
  88. return E_FAIL;
  89. }
  90. //Encrypt the password
  91. if(!EncryptDecryptLocalData50( m_NonPortablePassword, sizeof(m_NonPortablePassword),
  92. m_NonPortableSalt, sizeof(m_NonPortableSalt)))
  93. {
  94. ATLASSERT(0);
  95. ResetNonPortablePassword();
  96. return E_FAIL;
  97. }
  98. //Mark that the non-portable password has been set
  99. SetNonPortablePassFlag(TRUE);
  100. SetNonPortableSaltFlag(TRUE);
  101. return S_OK;
  102. }
  103. //
  104. // Portable password put/get
  105. //
  106. STDMETHODIMP CMsTscAx::put_PortablePassword(BSTR newPortablePassVal)
  107. {
  108. //
  109. // Deprecated
  110. //
  111. return E_NOTIMPL;
  112. }
  113. STDMETHODIMP CMsTscAx::get_PortablePassword(BSTR* pPortablePass)
  114. {
  115. //
  116. // Deprecated
  117. //
  118. return E_NOTIMPL;
  119. }
  120. //
  121. // Portable salt put/get
  122. //
  123. STDMETHODIMP CMsTscAx::put_PortableSalt(BSTR newPortableSalt)
  124. {
  125. //
  126. // Deprecated
  127. //
  128. return E_NOTIMPL;
  129. }
  130. STDMETHODIMP CMsTscAx::get_PortableSalt(BSTR* pPortableSalt)
  131. {
  132. //
  133. // Deprecated
  134. //
  135. return E_NOTIMPL;
  136. }
  137. //
  138. // Non-portable (binary) password put_get
  139. //
  140. STDMETHODIMP CMsTscAx::put_BinaryPassword(BSTR newPassword)
  141. {
  142. //
  143. // Deprecated
  144. //
  145. return E_NOTIMPL;
  146. }
  147. STDMETHODIMP CMsTscAx::get_BinaryPassword(BSTR* pPass)
  148. {
  149. //
  150. // Deprecated
  151. //
  152. return E_NOTIMPL;
  153. }
  154. //
  155. // Non-portable salt (binary) password put_get
  156. //
  157. STDMETHODIMP CMsTscAx::put_BinarySalt(BSTR newSalt)
  158. {
  159. //
  160. // Deprecated
  161. //
  162. return E_NOTIMPL;
  163. }
  164. STDMETHODIMP CMsTscAx::get_BinarySalt(BSTR* pSalt)
  165. {
  166. //
  167. // Deprecated
  168. //
  169. return E_NOTIMPL;
  170. }
  171. /**PROC+*********************************************************************/
  172. /* Name: ConvertNonPortableToPortablePass */
  173. /* */
  174. /* Purpose: Takes the non portable pass/salt pair...generates a new salt */
  175. /* and re-encrypts and stores as portable */
  176. /* */
  177. /* */
  178. /**PROC-*********************************************************************/
  179. DCBOOL CMsTscAx::ConvertNonPortableToPortablePass()
  180. {
  181. //
  182. // Deprecated
  183. //
  184. return E_NOTIMPL;
  185. }
  186. /**PROC+*********************************************************************/
  187. /* Name: ConvertPortableToNonPortablePass */
  188. /* */
  189. /* Purpose: Takes the portable pass/salt pair...generates a new salt */
  190. /* and re-encrypts and stores as non-portable */
  191. /* */
  192. /* */
  193. /**PROC-*********************************************************************/
  194. DCBOOL CMsTscAx::ConvertPortableToNonPortablePass()
  195. {
  196. //
  197. // Deprecated
  198. //
  199. return E_NOTIMPL;
  200. }
  201. /**PROC+*********************************************************************/
  202. /* Name: ResetPassword */
  203. /* */
  204. /* Purpose: Method to reset passwords */
  205. /* */
  206. /* */
  207. /* */
  208. /**PROC-*********************************************************************/
  209. STDMETHODIMP CMsTscAx::ResetPassword()
  210. {
  211. //Reset both portable and non-portable passwords
  212. //need to have this method because setting a password to ""
  213. //might be a valid password so we can't interpret that as a reset
  214. ResetNonPortablePassword();
  215. ResetPortablePassword();
  216. return S_OK;
  217. }