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.

190 lines
3.7 KiB

  1. /*
  2. // Copyright (c) 2000-2002 Microsoft Corporation, All Rights Reserved
  3. *
  4. * Created: 4/21/2000, Kevin Hughes
  5. */
  6. #pragma once
  7. class CSidAndAttribute
  8. {
  9. public:
  10. CSidAndAttribute() {}
  11. CSidAndAttribute(
  12. CSid& csidIn,
  13. DWORD dwAttribIn)
  14. {
  15. m_sid = csidIn;
  16. m_dwAttributes = dwAttribIn;
  17. }
  18. virtual ~CSidAndAttribute() {}
  19. CSid m_sid;
  20. DWORD m_dwAttributes;
  21. };
  22. class Privilege
  23. {
  24. public:
  25. Privilege() : dwAttributes(0) {}
  26. virtual ~Privilege() {}
  27. Privilege(
  28. CHString& strIn,
  29. DWORD attribsIn)
  30. : dwAttributes(attribsIn)
  31. {
  32. chstrName = strIn;
  33. }
  34. CHString chstrName;
  35. DWORD dwAttributes;
  36. };
  37. typedef std::vector<CSidAndAttribute> SANDATTRIBUTE_VECTOR;
  38. typedef std::vector<Privilege> PRIVILEGE_VECTOR;
  39. //
  40. // forwarding
  41. //
  42. class CSecurityDescriptor;
  43. class CToken
  44. {
  45. public:
  46. CToken();
  47. CToken(const CToken& rTok);
  48. virtual ~CToken();
  49. void CleanToken () ;
  50. BOOL Duplicate (
  51. const CToken& rTok,
  52. BOOL bReInit = TRUE,
  53. DWORD dwDesiredAccess = TOKEN_IMPERSONATE | TOKEN_DUPLICATE | TOKEN_QUERY,
  54. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel = SecurityImpersonation,
  55. TOKEN_TYPE type = TokenImpersonation
  56. ) ;
  57. BOOL GetTokenType ( TOKEN_TYPE& type ) const;
  58. BOOL IsValidToken ()
  59. {
  60. return m_fIsValid ;
  61. }
  62. long GetPrivCount() const;
  63. long GetGroupCount() const;
  64. bool GetPrivilege(
  65. Privilege* privOut,
  66. long lPos) const;
  67. bool GetGroup(
  68. CSid* sidOut,
  69. long lPos) const;
  70. // Deletes a member from the access token's
  71. // member list, and applies the change.
  72. bool DeleteGroup(
  73. CSid& sidToDelete);
  74. // Adds a member to the specified group to
  75. // the list of token groups.
  76. bool AddGroup(
  77. CSid& sidToAdd,
  78. DWORD dwAttributes);
  79. CToken& operator=(const CToken& rv);
  80. HANDLE GetTokenHandle() const;
  81. bool GetTokenOwner(
  82. CSid* sidOwner) const;
  83. // NOTE: hands back internal descriptor.
  84. bool GetDefaultSD(
  85. CSecurityDescriptor** ppsdDefault);
  86. DWORD SetDefaultSD(
  87. CSecurityDescriptor& SourceSD);
  88. DWORD EnablePrivilege(
  89. CHString& strPrivilegeName);
  90. DWORD DisablePrivilege(
  91. CHString& chstrPrivilegeName);
  92. void Dump(WCHAR* pszFileName);
  93. protected:
  94. DWORD ReinitializeAll();
  95. HANDLE m_hToken;
  96. DWORD m_dwLastError;
  97. bool m_fIsValid;
  98. private:
  99. DWORD ReinitializeOwnerSid();
  100. DWORD ReinitializeDefaultSD();
  101. DWORD RebuildGroupList();
  102. DWORD RebuildPrivilegeList();
  103. DWORD GTI(
  104. TOKEN_INFORMATION_CLASS TokenInformationClass,
  105. PVOID* ppvBuff);
  106. bool ApplyTokenGroups();
  107. CSid m_sidTokenOwner;
  108. CSecurityDescriptor* m_psdDefault; // Default security info
  109. SANDATTRIBUTE_VECTOR m_vecGroupsAndAttributes; // List of groups and their attributes
  110. PRIVILEGE_VECTOR m_vecPrivileges; // List of privileges
  111. protected:
  112. bool m_fClose;
  113. };
  114. class CProcessToken : public CToken
  115. {
  116. public:
  117. CProcessToken (
  118. HANDLE hProcess = INVALID_HANDLE_VALUE,
  119. bool fGetHandleOnly = true,
  120. DWORD dwDesiredAccess = MAXIMUM_ALLOWED
  121. );
  122. virtual ~CProcessToken() {}
  123. private:
  124. };
  125. class CThreadToken : public CToken
  126. {
  127. public:
  128. //CThreadToken();
  129. CThreadToken (
  130. HANDLE hThread = INVALID_HANDLE_VALUE,
  131. bool fGetHandleOnly = true,
  132. bool fAccessCheckProcess = false,
  133. DWORD dwDesiredAccess = MAXIMUM_ALLOWED
  134. );
  135. virtual ~CThreadToken() {}
  136. private:
  137. };