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.

135 lines
2.8 KiB

  1. /*****************************************************************************\
  2. * MODULE: lusrdata.cxx
  3. *
  4. * PURPOSE: This specialises the user data class to keep track of data
  5. * useful for the user port reference count.
  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. CLogonUserData::CLogonUserData()
  18. /*++
  19. Routine Description:
  20. Default constructor for Logon User Data, once the parent
  21. gets the SID, we get the session ID.
  22. --*/
  23. : CUserData() ,
  24. m_ulSessionId(0),
  25. m_dwRefCount(1) {
  26. if (m_bValid) { // We get the user SID successfully
  27. m_bValid = _GetClientSessionId( );
  28. }
  29. }
  30. BOOL
  31. CLogonUserData::_GetClientSessionId(
  32. VOID )
  33. /*++
  34. Routine Description:
  35. Set the session ID from the client token and set it if we can get it.
  36. Return Value:
  37. TRUE if we could get the session ID, false otherwise.
  38. --*/
  39. {
  40. BOOL bResult;
  41. HANDLE hToken;
  42. ULONG ulSessionId, ulReturnLength;
  43. //
  44. // We should be impersonating the client, so we will get the
  45. // SessionId from our token.
  46. //
  47. bResult = OpenThreadToken(
  48. GetCurrentThread(),
  49. TOKEN_QUERY,
  50. FALSE, // Use impersonation
  51. &hToken
  52. );
  53. if( bResult ) {
  54. //
  55. // Query the SessionID from the token added by HYDRA
  56. //
  57. bResult = GetTokenInformation(
  58. hToken,
  59. (TOKEN_INFORMATION_CLASS)TokenSessionId,
  60. &m_ulSessionId,
  61. sizeof(m_ulSessionId),
  62. &ulReturnLength
  63. );
  64. m_ulSessionId = bResult ? m_ulSessionId : 0;
  65. CloseHandle( hToken );
  66. bResult = TRUE;
  67. }
  68. return bResult;
  69. }
  70. CLogonUserData &
  71. CLogonUserData::operator=(
  72. const CLogonUserData &rhs) {
  73. this->CUserData::operator=( rhs );
  74. m_ulSessionId = rhs.m_ulSessionId;
  75. return *this;
  76. }
  77. int
  78. CLogonUserData::Compare(
  79. const CLogonUserData *second) const
  80. /*++
  81. Routine Description:
  82. Compare the CLogonUser with another.
  83. Arguments:
  84. second - The CLogonUser we are comparing this with.
  85. Return Value:
  86. TRUE if they are different, FALSE if they are the same.
  87. --*/
  88. {
  89. if (m_bValid && second->m_bValid) {
  90. return m_ulSessionId != second->m_ulSessionId ||
  91. RtlEqualSid(m_pSid, second->m_pSid) == FALSE;
  92. } else {
  93. return TRUE;
  94. }
  95. }
  96. #endif // #if (defined(WINNT32))
  97. /****************************************************************
  98. ** End of File (lusrdata.cxx)
  99. ****************************************************************/