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.

167 lines
3.2 KiB

  1. /************************************************************************
  2. Copyright (c) 2000 - 2000 Microsoft Corporation
  3. Module Name :
  4. logontable.h
  5. Abstract :
  6. Header file for the logon table
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. #pragma once
  11. #include <wtypes.h>
  12. #include <unknwn.h>
  13. #include <utility>
  14. #include <set>
  15. #include <map>
  16. #include "tasksched.h"
  17. class CUser
  18. {
  19. public:
  20. CUser( HANDLE Token );
  21. ~CUser();
  22. long IncrementRefCount();
  23. long DecrementRefCount();
  24. void SetCookie( DWORD cookie )
  25. {
  26. _Cookie = cookie;
  27. }
  28. DWORD GetCookie()
  29. {
  30. return _Cookie;
  31. }
  32. DWORD CopyToken( HANDLE * pToken )
  33. {
  34. if (!DuplicateHandle( GetCurrentProcess(),
  35. _Token,
  36. GetCurrentProcess(),
  37. pToken,
  38. TOKEN_ALL_ACCESS,
  39. FALSE, // no inheritance
  40. 0 // no extra options
  41. ))
  42. {
  43. return GetLastError();
  44. }
  45. return 0;
  46. }
  47. HRESULT Impersonate()
  48. {
  49. if (!ImpersonateLoggedOnUser(_Token))
  50. {
  51. return HRESULT_FROM_WIN32( GetLastError() );
  52. }
  53. return S_OK;
  54. }
  55. SidHandle & QuerySid()
  56. {
  57. return _Sid;
  58. }
  59. void Dump();
  60. HRESULT
  61. LaunchProcess(
  62. StringHandle Program,
  63. StringHandle Parameters
  64. );
  65. private:
  66. long _ReferenceCount;
  67. HANDLE _Token;
  68. SidHandle _Sid;
  69. DWORD _Cookie;
  70. //--------------------------------------------------------------------
  71. };
  72. class CLoggedOnUsers
  73. {
  74. class CSessionList : public std::map<DWORD, CUser *>
  75. {
  76. public:
  77. void Dump();
  78. };
  79. class CUserList : public std::multimap<SidHandle, CUser *, CSidSorter>
  80. {
  81. public:
  82. ~CUserList();
  83. CUser *
  84. RemoveByCookie(
  85. SidHandle sid,
  86. DWORD cookie
  87. );
  88. bool
  89. RemovePair(
  90. SidHandle sid,
  91. CUser * user
  92. );
  93. CUser *
  94. FindSid(
  95. SidHandle sid
  96. );
  97. void Dump();
  98. };
  99. public:
  100. CLoggedOnUsers( TaskScheduler & sched );
  101. ~CLoggedOnUsers();
  102. HRESULT AddServiceAccounts();
  103. HRESULT AddActiveUsers();
  104. HRESULT LogonSession( DWORD session );
  105. HRESULT LogoffSession( DWORD session );
  106. HRESULT LogonService( HANDLE token, DWORD * cookie );
  107. HRESULT LogoffService( SidHandle Sid, DWORD cookie );
  108. CUser * FindUser( SidHandle sid, DWORD session );
  109. void Dump();
  110. private:
  111. //--------------------------------------------------------------------
  112. TaskScheduler & m_TaskScheduler;
  113. CSessionList m_ActiveSessions;
  114. CUserList m_ActiveUsers;
  115. CUserList m_ActiveServiceAccounts;
  116. long m_CurrentCookie;
  117. CLogonNotification * m_SensNotifier;
  118. };