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.

166 lines
3.0 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 CmdLine
  63. );
  64. private:
  65. long _ReferenceCount;
  66. HANDLE _Token;
  67. SidHandle _Sid;
  68. DWORD _Cookie;
  69. //--------------------------------------------------------------------
  70. };
  71. class CLoggedOnUsers
  72. {
  73. class CSessionList : public std::map<DWORD, CUser *>
  74. {
  75. public:
  76. void Dump();
  77. };
  78. class CUserList : public std::multimap<SidHandle, CUser *, CSidSorter>
  79. {
  80. public:
  81. ~CUserList();
  82. CUser *
  83. RemoveByCookie(
  84. SidHandle sid,
  85. DWORD cookie
  86. );
  87. bool
  88. RemovePair(
  89. SidHandle sid,
  90. CUser * user
  91. );
  92. CUser *
  93. FindSid(
  94. SidHandle sid
  95. );
  96. void Dump();
  97. };
  98. public:
  99. CLoggedOnUsers( TaskScheduler & sched );
  100. ~CLoggedOnUsers();
  101. HRESULT AddServiceAccounts();
  102. HRESULT AddActiveUsers();
  103. HRESULT LogonSession( DWORD session );
  104. HRESULT LogoffSession( DWORD session );
  105. HRESULT LogonService( HANDLE token, DWORD * cookie );
  106. HRESULT LogoffService( SidHandle Sid, DWORD cookie );
  107. CUser * FindUser( SidHandle sid, DWORD session );
  108. void Dump();
  109. private:
  110. //--------------------------------------------------------------------
  111. TaskScheduler & m_TaskScheduler;
  112. CSessionList m_ActiveSessions;
  113. CUserList m_ActiveUsers;
  114. CUserList m_ActiveServiceAccounts;
  115. long m_CurrentCookie;
  116. CLogonNotification * m_SensNotifier;
  117. };