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.

112 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996, Microsoft Corporation
  4. //
  5. // File: secident.hxx
  6. //
  7. // Contents: Security identity, to determine if two requests are on
  8. // behalf of the same authenticated ID.
  9. //
  10. // Class: CSecurityIdentity
  11. //
  12. // History: 23 Jan 96 Alanw Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Class: CSecurityIdentity
  19. //
  20. // Purpose: Identify the client of a query for query caching.
  21. //
  22. // History: 23 Jan 1996 AlanW Created
  23. //
  24. // Notes: The token's ModifiedId is used to correlate tokens with
  25. // the same SIDs and Privileges. The ModifiedId is changed
  26. // any time a token is changed. On a server, the privileges
  27. // are not modified, so the ModifiedId doesn't change typically.
  28. //
  29. // The ModifiedId is a LUID, so it's very convenient for
  30. // comparisons.
  31. //
  32. //----------------------------------------------------------------------------
  33. class CSecurityIdentity
  34. {
  35. public:
  36. inline CSecurityIdentity();
  37. CSecurityIdentity( CSecurityIdentity const & securityIdentity )
  38. {
  39. _TokenModifiedId = securityIdentity._TokenModifiedId;
  40. }
  41. void SetSecurityToken( CSecurityIdentity const & securityIdentity )
  42. {
  43. _TokenModifiedId = securityIdentity._TokenModifiedId;
  44. }
  45. inline BOOL IsEqual( CSecurityIdentity const & Other ) const;
  46. private:
  47. LUID _TokenModifiedId; // the token ID
  48. };
  49. //+---------------------------------------------------------------------------
  50. //----------------------------------------------------------------------------
  51. HANDLE GetSecurityToken(TOKEN_STATISTICS & TokenInformation);
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Method: CSecurityIdentity::CSecurityIdentity, public
  55. //
  56. // Synopsis: Constructor of a CSecurityIdentity. Get information
  57. // from a token to identify the client.
  58. //
  59. // Arguments: - none -
  60. //
  61. // History: 25 Jan 96 Alanw Created
  62. //
  63. //----------------------------------------------------------------------------
  64. inline CSecurityIdentity::CSecurityIdentity()
  65. {
  66. _TokenModifiedId.LowPart = 0;
  67. _TokenModifiedId.HighPart = 0;
  68. TOKEN_STATISTICS TokenInformation;
  69. HANDLE hToken = GetSecurityToken(TokenInformation);
  70. CloseHandle( hToken );
  71. _TokenModifiedId = TokenInformation.ModifiedId;
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Method: CSecurityIdentity::IsEqual, public
  76. //
  77. // Synopsis: Test for equality.
  78. //
  79. // Arguments: [Other] -- Token to compare
  80. //
  81. // Returns: TRUE if tokens are equal
  82. //
  83. // History: 25 Jan 96 Alanw Created
  84. //
  85. //----------------------------------------------------------------------------
  86. inline BOOL CSecurityIdentity::IsEqual( CSecurityIdentity const & Other ) const
  87. {
  88. //
  89. // Note: The cast to int64 works *only* for equality!
  90. //
  91. Win4Assert( sizeof( _TokenModifiedId ) == sizeof( LARGE_INTEGER ) );
  92. return ( ((UNALIGNED LARGE_INTEGER *)&_TokenModifiedId)->QuadPart ==
  93. ((UNALIGNED LARGE_INTEGER *)&Other._TokenModifiedId)->QuadPart);
  94. }