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.

236 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2002.
  5. //
  6. // File: secstore.hxx
  7. //
  8. // Contents: SDID to SECURIRY_DESCRIPTOR mapping table for downlevel content
  9. // index. Stored persistently in the files CiST0000.00?.
  10. //
  11. // Classes: CSdidLookupEntry
  12. // CSdidLookupTable
  13. // SSdidLookupTableHeader
  14. //
  15. // History: 26 Jan 1996 AlanW Created
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include <prcstob.hxx>
  20. #include <enumstr.hxx>
  21. class CiStorage;
  22. class CRcovStrmReadIter;
  23. typedef ULONG SDID;
  24. const SDID SDID_NULL_SECURITY = 0xFFFFFFF0;
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Class: CSdidLookupEntry
  28. //
  29. // Purpose: CSdidLookup table entries. These are the records stored
  30. // persistently for a security descriptor. There is a header
  31. // record that describes the SD, followed by the self-relative
  32. // security descriptor, in as many file records as are required
  33. // to store it.
  34. //
  35. // History: 26 Jan 1996 AlanW Created
  36. //
  37. // Notes:
  38. //
  39. //----------------------------------------------------------------------------
  40. // Note: SECSTORE_REC_SIZE should be larger than sizeof (SSdHeaderRecord) +
  41. // SECURITY_DESCRIPTOR_MIN_LENGTH.
  42. const USHORT SECSTORE_REC_SIZE = 64;
  43. const ULONG SECSTORE_HASH_SIZE = 199;
  44. struct SSdHeaderRecord
  45. {
  46. ULONG cbSD; // size in bytes of the security descriptor
  47. ULONG ulHash; // the hash of the security descriptor
  48. SDID iHashChain; // index to previous entry for hash bucket
  49. };
  50. class CSdidLookupEntry : public CDoubleLink
  51. {
  52. friend class CSdidLookupTable;
  53. public:
  54. CSdidLookupEntry( SDID sdid ) :
  55. _sdid( sdid ),
  56. _pSD( 0 )
  57. {
  58. }
  59. ~CSdidLookupEntry( )
  60. {
  61. delete _pSD;
  62. }
  63. PSECURITY_DESCRIPTOR GetSD( void ) { return _pSD; }
  64. BOOL IsEqual( const PSECURITY_DESCRIPTOR pSD,
  65. ULONG cbSD,
  66. ULONG ulHash ) const {
  67. return _hdr.ulHash == ulHash &&
  68. _hdr.cbSD == cbSD &&
  69. RtlEqualMemory( _pSD, pSD, cbSD );
  70. }
  71. ULONG Size( void ) const { return _hdr.cbSD + sizeof _hdr; }
  72. ULONG iNextRecord( ) const { return BytesToRecords( Size() ); }
  73. ULONG Sdid( ) const { return _sdid; }
  74. ULONG Hash( ) const { return _hdr.ulHash; }
  75. ULONG Length( ) const { return _hdr.cbSD; }
  76. ULONG Chain( ) const { return _hdr.iHashChain; }
  77. private:
  78. ULONG BytesToRecords ( ULONG cb ) const {
  79. return (cb + (SECSTORE_REC_SIZE - 1)) / SECSTORE_REC_SIZE;
  80. }
  81. SSdHeaderRecord _hdr;
  82. SDID _sdid;
  83. PSECURITY_DESCRIPTOR _pSD;
  84. };
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Class: CSdidCache
  88. //
  89. // Purpose: Cache of CSdidListEntry.
  90. //
  91. // History: 18 Apr 1996 AlanW Created
  92. //
  93. // Notes:
  94. //
  95. //----------------------------------------------------------------------------
  96. const unsigned MAX_SDID_CACHE = 16;
  97. class CSdidCache : public TDoubleList<CSdidLookupEntry>
  98. {
  99. public:
  100. CSdidCache ( unsigned maxEntries = MAX_SDID_CACHE ) :
  101. _maxEntries( maxEntries )
  102. { }
  103. ~CSdidCache () { Empty(); }
  104. void Add( CSdidLookupEntry * pSLE );
  105. void Empty( );
  106. private:
  107. ULONG _maxEntries; // maximum size
  108. };
  109. typedef TFwdListIter< CSdidLookupEntry, CSdidCache > CSdidCacheIter;
  110. //+---------------------------------------------------------------------------
  111. //
  112. // Class: CSdidLookupTable
  113. //
  114. // Purpose: Persistent SDID to SECURITY_DESCRIPTOR mapping table for
  115. // downlevel content index.
  116. //
  117. // History: 26 Jan 1996 AlanW Created
  118. //
  119. // Notes:
  120. //
  121. //----------------------------------------------------------------------------
  122. class CSdidLookupTable
  123. {
  124. enum { eSecStoreWid = 0 };
  125. public:
  126. CSdidLookupTable ( );
  127. ~CSdidLookupTable ();
  128. BOOL Init( CiStorage * pStorage );
  129. void Empty();
  130. SDID LookupSDID( PSECURITY_DESCRIPTOR pSD,
  131. ULONG cbSD );
  132. BOOL AccessCheck( SDID sdid,
  133. HANDLE hToken,
  134. ACCESS_MASK am,
  135. BOOL & fGranted );
  136. HRESULT GetSecurityDescriptor( SDID sdid,
  137. PSECURITY_DESCRIPTOR pSD,
  138. ULONG cbIn,
  139. ULONG & cbOut );
  140. ULONG Records() const { return _Header.cRecords; }
  141. ULONG HashSize() const { return _Header.cHash; }
  142. void Save( IProgressNotify * pIProgressNotify,
  143. BOOL & fAbort,
  144. CiStorage & dstStorage,
  145. IEnumString **ppFileList );
  146. void Shutdown()
  147. {
  148. _xrsoSdidTable.Free();
  149. }
  150. private:
  151. CSdidLookupEntry * Lookup( SDID sdid );
  152. void AddToCache( CSdidLookupEntry * pSLE );
  153. static ULONG Hash( const PSECURITY_DESCRIPTOR pSD, unsigned cbSD );
  154. void LoadTableEntry(
  155. CRcovStrmReadIter & iter,
  156. CSdidLookupEntry & Entry,
  157. SDID iSdid );
  158. struct SSdidLookupTableHeader {
  159. CHAR Signature[8]; // "SECSTORE"
  160. USHORT cbRecord; // size of file records
  161. ULONG cHash; // number of hash table entries
  162. ULONG cRecords; // number of file records
  163. };
  164. SSdidLookupTableHeader _Header;
  165. SDID * _pTable; // the hash table
  166. CMutexSem _mutex;
  167. CSdidCache _cache; // lookaside list of entries
  168. XPtr<PRcovStorageObj> _xrsoSdidTable; // The persistent storage
  169. #if defined(UNIT_TEST)
  170. public:
  171. void Print( void );
  172. #endif // defined(UNIT_TEST)
  173. #if (DBG == 1)
  174. ULONG _cMaxChainLen;
  175. ULONG _cTotalSearches;
  176. ULONG _cTotalLength;
  177. #endif // (DBG == 1)
  178. };