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.

173 lines
3.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: catcache.h
  7. //
  8. // Contents: Catalog Cache for performance improvement to verification path
  9. //
  10. // History: 26-May-98 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #if !defined(__CATCACHE_H__)
  14. #define __CATCACHE_H__
  15. //
  16. // This caches state data for catalog member verification indexed by the file
  17. // path to the catalog. This relieves the caller from having to user the
  18. // icky WTD_STATEACTION* stuff in order to achieve the same ends. Someday,
  19. // we will just re-design/re-implement the WVT and Catalog stuff and life
  20. // will be good.
  21. //
  22. #include <lrucache.h>
  23. #define DEFAULT_CATALOG_CACHE_BUCKETS 3
  24. #define DEFAULT_CATALOG_CACHE_MAX_ENTRIES 3
  25. typedef struct _CATALOG_CACHED_STATE {
  26. HANDLE hStateData;
  27. HLRUENTRY hEntry;
  28. } CATALOG_CACHED_STATE, *PCATALOG_CACHED_STATE;
  29. class CCatalogCache
  30. {
  31. public:
  32. //
  33. // Construction
  34. //
  35. inline CCatalogCache ();
  36. inline ~CCatalogCache ();
  37. //
  38. // Initialization
  39. //
  40. BOOL Initialize ();
  41. VOID Uninitialize ();
  42. //
  43. // Cache locking
  44. //
  45. inline VOID LockCache ();
  46. inline VOID UnlockCache ();
  47. //
  48. // Cached State management
  49. //
  50. BOOL IsCacheableWintrustCall (WINTRUST_DATA* pWintrustData);
  51. VOID AdjustWintrustDataToCachedState (
  52. WINTRUST_DATA* pWintrustData,
  53. PCATALOG_CACHED_STATE pCachedState,
  54. BOOL fUndoAdjustment
  55. );
  56. BOOL CreateCachedStateFromWintrustData (
  57. WINTRUST_DATA* pWintrustData,
  58. PCATALOG_CACHED_STATE* ppCachedState
  59. );
  60. VOID ReleaseCachedState (PCATALOG_CACHED_STATE pCachedState);
  61. VOID AddCachedState (PCATALOG_CACHED_STATE pCachedState);
  62. VOID RemoveCachedState (PCATALOG_CACHED_STATE pCachedState);
  63. VOID RemoveCachedState (WINTRUST_DATA* pWintrustData);
  64. VOID FlushCache ();
  65. //
  66. // Cached State lookup
  67. //
  68. PCATALOG_CACHED_STATE FindCachedState (WINTRUST_DATA* pWintrustData);
  69. private:
  70. //
  71. // Lock
  72. //
  73. CRITICAL_SECTION m_Lock;
  74. //
  75. // Cache
  76. //
  77. HLRUCACHE m_hCache;
  78. };
  79. //
  80. // Entry data free function
  81. //
  82. VOID WINAPI
  83. CatalogCacheFreeEntryData (LPVOID pvData);
  84. DWORD WINAPI
  85. CatalogCacheHashIdentifier (PCRYPT_DATA_BLOB pIdentifier);
  86. //
  87. // Inline methods
  88. //
  89. //+---------------------------------------------------------------------------
  90. //
  91. // Member: CCatalogCache::CCatalogCache, public
  92. //
  93. // Synopsis: Constructor
  94. //
  95. //----------------------------------------------------------------------------
  96. inline
  97. CCatalogCache::CCatalogCache ()
  98. {
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Member: CCatalogCache::~CCatalogCache, public
  103. //
  104. // Synopsis: Destructor
  105. //
  106. //----------------------------------------------------------------------------
  107. inline
  108. CCatalogCache::~CCatalogCache ()
  109. {
  110. }
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Member: CCatalogCache::LockCache, public
  114. //
  115. // Synopsis: lock the cache
  116. //
  117. //----------------------------------------------------------------------------
  118. inline VOID
  119. CCatalogCache::LockCache ()
  120. {
  121. EnterCriticalSection( &m_Lock );
  122. }
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Member: CCatalogCache::UnlockCache, public
  126. //
  127. // Synopsis: unlock the cache
  128. //
  129. //----------------------------------------------------------------------------
  130. inline VOID
  131. CCatalogCache::UnlockCache ()
  132. {
  133. LeaveCriticalSection( &m_Lock );
  134. }
  135. #endif