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.

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