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.

128 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1994-2002 Microsoft Corporation
  3. Module Name :
  4. strpass.h
  5. Abstract:
  6. Message Functions Definitions
  7. Author:
  8. Aaron Lee (aaronl)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. #ifndef _STRPASS_H_
  14. #define _STRPASS_H_
  15. // ----------------------------------------
  16. // This class was created to allow a class to
  17. // keep passwords in it's member variables.
  18. //
  19. // In the event that the process get's paged out to
  20. // the swapfile, any user will be able to read the
  21. // swapfile. if the member variables contained
  22. // passwords, they wil be there in clear text.
  23. //
  24. // Usage1 -- with LPTSTR:
  25. // CStrPassword m_strPassword;
  26. // // assign a password into member variable
  27. // m_strPassword = _T("MyPassword");
  28. // // get a password out
  29. // LPTSTR lpPassword = m_strPassword.GetClearTextPassword();
  30. // // use it...
  31. // FunctionToUsePassword(lpPassword);
  32. // // erase it -- this will erase memory where cleartext password was stored
  33. // m_strPassword.DestroyClearTextPassword();
  34. //
  35. // Usage2 -- with CString:
  36. // CStrPassword m_strPassword(_T("MyPassword"));
  37. // // get a password out into CString
  38. // CString csPassword;
  39. // m_strPassword.CopyTo(csPassword);
  40. // // use it...
  41. // FunctionToUsePassword(csPassword);
  42. // // erase it by overwritting
  43. // csPassword = _T(" ");
  44. // csPassword.Empty();
  45. //
  46. // DO NOT DO THIS -- this will allocate a cleartext password and it will never be Freed!
  47. // FunctionToUsePassword( (LPTSTR) m_strPassword.GetClearTextPassword());
  48. //
  49. // ----------------------------------------
  50. #ifdef _COMEXPORT
  51. class COMDLL CStrPassword
  52. #elif defined(_DLLEXP)
  53. class _EXPORT CStrPassword
  54. #else
  55. class CStrPassword
  56. #endif
  57. {
  58. public:
  59. // constructor/destructor
  60. CStrPassword();
  61. ~CStrPassword();
  62. // copy constructors
  63. CStrPassword(LPTSTR lpsz);
  64. CStrPassword(LPCTSTR lpsz);
  65. CStrPassword(CStrPassword& csPassword);
  66. // get character count
  67. int GetLength() const;
  68. // get byte count
  69. int GetByteLength() const;
  70. // TRUE if zero length
  71. BOOL IsEmpty() const;
  72. // clear contents to empty
  73. void Empty();
  74. // straight character comparison
  75. int Compare(LPCTSTR lpsz) const;
  76. int Compare(CString& lpsz) const;
  77. int Compare(CStrPassword& lpsz) const;
  78. // copy string content from UNICODE string (converts to TCHAR)
  79. const CStrPassword& operator=(LPCTSTR lpsz);
  80. const CStrPassword& operator=(CStrPassword& lpStrPass);
  81. // copy to...
  82. void CopyTo(CString& stringSrc);
  83. void CopyTo(CStrPassword& stringSrc);
  84. // Get Data out from it (unencrypted)
  85. // Each call to GetClearTextPassword() should have an equal
  86. // DestroyClearTextPassword() call to it.
  87. LPTSTR GetClearTextPassword();
  88. void DestroyClearTextPassword(LPTSTR lpClearTextPassword) const;
  89. // not implemented
  90. operator TCHAR*();
  91. // returns CString
  92. operator CString();
  93. bool operator== (CStrPassword& csCompareToMe);
  94. bool operator!= (CStrPassword& csCompareToMe)
  95. {
  96. return !(operator==(csCompareToMe));
  97. }
  98. private:
  99. void ClearPasswordBuffers(void);
  100. protected:
  101. LPTSTR m_pszDataEncrypted;
  102. DWORD m_cbDataEncrypted;
  103. };
  104. #endif