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.

191 lines
3.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: dbcomp.h
  7. //
  8. // Contents: Hash Database Compactor
  9. //
  10. // History: 9-8-1998 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #if !defined(__DBCOMP_H__)
  14. #define __DBCOMP_H__
  15. #include <cbfile.hxx>
  16. #include <catdb.hxx>
  17. //
  18. // Unique catalog structure
  19. //
  20. typedef struct _UNIQUE_CATALOG {
  21. HashMastRec HashDbRecord;
  22. DWORD UniqueOffset;
  23. } UNIQUE_CATALOG, *PUNIQUE_CATALOG;
  24. #define INITIAL_UNIQUE_CATALOGS 10
  25. #define GROW_UNIQUE_CATALOGS 5
  26. #define DB_KEY_EXT L".cbk"
  27. #define DB_DATA_EXT L".cbd"
  28. #define KEY_RECORD_SIZE 24
  29. #define KEY_SIZE 20
  30. //
  31. // Analyzes and compacts the current icky PBerkman hash database format with
  32. // support for removal of unwanted catalog entries
  33. //
  34. class CHashDbCompactor
  35. {
  36. public:
  37. //
  38. // Construction
  39. //
  40. CHashDbCompactor ();
  41. ~CHashDbCompactor ();
  42. //
  43. // Initialize
  44. //
  45. BOOL Initialize (
  46. IN LPCWSTR pwszDbLock,
  47. IN LPCWSTR pwszDbDirectory
  48. );
  49. //
  50. // Original database locking
  51. //
  52. VOID LockDatabase ();
  53. VOID UnlockDatabase ();
  54. //
  55. // Map original database
  56. //
  57. BOOL MapDatabase (
  58. IN LPCWSTR pwszDbName,
  59. OUT PCRYPT_DATA_BLOB pKey,
  60. OUT LPWSTR* ppwszKeyPath,
  61. OUT PCRYPT_DATA_BLOB pData,
  62. OUT LPWSTR* ppwszDataPath
  63. );
  64. VOID UnmapDatabase (
  65. IN PCRYPT_DATA_BLOB pKey,
  66. IN PCRYPT_DATA_BLOB pData
  67. );
  68. //
  69. // Analyze the data for compaction
  70. //
  71. BOOL AnalyzeDataForCompaction (
  72. IN PCRYPT_DATA_BLOB pData,
  73. IN OPTIONAL LPCSTR pszUnwantedCatalog
  74. );
  75. //
  76. // Flush compaction analysis
  77. //
  78. BOOL FlushCompactionAnalysis ();
  79. //
  80. // Write the compacted database
  81. //
  82. BOOL WriteCompactedDatabase (
  83. IN PCRYPT_DATA_BLOB pKey,
  84. IN PCRYPT_DATA_BLOB pData,
  85. IN OPTIONAL LPCSTR pszUnwantedCatalog
  86. );
  87. //
  88. // Commit compacted database
  89. //
  90. BOOL CommitCompactedDatabase (
  91. IN LPCWSTR pwszFinalKeyPath,
  92. IN LPCWSTR pwszFinalDataPath
  93. );
  94. //
  95. // Free memory
  96. //
  97. VOID FreeString (IN LPWSTR pwsz);
  98. private:
  99. //
  100. // Database lock
  101. //
  102. HANDLE m_hDbLock;
  103. //
  104. // Database directory
  105. //
  106. LPWSTR m_pwszDbDirectory;
  107. //
  108. // Compacted database data
  109. //
  110. DWORD m_cAllocatedUniqueCatalogs;
  111. DWORD m_cUniqueCatalogs;
  112. PUNIQUE_CATALOG m_aUniqueCatalogs;
  113. //
  114. // Temp database names
  115. //
  116. WCHAR m_pwszTempKeyPath[MAX_PATH+1];
  117. WCHAR m_pwszTempDataPath[MAX_PATH+1];
  118. //
  119. // Cached search data
  120. //
  121. DWORD m_iLastUniqueCatalogFoundByName;
  122. //
  123. // Private methods
  124. //
  125. BOOL GrowUniqueCatalogs (DWORD cGrow);
  126. PUNIQUE_CATALOG FindUniqueCatalogByName (LPCSTR pszCatalogName);
  127. BOOL AddUniqueCatalog (HashMastRec* pHashMastRecord);
  128. BOOL CatalogFileExists (LPCSTR pszCatalogName, DWORD cbName);
  129. };
  130. //
  131. // API for compacting the database
  132. //
  133. extern "C" {
  134. BOOL WINAPI
  135. CatalogCompactHashDatabase (
  136. IN LPCWSTR pwszDbLock,
  137. IN LPCWSTR pwszDbDirectory,
  138. IN LPCWSTR pwszDbName,
  139. IN OPTIONAL LPCWSTR pwszUnwantedCatalog
  140. );
  141. }
  142. #endif