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.

213 lines
4.8 KiB

  1. /*****************************************************************************\
  2. * MODULE: pusrdata.hxx
  3. *
  4. * PURPOSE: This specialises the user data class to keep track of data
  5. * useful to a basic connection port.
  6. *
  7. * Copyright (C) 2000 Microsoft Corporation
  8. *
  9. * History:
  10. *
  11. * 1/11/2000 mlawrenc Implemented
  12. *
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #if (defined(WINNT32))
  16. #include "priv.h"
  17. CPortUserData::CPortUserData()
  18. /*++
  19. Constructor:
  20. Default constructor for Port User Information.
  21. --*/
  22. : CUserData(),
  23. m_lpszUserName (NULL),
  24. m_lpszPassword (NULL),
  25. m_bNeverPopup (FALSE) {
  26. if (m_bValid)
  27. m_bValid = _GetLogonSession(m_lastLogonTime);
  28. }
  29. CPortUserData::CPortUserData (
  30. LPTSTR lpszUserName,
  31. LPTSTR lpszPassword,
  32. BOOL bNeverPopup)
  33. /*++
  34. Constructor:
  35. Constructor for the CPortUserData used for dialogue control
  36. Arguments:
  37. lpszUserName - User name that this user has authenticated as on this port.
  38. lpszPassword - Password that the user authenticated under
  39. bNeverPopup - Whether user pushed cancel or not.
  40. --*/
  41. : CUserData(),
  42. m_lpszUserName (NULL),
  43. m_lpszPassword (NULL),
  44. m_bNeverPopup (bNeverPopup) {
  45. if (m_bValid) {
  46. m_bValid = _GetLogonSession (m_lastLogonTime) &&
  47. AssignString (m_lpszUserName, lpszUserName) &&
  48. AssignString (m_lpszPassword, lpszPassword);
  49. }
  50. }
  51. CPortUserData::~CPortUserData()
  52. /*++
  53. Destructor:
  54. Destructor for Port User Data.
  55. --*/
  56. {
  57. LocalFree (m_lpszUserName);
  58. LocalFree (m_lpszPassword);
  59. }
  60. BOOL
  61. CPortUserData::SetPassword (
  62. LPTSTR lpszPassword)
  63. {
  64. if (m_bValid) {
  65. m_bValid = AssignString (m_lpszPassword, lpszPassword);
  66. }
  67. return m_bValid;
  68. }
  69. BOOL
  70. CPortUserData::SetUserName (
  71. LPTSTR lpszUserName)
  72. {
  73. if (m_bValid) {
  74. m_bValid = AssignString (m_lpszUserName, lpszUserName);
  75. }
  76. return m_bValid;
  77. }
  78. BOOL
  79. CPortUserData::SetPopupFlag (
  80. BOOL bNeverPopup)
  81. /*++
  82. Routine Description:
  83. Set the fact that we should not pop up the dialogue box again,
  84. Record the logon time when we made the decision, if the logon time
  85. advances, we will disregard this flag.
  86. Arguments:
  87. bNeverPopup - TRUE if the user pushed Cancel.
  88. Return Value:
  89. TRUE if we could get the logon time.
  90. --*/
  91. {
  92. if (m_bNeverPopup = bNeverPopup) {
  93. m_bValid = _GetLogonSession (m_lastLogonTime);
  94. }
  95. return m_bValid;
  96. }
  97. BOOL
  98. CPortUserData::GetPopupFlag (void)
  99. {
  100. FILETIME LogonTime;
  101. if (m_bNeverPopup) {
  102. if (_GetLogonSession (LogonTime)) {
  103. if (CompareFileTime (&LogonTime, &m_lastLogonTime)) { // New logon session
  104. m_bNeverPopup = FALSE;
  105. }
  106. }
  107. }
  108. return m_bNeverPopup;
  109. }
  110. BOOL
  111. CPortUserData::_GetLogonSession (FILETIME &LogonTime)
  112. {
  113. // Read the registry and check if it is a new logon session
  114. BOOL bRet = FALSE;
  115. HKEY hProvidersKey = NULL;
  116. DWORD dwType = REG_BINARY;
  117. DWORD dwSize = sizeof (FILETIME);
  118. LPTSTR szPrintProviders = g_szRegPrintProviders;
  119. LPTSTR szLogonTime = TEXT ("LogonTime");
  120. HANDLE hToken;
  121. if (hToken = RevertToPrinterSelf()) {
  122. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  123. szPrintProviders,
  124. 0,
  125. KEY_QUERY_VALUE,
  126. &hProvidersKey) &&
  127. ERROR_SUCCESS == RegQueryValueEx (hProvidersKey,
  128. szLogonTime,
  129. 0,
  130. &dwType,
  131. (LPBYTE) &LogonTime,
  132. &dwSize)) {
  133. bRet = TRUE;
  134. RegCloseKey (hProvidersKey);
  135. }
  136. if (!ImpersonatePrinterClient(hToken))
  137. bRet = FALSE;
  138. }
  139. return bRet;
  140. }
  141. CPortUserData &
  142. CPortUserData::operator=(const CPortUserData &rhs) {
  143. LocalFree (m_lpszUserName);
  144. LocalFree (m_lpszPassword);
  145. m_lpszUserName = NULL;
  146. m_lpszPassword = NULL;
  147. m_bNeverPopup = FALSE;
  148. this->CUserData::operator= ( rhs );
  149. if (m_bValid) {
  150. m_bNeverPopup = rhs.m_bNeverPopup;
  151. m_bValid = AssignString (m_lpszUserName, rhs.m_lpszUserName) &&
  152. AssignString (m_lpszPassword, rhs.m_lpszPassword);
  153. }
  154. return *this;
  155. }
  156. #endif // #if (defined(WINNT32))
  157. /*****************************************************************
  158. ** End of File (pusrdata.cxx)
  159. ******************************************************************/