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.

242 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998.
  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 Load( CiStorage * pStorage,
  147. IEnumString * pFileList,
  148. IProgressNotify * pProgressNotify,
  149. BOOL fCallerOwnsFiles,
  150. BOOL * pfAbort );
  151. void Shutdown()
  152. {
  153. _xrsoSdidTable.Free();
  154. }
  155. private:
  156. CSdidLookupEntry * Lookup( SDID sdid );
  157. void AddToCache( CSdidLookupEntry * pSLE );
  158. static ULONG Hash( const PSECURITY_DESCRIPTOR pSD, unsigned cbSD );
  159. void LoadTableEntry(
  160. CRcovStrmReadIter & iter,
  161. CSdidLookupEntry & Entry,
  162. SDID iSdid );
  163. struct SSdidLookupTableHeader {
  164. CHAR Signature[8]; // "SECSTORE"
  165. USHORT cbRecord; // size of file records
  166. ULONG cHash; // number of hash table entries
  167. ULONG cRecords; // number of file records
  168. };
  169. SSdidLookupTableHeader _Header;
  170. SDID * _pTable; // the hash table
  171. CMutexSem _mutex;
  172. CSdidCache _cache; // lookaside list of entries
  173. XPtr<PRcovStorageObj> _xrsoSdidTable; // The persistent storage
  174. #if defined(UNIT_TEST)
  175. public:
  176. void Print( void );
  177. #endif // defined(UNIT_TEST)
  178. #if (DBG == 1)
  179. ULONG _cMaxChainLen;
  180. ULONG _cTotalSearches;
  181. ULONG _cTotalLength;
  182. #endif // (DBG == 1)
  183. };