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.

278 lines
12 KiB

  1. #if !defined(_FUSION_SXS_NODEFACTORY_H_INCLUDED_)
  2. #define _FUSION_SXS_NODEFACTORY_H_INCLUDED_
  3. #pragma once
  4. #include "fusioneventlog.h"
  5. #include <windows.h>
  6. #include <sxsp.h>
  7. #include <ole2.h>
  8. #include <xmlparser.h>
  9. #include "fusionbuffer.h"
  10. #include "partialassemblyversion.h"
  11. #include "xmlns.h"
  12. #include "policystatement.h"
  13. #define ELEMENT_LEGAL_ATTRIBUTE_FLAG_IGNORE (0x00000001)
  14. #define ELEMENT_LEGAL_ATTRIBUTE_FLAG_REQUIRED (0x00000002)
  15. typedef struct _ELEMENT_LEGAL_ATTRIBUTE
  16. {
  17. DWORD m_dwFlags;
  18. PCATTRIBUTE_NAME_DESCRIPTOR m_pName;
  19. SXSP_GET_ATTRIBUTE_VALUE_VALIDATION_ROUTINE m_pfnValidator;
  20. DWORD m_dwValidatorFlags;
  21. } ELEMENT_LEGAL_ATTRIBUTE, PELEMENT_LEGAL_ATTRIBUTE;
  22. typedef const struct _ELEMENT_LEGAL_ATTRIBUTE *PCELEMENT_LEGAL_ATTRIBUTE;
  23. //
  24. // ISSUE: jonwis 3/9/2002 - Consider reordering member data to group member data
  25. // together rather than interspersing it with functions. Group larger
  26. // objects together at the front of the class, etc. to get a smaller
  27. // memory footprint
  28. //
  29. class __declspec(uuid("832ff3cf-05bd-4eda-962f-d0a5307d55ae"))
  30. CNodeFactory : public IXMLNodeFactory
  31. {
  32. public:
  33. CNodeFactory();
  34. ~CNodeFactory();
  35. BOOL Initialize(
  36. PACTCTXGENCTX ActCtxGenCtx,
  37. PASSEMBLY Assembly,
  38. PACTCTXCTB_ASSEMBLY_CONTEXT AssemblyContext
  39. );
  40. BOOL SetParseType(ULONG ParseType, ULONG PathType, const CBaseStringBuffer &buffFileName, const FILETIME &rftLastWriteTime);
  41. VOID ResetParseState();
  42. // IUnknown methods:
  43. STDMETHODIMP_(ULONG) AddRef() { return 1; }
  44. STDMETHODIMP_(ULONG) Release() { return 1; }
  45. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  46. // IXMLNodeFactory methods:
  47. STDMETHODIMP NotifyEvent(IXMLNodeSource *pSource, XML_NODEFACTORY_EVENT iEvt);
  48. STDMETHODIMP BeginChildren(IXMLNodeSource *pSource, XML_NODE_INFO *pNodeInfo);
  49. STDMETHODIMP EndChildren(IXMLNodeSource *pSource, BOOL fEmpty, XML_NODE_INFO *pNodeInfo);
  50. STDMETHODIMP Error(IXMLNodeSource *pSource, HRESULT hrErrorCode, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  51. STDMETHODIMP CreateNode(IXMLNodeSource *pSource, PVOID pNodeParent, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  52. HRESULT FirstCreateNodeCall(IXMLNodeSource *pSource, PVOID pNodeParent, USHORT NodeCount, const SXS_NODE_INFO *prgNodeInfo);
  53. enum
  54. {
  55. eValidateIdentity_VersionRequired = 0x00000001,
  56. eValidateIdentity_PoliciesNotAllowed = 0x00000002,
  57. eValidateIdentity_VersionNotAllowed = 0x00000008,
  58. };
  59. enum
  60. {
  61. eActualParseType_Undetermined,
  62. eActualParseType_Manifest,
  63. eActualParseType_PolicyManifest
  64. } m_IntuitedParseType;
  65. BOOL ValidateIdentity(DWORD Flags, ULONG Type, PCASSEMBLY_IDENTITY AssemblyIdentity);
  66. BOOL ValidateElementAttributes(PCSXS_NODE_INFO prgNodes, SIZE_T cNodes, PCELEMENT_LEGAL_ATTRIBUTE prgAttributes, UCHAR cAttributes);
  67. PCACTCTXCTB_PARSE_CONTEXT GetParseContext() const { return &m_ParseContext; }
  68. #if FUSION_XML_TREE
  69. HRESULT CreateXmlNode(PSXS_XML_NODE pParent, ULONG cNodes, XML_NODE_INFO **prgpNodes, PSXS_XML_NODE &rpNewNode);
  70. #endif // FUSION_XML_TREE
  71. // protected:
  72. PACTCTXGENCTX m_ActCtxGenCtx;
  73. PASSEMBLY m_Assembly;
  74. CXMLNamespaceManager m_XMLNamespaceManager;
  75. ULONG m_ParseType;
  76. bool m_fFirstCreateNodeCall;
  77. // We only track the state of the parse with respect to the tags that
  78. // we're interested in for metadata purposes. This amounts to just the
  79. // <assembly> tag, and the dependencies. We ignore the rest.
  80. enum XMLParseState
  81. {
  82. eNotParsing,
  83. eParsing_doc,
  84. eParsing_doc_assembly,
  85. eParsing_doc_assembly_assemblyIdentity,
  86. eParsing_doc_assembly_comInterfaceExternalProxyStub,
  87. eParsing_doc_assembly_description,
  88. eParsing_doc_assembly_dependency,
  89. eParsing_doc_assembly_dependency_dependentAssembly,
  90. eParsing_doc_assembly_dependency_dependentAssembly_assemblyIdentity,
  91. eParsing_doc_assembly_dependency_dependentAssembly_bindingRedirect,
  92. eParsing_doc_assembly_file,
  93. eParsing_doc_assembly_file_comClass,
  94. eParsing_doc_assembly_file_comClass_progid,
  95. eParsing_doc_assembly_file_comInterfaceProxyStub,
  96. eParsing_doc_assembly_file_typelib,
  97. eParsing_doc_assembly_file_windowClass,
  98. eParsing_doc_assembly_clrSurrogate,
  99. eParsing_doc_assembly_clrClass,
  100. eParsing_doc_assembly_clrClass_progid,
  101. eParsing_doc_assembly_noInherit,
  102. eParsing_doc_assembly_noInheritable,
  103. eParsing_doc_configuration,
  104. eParsing_doc_configuration_windows,
  105. eParsing_doc_configuration_windows_assemblyBinding,
  106. eParsing_doc_configuration_windows_assemblyBinding_publisherPolicy,
  107. eParsing_doc_configuration_windows_assemblyBinding_assemblyIdentity,
  108. eParsing_doc_configuration_windows_assemblyBinding_dependentAssembly,
  109. eParsing_doc_configuration_windows_assemblyBinding_dependentAssembly_assemblyIdentity,
  110. eParsing_doc_configuration_windows_assemblyBinding_dependentAssembly_bindingRedirect,
  111. eParsing_doc_configuration_windows_assemblyBinding_dependentAssembly_publisherPolicy,
  112. eFatalParseError,
  113. } m_xpsParseState;
  114. ULONG m_cUnknownChildDepth;
  115. PACTCTXCTB_ASSEMBLY_CONTEXT m_AssemblyContext;
  116. ACTCTXCTB_PARSE_CONTEXT m_ParseContext;
  117. CSmallStringBuffer m_buffElementPath;
  118. CStringBuffer m_buffCurrentFileName;
  119. PASSEMBLY_IDENTITY m_CurrentPolicyDependentAssemblyIdentity;
  120. CPolicyStatement *m_CurrentPolicyStatement;
  121. CCaseInsensitiveUnicodeStringPtrTable<CPolicyStatement> *m_pApplicationPolicyTable;
  122. CStringBuffer m_buffCurrentApplicationPolicyIdentityKey;
  123. bool m_fAssemblyFound;
  124. bool m_fIdentityFound;
  125. bool m_fIsDependencyOptional;
  126. bool m_fDependencyChildHit;
  127. bool m_fAssemblyIdentityChildOfDependenctAssemblyHit;
  128. bool m_fIsMetadataSatellite;
  129. bool m_fMetadataSatelliteAlreadyFound;
  130. bool m_fNoInheritableFound;
  131. HRESULT ConvertXMLNodeInfoToSXSNodeInfo(const XML_NODE_INFO *pNodeInfo, SXS_NODE_INFO & sxsNodeInfo);
  132. //
  133. // XML Parsing worker functions:
  134. //
  135. typedef BOOL (CNodeFactory::*XMLParserWorkerFunctionPtr)(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  136. BOOL XMLParser_Element_doc_assembly(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  137. BOOL XMLParser_Element_doc_assembly_noInherit(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  138. BOOL XMLParser_Element_doc_assembly_noInheritable(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  139. BOOL XMLParser_Element_doc_assembly_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  140. BOOL XMLParser_Element_doc_assembly_dependency(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  141. BOOL XMLParser_Element_doc_assembly_dependency_dependentAssembly(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  142. BOOL XMLParser_Element_doc_assembly_dependency_dependentAssembly_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  143. BOOL XMLParser_Element_doc_assembly_dependency_dependentAssembly_bindingRedirect(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  144. BOOL XMLParser_Element_doc_configuration(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  145. BOOL XMLParser_Element_doc_configuration_windows(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  146. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  147. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  148. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  149. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_publisherPolicy(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  150. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_assemblyIdentity(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  151. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_bindingRedirect(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  152. BOOL XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_publisherPolicy(USHORT cNumRecs, PCSXS_NODE_INFO prgNodeInfo);
  153. //
  154. // Parsing helper functions:
  155. //
  156. enum XMLAttributeType
  157. {
  158. eAttributeTypeString, // represented by a CStringBuffer
  159. eAttributeTypeVersion, // represented by a ASSEMBLY_VERSION
  160. };
  161. //
  162. // Parser datatype specific worker functions. The first two parameters
  163. // are combined to refer the member to actually modify. The third is the
  164. // character string to be used as the value of the attribute.
  165. //
  166. // As an optimization, the datatype worker function may modify/destroy
  167. // the value in the third parameter. For example, the worker function
  168. // which just copies a CStringBuffer to another CStringBuffer actually
  169. // uses the CStringBuffer::TakeValue() member which avoids performing
  170. // a dynamic allocation if the attribute value exceeded the non-dynamically
  171. // allocated portion of the CStringBuffer.
  172. //
  173. typedef BOOL (CNodeFactory::*XMLParserValueParserFunctionPtr)(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  174. BOOL XMLParser_Parse_String(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  175. BOOL XMLParser_Parse_Version(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  176. BOOL XMLParser_Parse_ULARGE_INTEGER(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  177. BOOL XMLParser_Parse_FILETIME(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  178. BOOL XMLParser_Parse_GUID(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  179. BOOL XMLParser_Parse_BLOB(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  180. BOOL XMLParser_Parse_InstallAction(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  181. BOOL XMLParser_Parse_Boolean(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  182. BOOL XMLParser_Parse_PartialAssemblyVersion(LPVOID pvDatum, BOOL fAlreadyFound, CBaseStringBuffer &rbuff);
  183. struct AttributeMapEntry
  184. {
  185. LPCWSTR m_pszAttributeName;
  186. SIZE_T m_cchAttributeName;
  187. SIZE_T m_offsetData;
  188. SIZE_T m_offsetIndicator;
  189. XMLParserValueParserFunctionPtr m_pfn;
  190. };
  191. BOOL ParseElementAttributes(
  192. USHORT cNumRecs,
  193. XML_NODE_INFO **prgpNodeInfo,
  194. SIZE_T cAttributeMapEntries,
  195. const AttributeMapEntry *prgEntries);
  196. HRESULT LogParseError(
  197. DWORD dwLastParseError,
  198. const UNICODE_STRING *p1 = NULL,
  199. const UNICODE_STRING *p2 = NULL,
  200. const UNICODE_STRING *p3 = NULL,
  201. const UNICODE_STRING *p4 = NULL,
  202. const UNICODE_STRING *p5 = NULL,
  203. const UNICODE_STRING *p6 = NULL,
  204. const UNICODE_STRING *p7 = NULL,
  205. const UNICODE_STRING *p8 = NULL,
  206. const UNICODE_STRING *p9 = NULL,
  207. const UNICODE_STRING *p10 = NULL,
  208. const UNICODE_STRING *p11 = NULL,
  209. const UNICODE_STRING *p12 = NULL,
  210. const UNICODE_STRING *p13 = NULL,
  211. const UNICODE_STRING *p14 = NULL,
  212. const UNICODE_STRING *p15 = NULL,
  213. const UNICODE_STRING *p16 = NULL,
  214. const UNICODE_STRING *p17 = NULL,
  215. const UNICODE_STRING *p18 = NULL,
  216. const UNICODE_STRING *p19 = NULL,
  217. const UNICODE_STRING *p20 = NULL
  218. );
  219. static VOID WINAPI ParseErrorCallback_MissingRequiredAttribute(
  220. PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  221. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  222. );
  223. static VOID WINAPI ParseErrorCallback_AttributeNotAllowed(
  224. IN PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  225. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  226. );
  227. static VOID WINAPI ParseErrorCallback_InvalidAttributeValue(
  228. IN PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  229. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  230. );
  231. private:
  232. CNodeFactory(const CNodeFactory &);
  233. void operator =(const CNodeFactory &);
  234. };
  235. #endif