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.

290 lines
11 KiB

  1. /*
  2. Copyright (c) Microsoft Corporation
  3. */
  4. #pragma once
  5. #include "fusionbuffer.h"
  6. class CAssemblyRecoveryInfo;
  7. enum SxsWFPResolveCodebase
  8. {
  9. CODEBASE_RESOLVED_URLHEAD_UNKNOWN,
  10. CODEBASE_RESOLVED_URLHEAD_FILE,
  11. CODEBASE_RESOLVED_URLHEAD_HTTP,
  12. CODEBASE_RESOLVED_URLHEAD_WINSOURCE,
  13. CODEBASE_RESOLVED_URLHEAD_CDROM
  14. };
  15. BOOL
  16. SxspDetermineCodebaseType(
  17. IN const CBaseStringBuffer &rcbuffUrlString,
  18. OUT SxsWFPResolveCodebase &rcbaseType,
  19. OUT CBaseStringBuffer *pbuffRemainder = NULL
  20. );
  21. //
  22. // no parens on these macros so that you can use them
  23. // in compile-time string concatenation, and parens
  24. // here wouldn't actually help anything
  25. //
  26. #define CSMD_TOPLEVEL_CODEBASE L"Codebase"
  27. #define CSMD_TOPLEVEL_CATALOG L"Catalog"
  28. #define CSMD_TOPLEVEL_SHORTNAME L"ShortName"
  29. #define CSMD_TOPLEVEL_SHORTCATALOG L"ShortCatalogName"
  30. #define CSMD_TOPLEVEL_SHORTMANIFEST L"ShortManifestName"
  31. #define CSMD_TOPLEVEL_MANIFESTHASH L"ManifestSHA1Hash"
  32. #define CSMD_TOPLEVEL_FILES L"Files"
  33. #define CSMD_TOPLEVEL_CODEBASES L"Codebases"
  34. #define CSMD_TOPLEVEL_PUBLIC_KEY_TOKEN L"PublicKeyToken"
  35. #define CSMD_CODEBASES_PROMPTSTRING L"Prompt"
  36. #define CSMD_CODEBASES_URL L"URL"
  37. #define CSMD_TOPLEVEL_IDENTITY L"Identity"
  38. typedef CFusionArray<BYTE> CFusionByteArray;
  39. typedef CFusionArray<CStringBuffer> CFusionStringArray;
  40. class CFileInformationTableHelper;
  41. class CFileHashTableHelper;
  42. class CSecurityMetaData;
  43. class CFileHashTableHelper:
  44. public CCaseInsensitiveSimpleUnicodeStringTableHelper<CFusionByteArray>
  45. {
  46. public:
  47. static BOOL InitializeValue(const CFusionByteArray &vin, CFusionByteArray &rvstored)
  48. {
  49. FN_PROLOG_WIN32
  50. IFW32FALSE_EXIT(vin.Win32Clone(rvstored));
  51. FN_EPILOG
  52. }
  53. static BOOL UpdateValue(const CFusionByteArray &vin, CFusionByteArray &rvstored) { return InitializeValue( vin, rvstored ); }
  54. };
  55. typedef CCaseInsensitiveSimpleUnicodeStringTable<CFusionByteArray, CFileHashTableHelper> CFileHashTable;
  56. typedef CCaseInsensitiveSimpleUnicodeStringTableIter<CFusionByteArray, CFileHashTableHelper> CFileHashTableIter;
  57. //
  58. // Contains metadata about a file element. This is a collection with the name of
  59. // the file and a list (table) of the SHA1 hash elements.
  60. //
  61. class CMetaDataFileElement : CFileHashTable
  62. {
  63. CMetaDataFileElement( const CMetaDataFileElement& );
  64. CMetaDataFileElement& operator=( const CMetaDataFileElement& );
  65. friend CFileInformationTableHelper;
  66. friend CSecurityMetaData;
  67. BOOL ReadFromRegistry( CRegKey& hkThisFileNode );
  68. BOOL WriteToRegistry( CRegKey& hkThisFileNode ) const;
  69. public:
  70. CMetaDataFileElement();
  71. BOOL Initialize();
  72. BOOL Initialize( const CMetaDataFileElement& other );
  73. BOOL GetHashDataForKind( IN const ALG_ID aid, OUT CFusionByteArray& arrHashData, BOOL &bHadSuchData ) const;
  74. BOOL GetHashDataForKind( IN const CBaseStringBuffer& buffId, OUT CFusionByteArray& arrHashData, BOOL &bHadSuchData ) const;
  75. BOOL PutHashData( IN const ALG_ID aid, IN const CFusionByteArray& arrHashData );
  76. BOOL PutHashData( IN const CBaseStringBuffer& buffId, IN const CFusionByteArray& arrHashData );
  77. };
  78. //
  79. // Now another table, this time of file to metadata mappings
  80. //
  81. class CFileInformationTableHelper :
  82. public CCaseInsensitiveSimpleUnicodeStringTableHelper<CMetaDataFileElement>
  83. {
  84. public:
  85. static BOOL InitializeValue( const CMetaDataFileElement &vin, CMetaDataFileElement &stored ) { return stored.Initialize( vin ); }
  86. static BOOL UpdateValue( const CMetaDataFileElement &vin, CMetaDataFileElement &stored );
  87. };
  88. typedef CCaseInsensitiveSimpleUnicodeStringTable<CMetaDataFileElement, CFileInformationTableHelper> CFileInformationTable;
  89. typedef CCaseInsensitiveSimpleUnicodeStringTableIter<CMetaDataFileElement, CFileInformationTableHelper> CFileInformationTableIter;
  90. class CCodebaseInformation
  91. {
  92. friend CSecurityMetaData;
  93. public:
  94. CCodebaseInformation() : m_Type(CODEBASE_RESOLVED_URLHEAD_UNKNOWN) { }
  95. BOOL Initialize();
  96. BOOL Initialize(const CCodebaseInformation &other);
  97. const CBaseStringBuffer& GetCodebase() const { return m_Codebase; }
  98. BOOL SetCodebase(PCWSTR psz, SIZE_T cch) { return m_Codebase.Win32Assign(psz, cch); }
  99. BOOL SetCodebase(const CBaseStringBuffer & rsb) { return m_Codebase.Win32Assign(rsb); }
  100. const CBaseStringBuffer& GetPromptText() const { return m_PromptText; }
  101. BOOL SetPromptText(PCWSTR psz, SIZE_T cch) { return m_PromptText.Win32Assign(psz, cch); }
  102. BOOL SetPromptText(const CBaseStringBuffer & rsb) { return m_PromptText.Win32Assign(rsb); }
  103. const CBaseStringBuffer &GetReference() const { return m_Reference; }
  104. BOOL SetReference(const CBaseStringBuffer &r) { return m_Reference.Win32Assign(r); }
  105. BOOL Win32GetType(SxsWFPResolveCodebase& Type) const
  106. {
  107. FN_PROLOG_WIN32
  108. if (m_Type == CODEBASE_RESOLVED_URLHEAD_UNKNOWN)
  109. {
  110. IFW32FALSE_EXIT(::SxspDetermineCodebaseType(this->m_Codebase, this->m_Type));
  111. }
  112. Type = m_Type ;
  113. FN_EPILOG
  114. }
  115. BOOL SetType( SxsWFPResolveCodebase Type )
  116. {
  117. FN_PROLOG_WIN32
  118. INTERNAL_ERROR_CHECK(m_Type == CODEBASE_RESOLVED_URLHEAD_UNKNOWN);
  119. this->m_Type = Type;
  120. FN_EPILOG
  121. }
  122. protected:
  123. BOOL WriteToRegistryKey(const CRegKey &rhkCodebaseKey) const;
  124. BOOL ReadFromRegistryKey(const CRegKey &rhkCodebaseKey);
  125. CMediumStringBuffer m_Reference;
  126. CMediumStringBuffer m_Codebase;
  127. CMediumStringBuffer m_PromptText;
  128. mutable SxsWFPResolveCodebase m_Type;
  129. private:
  130. CCodebaseInformation( const CCodebaseInformation& );
  131. CCodebaseInformation& operator=( const CCodebaseInformation& );
  132. };
  133. MAKE_CFUSIONARRAY_READY(CCodebaseInformation, Initialize);
  134. class CCodebaseInformationList : public CFusionArray<CCodebaseInformation>
  135. {
  136. public:
  137. BOOL FindCodebase(const CBaseStringBuffer &rbuffReference, CCodebaseInformation *&rpCodebaseInformation);
  138. BOOL RemoveCodebase(const CBaseStringBuffer &rbuffReference, bool &rfRemoved);
  139. };
  140. class CSecurityMetaData
  141. {
  142. CCodebaseInformationList m_cilCodebases;
  143. CFusionByteArray m_baSignerPublicKeyToken;
  144. CFileInformationTable m_fitFileDataTable;
  145. CSmallStringBuffer m_buffShortNameOnDisk;
  146. CFusionByteArray m_baManifestSha1Hash;
  147. CStringBuffer m_buffTextualAssemblyIdentity;
  148. CStringBuffer m_buffShortCatalogName;
  149. CStringBuffer m_buffShortManifestName;
  150. CSecurityMetaData( const CSecurityMetaData& );
  151. CSecurityMetaData& operator=( const CSecurityMetaData& );
  152. //
  153. // Cheesy, but we always want to merge the two elements if one already exists.
  154. //
  155. BOOL MergeFileDataElement(
  156. const CMetaDataFileElement &pNewFileDataElement,
  157. const CMetaDataFileElement &rpOldFileDataElement,
  158. InsertOrUpdateIfDisposition &Disposition ) { Disposition = eUpdateValue; return TRUE; }
  159. BOOL LoadCodebasesFromKey( CRegKey& hkCodebasesSubkey );
  160. BOOL LoadFilesFromKey( CRegKey& hkCodebasesSubkey );
  161. BOOL WriteFilesIntoKey( CRegKey &rhkFilesKey ) const;
  162. public:
  163. //
  164. // Get information about a single item
  165. //
  166. enum FileAdditionDisposition {
  167. eFailIfAlreadyExists,
  168. eReplaceIfAlreadyExists,
  169. eMergeIfAlreadyExists
  170. };
  171. BOOL AddFileMetaData( const CBaseStringBuffer& rcbuffFileName, CMetaDataFileElement &rElementData, FileAdditionDisposition dispHowToAdd = eFailIfAlreadyExists );
  172. BOOL GetFileMetaData( const CBaseStringBuffer& rcbuffFileName, CMetaDataFileElement const* &rpElementData ) const;
  173. //
  174. // Full table that we can iterate over
  175. //
  176. const CFileInformationTable& GetFileDataTable() const { return m_fitFileDataTable; }
  177. //
  178. // Simplify the addition of a hash value
  179. //
  180. BOOL QuickAddFileHash( const CBaseStringBuffer& rcbuffFileName, ALG_ID aidHashAlg, const CBaseStringBuffer& rcbuffHashValue );
  181. //
  182. // All your codebases are belong to us.
  183. //
  184. const CCodebaseInformationList& GetCodeBaseList() const { return m_cilCodebases; }
  185. protected:
  186. friend CAssemblyRecoveryInfo;
  187. CCodebaseInformationList& GetCodeBaseList() { return m_cilCodebases; }
  188. public:
  189. //
  190. // Short path data
  191. //
  192. BOOL SetShortManifestPath(IN const CBaseStringBuffer &rcbuffShortManifestPath) { return m_buffShortManifestName.Win32Assign(rcbuffShortManifestPath); }
  193. const CBaseStringBuffer &GetShortManifestPath() const { return m_buffShortManifestName; }
  194. BOOL SetShortCatalogPath(IN const CBaseStringBuffer &rcbuffShortCatalogPath) { return m_buffShortCatalogName.Win32Assign(rcbuffShortCatalogPath); }
  195. const CBaseStringBuffer &GetShortCatalogPath() const { return this->m_buffShortCatalogName; };
  196. BOOL AddCodebase(
  197. const CBaseStringBuffer &rbuffReference,
  198. const CBaseStringBuffer &rbuffCodebase,
  199. const CBaseStringBuffer &rbuffPrompt );
  200. BOOL RemoveCodebase(const CBaseStringBuffer &rbuffReference, bool &rfRemoved);
  201. //
  202. // On-disk shortname?
  203. //
  204. BOOL SetInstalledDirShortName(const CBaseStringBuffer &rcbuffShortName) { return this->m_buffShortNameOnDisk.Win32Assign(rcbuffShortName); }
  205. const CBaseStringBuffer &GetInstalledDirShortName() const { return this->m_buffShortNameOnDisk; }
  206. //
  207. // Manifest hash?
  208. //
  209. BOOL SetManifestHash( const CFusionByteArray &rcbaManifestHash ) { return rcbaManifestHash.Win32Clone(this->m_baManifestSha1Hash); }
  210. const CFusionByteArray &GetManifestHash() const { return this->m_baManifestSha1Hash; }
  211. //
  212. // Identity
  213. //
  214. BOOL SetTextualIdentity( const CBaseStringBuffer &rcbuffIdentity ) { return m_buffTextualAssemblyIdentity.Win32Assign(rcbuffIdentity); }
  215. const CBaseStringBuffer &GetTextualIdentity() const { return this->m_buffTextualAssemblyIdentity; }
  216. //
  217. // Signer public key token
  218. //
  219. BOOL SetSignerPublicKeyTokenBits( const CFusionByteArray& rcbuffSignerPublicKeyBits );
  220. const CFusionByteArray& GetSignerPublicKeyTokenBits() const { return m_baSignerPublicKeyToken; }
  221. //
  222. // Dummy - Initialize() is what you -really- want.
  223. //
  224. CSecurityMetaData() { }
  225. BOOL Initialize();
  226. BOOL Initialize(const CSecurityMetaData &other);
  227. BOOL Initialize(const CBaseStringBuffer &rcbuffTextualIdentity);
  228. BOOL LoadFromRegistryKey(const CRegKey &rhkRegistryNode);
  229. #define SXSP_WRITE_PRIMARY_ASSEMBLY_INFO_INTO_REGISTRY_KEY_FLAG_REFRESH (0x00000001)
  230. BOOL WritePrimaryAssemblyInfoIntoRegistryKey(ULONG Flags, const CRegKey &rhkRegistryNode) const;
  231. BOOL WriteSecondaryAssemblyInfoIntoRegistryKey(const CRegKey &rhkRegistryNode) const;
  232. };