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.

2896 lines
103 KiB

  1. /*
  2. Copyright (c) Microsoft Corporation
  3. */
  4. #include "stdinc.h"
  5. #include "actctxgenctx.h"
  6. //
  7. // ISSUE: jonwis 3/9/2002 - This file is full of missing parameter checking.
  8. //
  9. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Parameter checking (#1)
  10. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - FN_PROLOG/EPILOG (#2)
  11. #define DEFINE_ATTRIBUTE(attributeName, attributeType, typePrefix) \
  12. { \
  13. L ## #attributeName, \
  14. offsetof(CNodeFactory, m_ ## typePrefix ## _ ## attributeName), \
  15. offsetof(CNodeFactory, m_f ## attributeName ## _ ## Present), \
  16. &CNodeFactory::XMLParser_Parse_ ## attributeType \
  17. },
  18. const static ASSEMBLY_VERSION assemblyVersion0 = {0,0,0,0};
  19. typedef enum _in_xml_tag_when_identity_generated_{
  20. SXS_IN_INVALID_XML_TAG_WHEN_ASSEMBLY_IDENTITY_GENERATED,
  21. SXS_IN_ASSEMBLY_TAG,
  22. SXS_IN_DEPENDENCY_TAG
  23. }SXS_IN_XML_TAG_WHEN_IDENTITY_GENERATED;
  24. VOID
  25. SxspDbgPrintXmlNodeInfo(
  26. ULONG Level,
  27. XML_NODE_INFO *pNode
  28. );
  29. PCSTR
  30. SxspFormatXmlNodeType(
  31. DWORD dwType
  32. );
  33. struct EventIdErrorPair
  34. {
  35. DWORD dwEventId;
  36. LONG nError;
  37. };
  38. const static EventIdErrorPair eventIdToErrorMap[] =
  39. {
  40. #include "messages.hi" // generated from .x file, like .mc
  41. };
  42. // deliberately no extra paranetheses here
  43. #define NODEFACTORY_STRING_AND_LENGTH(x) x, NUMBER_OF(x) - 1
  44. const static SXS_NAME_LENGTH_PAIR IgnoredAttributesInDependencyTagForIdentity[]={
  45. //maybe more later
  46. { NODEFACTORY_STRING_AND_LENGTH(L"Description") }
  47. };
  48. const DWORD IGNORED_ATTRIBUTE_NUM_IN_DEPENDENCY_TAG = NUMBER_OF(IgnoredAttributesInDependencyTagForIdentity);
  49. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(baseInterface);
  50. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(clsid);
  51. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(description);
  52. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(flags);
  53. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(hash);
  54. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(hashalg);
  55. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(helpdir);
  56. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(iid);
  57. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(language);
  58. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(loadFrom);
  59. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(manifestVersion);
  60. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(metadataSatellite);
  61. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(name);
  62. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(newVersion);
  63. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(numMethods);
  64. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(oldVersion);
  65. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(optional);
  66. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(processorArchitecture);
  67. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(progid);
  68. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(proxyStubClsid32);
  69. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(publicKeyToken);
  70. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(publicKey);
  71. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(resourceid);
  72. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(runtimeVersion);
  73. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(size);
  74. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(threadingModel);
  75. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(tlbid);
  76. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(type);
  77. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(version);
  78. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(versioned);
  79. DECLARE_STD_ATTRIBUTE_NAME_DESCRIPTOR(apply);
  80. // How to interpret the parser worker rules here:
  81. //
  82. // First, the state of the parser must match m_xps for the rule to be considered.
  83. // If the value eNotParsing is in the table, it matches any current parser
  84. // state. Use this to globally ignore some particular tag type when
  85. // combined with a NULL m_pszTag and NULL m_pfn.
  86. // Second, the type of the tag from the XML parser must match m_dwType.
  87. // If m_pszTag is not NULL, a case-insensitive comparison is done between the
  88. // string m_pszTag points to and the tag from the XML parser. An m_pszTag
  89. // value of NULL matches any tag.
  90. // If the three criteria match, the worker function is called. The worker function
  91. // pointer may be NULL, in which case no action is taken. (This is useful for
  92. // callbacks from the parser about XML_WHITESPACE where we don't really have to do
  93. // anything at all.)
  94. //
  95. #define DEFINE_TAG_WORKER_IGNOREALLOFTYPE(dwType) { CNodeFactory::eNotParsing, (dwType), NULL, NULL, NULL, 0, 0, 0, NULL }
  96. //
  97. // Notes on use of the DEFINE_TAG_WORKER_ELEMENT() macro:
  98. //
  99. // The first parameter, sourceState, is part of the name of a XMLParseState
  100. // enumeration value. It is concatenated onto "eParsing" to form the name of
  101. // the state which the rule will match.
  102. //
  103. // The second parameter is both the text of the tag to match and is used to
  104. // form the name of the function to invoke if the rule matches. The tag is
  105. // compared case-insensitively, and the name of the member function invoked
  106. // is XMLParser_Element_ followed by the sourceState string followed by another
  107. // underscore, followed by the tagName string. So, for example, the following
  108. // rule:
  109. //
  110. // DEFINE_TAG_WORKER_ELEMENT(DepAssy, Version)
  111. //
  112. // says that when the parser is in the eParsingDepAssy state and a "Version"
  113. // tag is found, call the function CNodeFactory::XMLParser_Element_DepAssy_Version().
  114. //
  115. #define DEFINE_TAG_WORKER_ELEMENT(sourceState, tagName) \
  116. { \
  117. CNodeFactory::eParsing_ ## sourceState, \
  118. XML_ELEMENT, \
  119. SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE, \
  120. L ## #tagName, \
  121. s_rg_ ## sourceState ## _ ## tagName ## _attributes, \
  122. NUMBER_OF(SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE) - 1, \
  123. NUMBER_OF(L ## #tagName) - 1, \
  124. NUMBER_OF(s_rg_ ## sourceState ## _ ## tagName ## _attributes), \
  125. &CNodeFactory::XMLParser_Element_ ## sourceState ## _ ## tagName, \
  126. CNodeFactory::eParsing_ ## sourceState ## _ ## tagName \
  127. }
  128. #define DEFINE_TAG_WORKER_ELEMENT_NOCB(sourceState, tagName) \
  129. { \
  130. CNodeFactory::eParsing_ ## sourceState, \
  131. XML_ELEMENT, \
  132. SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE, \
  133. L ## #tagName, \
  134. s_rg_ ## sourceState ## _ ## tagName ## _attributes, \
  135. NUMBER_OF(SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE) - 1, \
  136. NUMBER_OF(L ## #tagName) - 1, \
  137. NUMBER_OF(s_rg_ ## sourceState ## _ ## tagName ## _attributes), \
  138. NULL, \
  139. CNodeFactory::eParsing_ ## sourceState ## _ ## tagName \
  140. }
  141. #define DEFINE_TAG_WORKER_ELEMENT_NONS(sourceState, tagName) \
  142. { \
  143. CNodeFactory::eParsing_ ## sourceState, \
  144. XML_ELEMENT, \
  145. NULL, \
  146. L ## #tagName, \
  147. s_rg_ ## sourceState ## _ ## tagName ## _attributes, \
  148. 0, \
  149. NUMBER_OF(L ## #tagName) - 1, \
  150. NUMBER_OF(s_rg_ ## sourceState ## _ ## tagName ## _attributes), \
  151. &CNodeFactory::XMLParser_Element_ ## sourceState ## _ ## tagName, \
  152. CNodeFactory::eParsing_ ## sourceState ## _ ## tagName \
  153. }
  154. #define BEGIN_ELEMENT_LEGAL_ATTRIBUTES(_element) \
  155. const static ELEMENT_LEGAL_ATTRIBUTE s_rg_ ## _element ## _attributes[] = { \
  156. { ELEMENT_LEGAL_ATTRIBUTE_FLAG_IGNORE, NULL, NULL },
  157. #define DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(attributeName, validatorFlags, validator) { ELEMENT_LEGAL_ATTRIBUTE_FLAG_REQUIRED, &s_AttributeName_ ## attributeName, validator, validatorFlags },
  158. #define DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(attributeName, validatorFlags, validator) { 0, &s_AttributeName_ ## attributeName, validator, validatorFlags },
  159. #define END_ELEMENT_LEGAL_ATTRIBUTES(_element) };
  160. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly)
  161. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(manifestVersion, 0, NULL)
  162. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly)
  163. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_description)
  164. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_description)
  165. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_noInherit)
  166. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_noInherit)
  167. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_noInheritable)
  168. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_noInheritable)
  169. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_assemblyIdentity)
  170. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  171. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(version, 0, NULL)
  172. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(type, 0, NULL)
  173. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(processorArchitecture, SXSP_VALIDATE_PROCESSOR_ARCHITECTURE_ATTRIBUTE_FLAG_WILDCARD_ALLOWED, &::SxspValidateProcessorArchitectureAttribute)
  174. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(publicKeyToken, 0, NULL)
  175. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(language, 0, &::SxspValidateLanguageAttribute)
  176. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(publicKey, 0, NULL)
  177. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_assemblyIdentity)
  178. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency)
  179. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(optional, 0, &::SxspValidateBoolAttribute)
  180. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency)
  181. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency_dependentAssembly)
  182. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency_dependentAssembly)
  183. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency_dependentAssembly_assemblyIdentity)
  184. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  185. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(type, 0, NULL)
  186. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(version, 0, NULL)
  187. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(processorArchitecture, SXSP_VALIDATE_PROCESSOR_ARCHITECTURE_ATTRIBUTE_FLAG_WILDCARD_ALLOWED, &::SxspValidateProcessorArchitectureAttribute)
  188. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(publicKeyToken, 0, NULL)
  189. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(language, SXSP_VALIDATE_LANGUAGE_ATTRIBUTE_FLAG_WILDCARD_ALLOWED, &::SxspValidateLanguageAttribute)
  190. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency_dependentAssembly_assemblyIdentity)
  191. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency_dependentAssembly_bindingRedirect)
  192. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(oldVersion, 0, NULL)
  193. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(newVersion, 0, NULL)
  194. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_dependency_dependentAssembly_bindingRedirect)
  195. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file)
  196. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  197. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(hash, 0, NULL)
  198. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(hashalg, 0, NULL)
  199. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(loadFrom, 0, NULL)
  200. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(size, 0, &::SxspValidateUnsigned64Attribute)
  201. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file)
  202. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_comClass)
  203. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(clsid, 0, &::SxspValidateGuidAttribute)
  204. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(threadingModel, 0, NULL)
  205. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(progid, 0, NULL)
  206. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(tlbid, 0, &::SxspValidateGuidAttribute)
  207. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(description, 0, NULL)
  208. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_comClass)
  209. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_comClass_progid)
  210. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_comClass_progid)
  211. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_clrClass)
  212. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  213. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(clsid, 0, &::SxspValidateGuidAttribute)
  214. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(progid, 0, NULL)
  215. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(tlbid, 0, &::SxspValidateGuidAttribute)
  216. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(description, 0, NULL)
  217. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(runtimeVersion, 0, NULL)
  218. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(threadingModel, 0, NULL)
  219. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_clrClass)
  220. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_clrSurrogate)
  221. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(clsid, 0, &::SxspValidateGuidAttribute)
  222. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  223. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(runtimeVersion, 0, NULL)
  224. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_clrSurrogate)
  225. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_clrClass_progid)
  226. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_clrClass_progid)
  227. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_comInterfaceProxyStub)
  228. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(iid, 0, &::SxspValidateGuidAttribute)
  229. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(tlbid, 0, &::SxspValidateGuidAttribute)
  230. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(name, 0, NULL)
  231. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(numMethods, 0, NULL)
  232. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(baseInterface, 0, &::SxspValidateGuidAttribute)
  233. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(proxyStubClsid32, 0, &::SxspValidateGuidAttribute)
  234. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(threadingModel, 0, NULL)
  235. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_comInterfaceProxyStub)
  236. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_typelib)
  237. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(tlbid, 0, &::SxspValidateGuidAttribute)
  238. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(version, 0, NULL)
  239. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(helpdir, 0, NULL)
  240. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(resourceid, 0, NULL)
  241. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(flags, 0, NULL)
  242. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_typelib)
  243. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_windowClass)
  244. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(versioned, 0, &::SxspValidateBoolAttribute)
  245. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_file_windowClass)
  246. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_comInterfaceExternalProxyStub)
  247. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(iid, 0, &::SxspValidateGuidAttribute)
  248. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  249. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(proxyStubClsid32, 0, &::SxspValidateGuidAttribute)
  250. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(tlbid, 0, &::SxspValidateGuidAttribute)
  251. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(numMethods, 0, NULL)
  252. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(baseInterface, 0, &::SxspValidateGuidAttribute)
  253. END_ELEMENT_LEGAL_ATTRIBUTES(doc_assembly_comInterfaceExternalProxyStub)
  254. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration)
  255. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration)
  256. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows)
  257. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows)
  258. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding)
  259. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding)
  260. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_assemblyIdentity)
  261. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  262. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(version, 0, NULL)
  263. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(type, 0, NULL)
  264. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(processorArchitecture, 0, &::SxspValidateProcessorArchitectureAttribute)
  265. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(publicKeyToken, 0, NULL)
  266. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(language, 0, &::SxspValidateLanguageAttribute)
  267. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_assemblyIdentity)
  268. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly_publisherPolicy)
  269. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(apply, 0, &::SxspValidateBoolAttribute)
  270. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly_publisherPolicy)
  271. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_publisherPolicy)
  272. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(apply, 0, &::SxspValidateBoolAttribute)
  273. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_publisherPolicy)
  274. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly)
  275. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly)
  276. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly_assemblyIdentity)
  277. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(name, 0, NULL)
  278. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(processorArchitecture, 0, &::SxspValidateProcessorArchitectureAttribute)
  279. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(type, 0, NULL)
  280. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(publicKeyToken, 0, NULL)
  281. DEFINE_ELEMENT_NONS_OPTIONAL_ATTRIBUTE(language, 0, &::SxspValidateLanguageAttribute)
  282. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly_assemblyIdentity)
  283. BEGIN_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly_bindingRedirect)
  284. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(oldVersion, 0, NULL)
  285. DEFINE_ELEMENT_NONS_REQUIRED_ATTRIBUTE(newVersion, 0, NULL)
  286. END_ELEMENT_LEGAL_ATTRIBUTES(doc_configuration_windows_assemblyBinding_dependentAssembly_bindingRedirect)
  287. static const struct
  288. {
  289. CNodeFactory::XMLParseState m_xpsOld;
  290. DWORD m_dwType;
  291. PCWSTR m_pszNamespace;
  292. PCWSTR m_pszName;
  293. PCELEMENT_LEGAL_ATTRIBUTE m_prgLegalAttributes;
  294. UCHAR m_cchNamespace; // We use UCHAR here just for greater data density. Changing this and rebuilding
  295. UCHAR m_cchName; // this module should work fine if you really need namespaces or names longer than
  296. // 255 characters.
  297. UCHAR m_cLegalAttributes;
  298. CNodeFactory::XMLParserWorkerFunctionPtr m_pfn;
  299. CNodeFactory::XMLParseState m_xpsNew;
  300. } s_rgWorkers[] =
  301. {
  302. DEFINE_TAG_WORKER_IGNOREALLOFTYPE(XML_WHITESPACE),
  303. DEFINE_TAG_WORKER_IGNOREALLOFTYPE(XML_COMMENT),
  304. DEFINE_TAG_WORKER_ELEMENT(doc, assembly),
  305. DEFINE_TAG_WORKER_ELEMENT(doc_assembly, assemblyIdentity),
  306. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly, description),
  307. DEFINE_TAG_WORKER_ELEMENT(doc_assembly, noInherit),
  308. DEFINE_TAG_WORKER_ELEMENT(doc_assembly, noInheritable),
  309. DEFINE_TAG_WORKER_ELEMENT(doc_assembly, dependency),
  310. DEFINE_TAG_WORKER_ELEMENT(doc_assembly_dependency, dependentAssembly),
  311. DEFINE_TAG_WORKER_ELEMENT(doc_assembly_dependency_dependentAssembly, assemblyIdentity),
  312. DEFINE_TAG_WORKER_ELEMENT(doc_assembly_dependency_dependentAssembly, bindingRedirect),
  313. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly, file),
  314. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly_file, comClass),
  315. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly_file_comClass, progid),
  316. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly, clrClass),
  317. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly_clrClass, progid),
  318. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly_file, comInterfaceProxyStub),
  319. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly_file, typelib),
  320. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly_file, windowClass),
  321. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly, clrSurrogate),
  322. DEFINE_TAG_WORKER_ELEMENT_NOCB(doc_assembly, comInterfaceExternalProxyStub),
  323. // All app config productions go here, just for neatness
  324. DEFINE_TAG_WORKER_ELEMENT_NONS(doc, configuration),
  325. DEFINE_TAG_WORKER_ELEMENT_NONS(doc_configuration, windows),
  326. DEFINE_TAG_WORKER_ELEMENT(doc_configuration_windows, assemblyBinding),
  327. DEFINE_TAG_WORKER_ELEMENT(doc_configuration_windows_assemblyBinding, assemblyIdentity),
  328. DEFINE_TAG_WORKER_ELEMENT(doc_configuration_windows_assemblyBinding, dependentAssembly),
  329. DEFINE_TAG_WORKER_ELEMENT(doc_configuration_windows_assemblyBinding, publisherPolicy),
  330. DEFINE_TAG_WORKER_ELEMENT(doc_configuration_windows_assemblyBinding_dependentAssembly, assemblyIdentity),
  331. DEFINE_TAG_WORKER_ELEMENT(doc_configuration_windows_assemblyBinding_dependentAssembly, bindingRedirect),
  332. DEFINE_TAG_WORKER_ELEMENT(doc_configuration_windows_assemblyBinding_dependentAssembly, publisherPolicy),
  333. };
  334. BOOL
  335. SxspIsNamespaceDeclaration(XML_NODE_INFO *pNodeInfo)
  336. {
  337. FN_TRACE();
  338. ASSERT(pNodeInfo->dwType == XML_ATTRIBUTE);
  339. //
  340. // ISSUE: jonwis 3/8/2002 - Could use FusionpCompareString rather than doing it the 'hard way'
  341. //
  342. if (pNodeInfo->ulLen >= 5)
  343. { // "xmlns" : prefix for namespace declaration, default ns or non-default ns
  344. if ((pNodeInfo->pwcText[0] == L'x') &&
  345. (pNodeInfo->pwcText[1] == L'm') &&
  346. (pNodeInfo->pwcText[2] == L'l') &&
  347. (pNodeInfo->pwcText[3] == L'n') &&
  348. (pNodeInfo->pwcText[4] == L's'))
  349. {
  350. if (pNodeInfo->ulLen == 5) // like xmlns="", default ns declaration
  351. return TRUE;
  352. else
  353. if (pNodeInfo->pwcText[5] == L':')
  354. return TRUE;
  355. }
  356. }
  357. return FALSE;
  358. }
  359. //In this function, two tasks:
  360. // 1) verify PublicKey and StrongName
  361. // 2) create AssemblyIdentity based on xmlnode array
  362. // 3) for (name, processorArchitecure, version. langid) they would be unique with SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE
  363. // 4) if there are dup triples {nsURL, name, value), only one is count, this is done with SxsCreateAssemblyIdentity
  364. BOOL
  365. SxspCreateAssemblyIdentityFromIdentityElement(
  366. DWORD Flags,
  367. PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  368. ULONG Type,
  369. PASSEMBLY_IDENTITY *AssemblyIdentityOut,
  370. DWORD cNumRecs,
  371. PCSXS_NODE_INFO prgNodeInfo
  372. )
  373. {
  374. BOOL fSuccess = FALSE;
  375. FN_TRACE_WIN32(fSuccess);
  376. DWORD i;
  377. //
  378. // ISSUE: 3/9/2002 - Consider using a smart pointer here for AssemblyIdentity
  379. // CSxsPointerWithNamedDestructor<ASSEMBLY_IDENTITY, ::SxsDestroyAssemblyIdentity> AssemblyIdentity;
  380. //
  381. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Leaking memory here if AssemblyIdentity isn't cleaned up (#3)
  382. PASSEMBLY_IDENTITY AssemblyIdentity = NULL;
  383. CStringBuffer buffValue;
  384. if (AssemblyIdentityOut != NULL)
  385. *AssemblyIdentityOut = NULL;
  386. PARAMETER_CHECK((Flags & ~(SXSP_CREATE_ASSEMBLY_IDENTITY_FROM_IDENTITY_TAG_FLAG_VERIFY_PUBLIC_KEY_IF_PRESENT)) == 0);
  387. PARAMETER_CHECK((Type == ASSEMBLY_IDENTITY_TYPE_DEFINITION) || (Type == ASSEMBLY_IDENTITY_TYPE_REFERENCE));
  388. PARAMETER_CHECK(AssemblyIdentityOut != NULL);
  389. PARAMETER_CHECK(prgNodeInfo != NULL);
  390. PARAMETER_CHECK(prgNodeInfo[0].Type == XML_ELEMENT);
  391. IFW32FALSE_EXIT(::SxsCreateAssemblyIdentity(0, Type, &AssemblyIdentity, 0, NULL));
  392. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Why not use a 'for' loop? (#4)
  393. i = 1;
  394. while (i<cNumRecs)
  395. {
  396. ULONG j;
  397. INTERNAL_ERROR_CHECK(prgNodeInfo[i].Type == XML_ATTRIBUTE);
  398. buffValue.Clear();
  399. //
  400. // ISSUE: jonwis 3/9/2002 - Consider moving this to a for() loop for optimization's sake:
  401. // for (j = i + 1; ((j < cNumRec) && (prgNodeInfo[j].Type == XML_PCDATA)); j++)
  402. //
  403. j = i + 1;
  404. while ((j < cNumRecs) && (prgNodeInfo[j].Type == XML_PCDATA))
  405. {
  406. IFW32FALSE_EXIT(buffValue.Win32Append(prgNodeInfo[j].pszText, prgNodeInfo[j].cchText));
  407. j++;
  408. }
  409. // if this is a special attribute, we'll handle it ... specially.
  410. if ((prgNodeInfo[i].NamespaceStringBuf.Cch() == 0) &&
  411. (::FusionpCompareStrings(
  412. SXS_ASSEMBLY_IDENTITY_STD_ATTRIBUTE_NAME_PUBLIC_KEY,
  413. SXS_ASSEMBLY_IDENTITY_STD_ATTRIBUTE_NAME_PUBLIC_KEY_CCH,
  414. prgNodeInfo[i].pszText,
  415. prgNodeInfo[i].cchText,
  416. false) == 0))
  417. {// ignore publicKey if it appears in assembly identity
  418. }
  419. else
  420. {
  421. //
  422. // ISSUE: jonwis 3/9/2002 - Consider moving this to initialization rather than assignment
  423. //
  424. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Compiler is better than you are (#5)
  425. ASSEMBLY_IDENTITY_ATTRIBUTE Attribute;
  426. Attribute.Flags = 0;
  427. Attribute.NamespaceCch = prgNodeInfo[i].NamespaceStringBuf.Cch();
  428. Attribute.Namespace = prgNodeInfo[i].NamespaceStringBuf;
  429. Attribute.NameCch = prgNodeInfo[i].cchText;
  430. Attribute.Name = prgNodeInfo[i].pszText;
  431. Attribute.ValueCch = buffValue.Cch();
  432. Attribute.Value = buffValue;
  433. IFW32FALSE_EXIT(::SxsInsertAssemblyIdentityAttribute(0, AssemblyIdentity, &Attribute));
  434. }
  435. i = j;
  436. }
  437. *AssemblyIdentityOut = AssemblyIdentity;
  438. AssemblyIdentity = NULL;
  439. fSuccess = TRUE;
  440. Exit:
  441. if (AssemblyIdentity != NULL)
  442. ::SxsDestroyAssemblyIdentity(AssemblyIdentity);
  443. return fSuccess;
  444. }
  445. //
  446. // ISSUE: jonwis 3/9/2002 - Consider reordering initializers to read more like what's in the
  447. // class def for simpler reading. Also consider using a smart-pointer object to manage
  448. // the m_Assembly, rather than doing our own management. Same for the ASSEMBLY_IDENTITY
  449. // m_CurrentPolicyDependentAssemblyIdentity
  450. //
  451. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Odd ordering of initializers (#6)
  452. CNodeFactory::CNodeFactory()
  453. : m_ActCtxGenCtx(NULL),
  454. m_Assembly(NULL),
  455. m_fFirstCreateNodeCall(true),
  456. m_cUnknownChildDepth(0),
  457. m_xpsParseState(eParsing_doc),
  458. m_fAssemblyFound(false),
  459. m_fIdentityFound(false),
  460. m_AssemblyContext(NULL),
  461. m_CurrentPolicyDependentAssemblyIdentity(NULL),
  462. m_CurrentPolicyStatement(NULL),
  463. m_IntuitedParseType(eActualParseType_Undetermined),
  464. m_pApplicationPolicyTable(NULL),
  465. m_fNoInheritableFound(false)
  466. {
  467. m_ParseContext.XMLElementDepth = 0;
  468. m_ParseContext.ElementPath = NULL;
  469. m_ParseContext.ElementPathCch = 0;
  470. m_ParseContext.ElementName = NULL;
  471. m_ParseContext.ElementPathCch = 0;
  472. m_ParseContext.ElementHash = 0;
  473. }
  474. CNodeFactory::~CNodeFactory()
  475. {
  476. CSxsPreserveLastError ple;
  477. if ((m_CurrentPolicyStatement != NULL) &&
  478. (m_CurrentPolicyDependentAssemblyIdentity != NULL) &&
  479. (m_pApplicationPolicyTable != NULL))
  480. {
  481. #if 1
  482. if (m_pApplicationPolicyTable->Find(m_buffCurrentApplicationPolicyIdentityKey, m_CurrentPolicyStatement))
  483. m_CurrentPolicyStatement = NULL;
  484. #else
  485. CStringBuffer EncodedPolicyIdentity;
  486. if (::SxspGenerateTextuallyEncodedPolicyIdentityFromAssemblyIdentity(
  487. SXSP_GENERATE_TEXTUALLY_ENCODED_POLICY_IDENTITY_FROM_ASSEMBLY_IDENTITY_FLAG_OMIT_ENTIRE_VERSION,
  488. m_CurrentPolicyDependentAssemblyIdentity,
  489. EncodedPolicyIdentity,
  490. NULL))
  491. {
  492. if (m_pApplicationPolicyTable->Find(EncodedPolicyIdentity, m_CurrentPolicyStatement))
  493. {
  494. m_CurrentPolicyStatement = NULL; // leave the cleanup work to outer destructor
  495. }
  496. }
  497. #endif
  498. }
  499. FUSION_DELETE_SINGLETON(m_CurrentPolicyStatement);
  500. if (m_CurrentPolicyDependentAssemblyIdentity != NULL)
  501. ::SxsDestroyAssemblyIdentity(m_CurrentPolicyDependentAssemblyIdentity);
  502. if (m_Assembly != NULL)
  503. {
  504. m_Assembly->Release();
  505. m_Assembly = NULL;
  506. }
  507. ple.Restore();
  508. }
  509. BOOL
  510. CNodeFactory::Initialize(
  511. PACTCTXGENCTX ActCtxGenCtx,
  512. PASSEMBLY Assembly,
  513. PACTCTXCTB_ASSEMBLY_CONTEXT AssemblyContext
  514. )
  515. {
  516. FN_PROLOG_WIN32
  517. PARAMETER_CHECK(Assembly != NULL);
  518. IFW32FALSE_EXIT(m_XMLNamespaceManager.Initialize());
  519. m_ActCtxGenCtx = ActCtxGenCtx;
  520. Assembly->AddRef();
  521. if (m_Assembly != NULL)
  522. m_Assembly->Release();
  523. m_Assembly = Assembly;
  524. m_AssemblyContext = AssemblyContext;
  525. m_ParseContext.AssemblyContext = AssemblyContext;
  526. m_ParseContext.ErrorCallbacks.MissingRequiredAttribute = &CNodeFactory::ParseErrorCallback_MissingRequiredAttribute;
  527. m_ParseContext.ErrorCallbacks.AttributeNotAllowed = &CNodeFactory::ParseErrorCallback_AttributeNotAllowed;
  528. m_ParseContext.ErrorCallbacks.InvalidAttributeValue = &CNodeFactory::ParseErrorCallback_InvalidAttributeValue;
  529. m_ParseContext.SourceFilePathType = AssemblyContext->ManifestPathType;
  530. m_ParseContext.SourceFile = AssemblyContext->ManifestPath;
  531. m_ParseContext.SourceFileCch = AssemblyContext->ManifestPathCch;
  532. m_ParseContext.LineNumber = 0;
  533. FN_EPILOG
  534. }
  535. VOID
  536. CNodeFactory::ResetParseState()
  537. {
  538. m_fFirstCreateNodeCall = true;
  539. m_fAssemblyFound = false;
  540. m_fIdentityFound = false;
  541. m_fNoInheritableFound = false;
  542. FUSION_DELETE_SINGLETON(m_CurrentPolicyStatement);
  543. m_CurrentPolicyStatement = NULL;
  544. ::SxsDestroyAssemblyIdentity(m_CurrentPolicyDependentAssemblyIdentity);
  545. m_CurrentPolicyDependentAssemblyIdentity = NULL;
  546. }
  547. HRESULT
  548. CNodeFactory::QueryInterface(
  549. REFIID riid,
  550. LPVOID *ppvObj
  551. )
  552. {
  553. FN_PROLOG_HR
  554. IUnknown *pIUnknown = NULL;
  555. if (ppvObj != NULL)
  556. *ppvObj = NULL;
  557. else
  558. ORIGINATE_HR_FAILURE_AND_EXIT(CNodeFactory::QueryInterface, E_POINTER);
  559. if (riid == __uuidof(this))
  560. pIUnknown = this;
  561. else if ((riid == IID_IUnknown) || (riid == IID_IXMLNodeFactory))
  562. pIUnknown = static_cast<IXMLNodeFactory *>(this);
  563. else
  564. ORIGINATE_HR_FAILURE_AND_EXIT(CNodeFactory::QueryInterface, E_NOINTERFACE);
  565. pIUnknown->AddRef();
  566. *ppvObj = pIUnknown;
  567. FN_EPILOG
  568. }
  569. HRESULT
  570. CNodeFactory::NotifyEvent(
  571. IXMLNodeSource *pSource,
  572. XML_NODEFACTORY_EVENT iEvt
  573. )
  574. {
  575. return NOERROR;
  576. }
  577. HRESULT
  578. CNodeFactory::ConvertXMLNodeInfoToSXSNodeInfo(
  579. const XML_NODE_INFO *pNodeInfo,
  580. SXS_NODE_INFO &rSXSNodeInfo
  581. )
  582. {
  583. //
  584. // ISSUE: jonwis 3/9/2002 - Consider filling out a private SXS_NODE_INFO and assigning it to
  585. // the output SXSNodeInfo on success.
  586. //
  587. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Use a private SXS_NODE_INFO (#7)
  588. HRESULT hr = NOERROR;
  589. FN_TRACE_HR(hr);
  590. INTERNAL_ERROR_CHECK(pNodeInfo != NULL);
  591. rSXSNodeInfo.Size = pNodeInfo->dwSize;
  592. rSXSNodeInfo.Type = pNodeInfo->dwType;
  593. switch (pNodeInfo->dwType)
  594. {
  595. case XML_ELEMENT:
  596. {
  597. SIZE_T cchNamespacePrefix;
  598. IFCOMFAILED_EXIT(
  599. m_XMLNamespaceManager.Map(
  600. 0,
  601. pNodeInfo,
  602. &rSXSNodeInfo.NamespaceStringBuf,
  603. &cchNamespacePrefix));
  604. // +1 to skip colon
  605. rSXSNodeInfo.pszText = pNodeInfo->pwcText + ((cchNamespacePrefix != 0) ? (cchNamespacePrefix + 1) : 0);
  606. rSXSNodeInfo.cchText = pNodeInfo->ulLen - ((cchNamespacePrefix != 0) ? (cchNamespacePrefix + 1) : 0);
  607. break;
  608. }
  609. case XML_ATTRIBUTE:
  610. {
  611. SIZE_T cchNamespacePrefix;
  612. //
  613. // ISSUE: jonwis 3/9/2002 - I think this is questionable. Why are we allowing through
  614. // attributes named "xmlns:" and "xmlns="? Shouldn't these have been fixed earlier?
  615. //
  616. // ISSUE:2002-3-29:jonwis - I also think that this is a gross method of doing this work. Calling
  617. // wcslen on constants is a "bad thing." There's got to be something better we
  618. // could be doing here.
  619. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Wierd passthroughs of xmlns variants
  620. // if this is a namespace definition, ignore
  621. const PCWSTR pwcText = pNodeInfo->pwcText;
  622. if ((pwcText[0] == L'x') &&
  623. (pwcText[1] == L'm') &&
  624. (pwcText[2] == L'l') &&
  625. (pwcText[3] == L'n') &&
  626. (pwcText[4] == L's') &&
  627. ((pwcText[5] == L':') ||
  628. (pwcText[5] == L'=')))
  629. {
  630. rSXSNodeInfo.pszText = pNodeInfo->pwcText;
  631. rSXSNodeInfo.cchText = pNodeInfo->ulLen;
  632. }
  633. else
  634. {
  635. IFCOMFAILED_EXIT(
  636. m_XMLNamespaceManager.Map(
  637. CXMLNamespaceManager::eMapFlag_DoNotApplyDefaultNamespace,
  638. pNodeInfo,
  639. &rSXSNodeInfo.NamespaceStringBuf,
  640. &cchNamespacePrefix));
  641. // +1 to skip colon
  642. rSXSNodeInfo.pszText = pNodeInfo->pwcText + ((cchNamespacePrefix != 0) ? (cchNamespacePrefix + 1) : 0);
  643. rSXSNodeInfo.cchText = pNodeInfo->ulLen - ((cchNamespacePrefix != 0) ? (cchNamespacePrefix + 1) : 0);
  644. }
  645. break;
  646. }
  647. default:
  648. // Otherwise we'll assume there's no namespace processing to do...
  649. rSXSNodeInfo.NamespaceStringBuf.Clear();
  650. rSXSNodeInfo.pszText = pNodeInfo->pwcText;
  651. rSXSNodeInfo.cchText = pNodeInfo->ulLen;
  652. break;
  653. }
  654. FN_EPILOG
  655. }
  656. HRESULT
  657. CNodeFactory::BeginChildren(
  658. IXMLNodeSource *pSource,
  659. XML_NODE_INFO *pNodeInfo
  660. )
  661. {
  662. FN_PROLOG_HR
  663. ULONG i = 0;
  664. SXS_NODE_INFO SXSNodeInfo;
  665. IFCOMFAILED_EXIT(m_XMLNamespaceManager.OnBeginChildren(pSource, pNodeInfo));
  666. IFCOMFAILED_EXIT(this->ConvertXMLNodeInfoToSXSNodeInfo(pNodeInfo, SXSNodeInfo));
  667. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  668. {
  669. IFW32FALSE_EXIT(
  670. m_ActCtxGenCtx->m_Contributors[i].Fire_BeginChildren(
  671. m_ActCtxGenCtx,
  672. m_AssemblyContext,
  673. &m_ParseContext,
  674. &SXSNodeInfo));
  675. }
  676. FN_EPILOG
  677. }
  678. HRESULT
  679. CNodeFactory::EndChildren(
  680. IXMLNodeSource *pSource,
  681. BOOL Empty,
  682. XML_NODE_INFO *pNodeInfo
  683. )
  684. {
  685. FN_PROLOG_HR
  686. ULONG i = 0;
  687. PWSTR Bang = NULL;
  688. SXS_NODE_INFO SXSNodeInfo;
  689. // Short-circuit PIs, XML-decls, whitespace and comments
  690. if ((pNodeInfo->dwType == XML_PI) ||
  691. (pNodeInfo->dwType == XML_XMLDECL) ||
  692. (pNodeInfo->dwType == XML_COMMENT) ||
  693. (pNodeInfo->dwType == XML_WHITESPACE))
  694. {
  695. FN_SUCCESSFUL_EXIT();
  696. }
  697. IFCOMFAILED_EXIT(m_XMLNamespaceManager.OnEndChildren(pSource, Empty, pNodeInfo));
  698. // We hit the end of something; if we're skipping stuff, we're one level back towards
  699. // paying attention.
  700. if (m_cUnknownChildDepth != 0)
  701. {
  702. m_cUnknownChildDepth--;
  703. }
  704. else
  705. {
  706. ULONG j;
  707. for (j=0; j<NUMBER_OF(s_rgWorkers); j++)
  708. {
  709. if (s_rgWorkers[j].m_xpsNew == m_xpsParseState)
  710. {
  711. m_xpsParseState = s_rgWorkers[j].m_xpsOld;
  712. break;
  713. }
  714. }
  715. if (j == NUMBER_OF(s_rgWorkers))
  716. {
  717. ::FusionpDbgPrintEx(
  718. FUSION_DBG_LEVEL_ERROR,
  719. "SXS.DLL: %s() called when we were not expecting it. m_xpsParseState = %d\n", __FUNCTION__, m_xpsParseState);
  720. INTERNAL_ERROR_CHECK(FALSE);
  721. // Hey, how the heck did we get here?
  722. }
  723. // One time end-of-manifest checks...
  724. if (m_xpsParseState == eParsing_doc)
  725. {
  726. switch (m_ParseType)
  727. {
  728. default:
  729. INTERNAL_ERROR_CHECK(false);
  730. break;
  731. case XML_FILE_TYPE_COMPONENT_CONFIGURATION:
  732. case XML_FILE_TYPE_APPLICATION_CONFIGURATION:
  733. break;
  734. case XML_FILE_TYPE_MANIFEST:
  735. // If this is not the root assembly, this is not a noInherit actctx and the noInheritable
  736. // element was not found, issue an error.
  737. if (((m_AssemblyContext->Flags & ACTCTXCTB_ASSEMBLY_CONTEXT_IS_ROOT_ASSEMBLY) == 0) &&
  738. m_ActCtxGenCtx->m_NoInherit &&
  739. !m_fNoInheritableFound)
  740. {
  741. this->LogParseError(MSG_SXS_NOINHERIT_REQUIRES_NOINHERITABLE);
  742. ORIGINATE_WIN32_FAILURE_AND_EXIT(NoInheritRequiresNoInheritable, ERROR_SXS_MANIFEST_PARSE_ERROR);
  743. }
  744. break;
  745. }
  746. }
  747. }
  748. if (pNodeInfo->dwType != XML_XMLDECL)
  749. {
  750. IFCOMFAILED_EXIT(this->ConvertXMLNodeInfoToSXSNodeInfo(pNodeInfo, SXSNodeInfo));
  751. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  752. {
  753. IFW32FALSE_EXIT(
  754. m_ActCtxGenCtx->m_Contributors[i].Fire_EndChildren(
  755. m_ActCtxGenCtx,
  756. m_AssemblyContext,
  757. &m_ParseContext,
  758. Empty,
  759. &SXSNodeInfo));
  760. }
  761. INTERNAL_ERROR_CHECK(m_ParseContext.XMLElementDepth != 0);
  762. //
  763. // ISSUE: jonwis 3/9/2002 - Comment this better! It's hard to figure out what this is doing.
  764. // It's apparently turning "foo!bar!bas" into "foo!bar", and "foo" into "". This
  765. // could probably be done much better with some cleaning.
  766. //
  767. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Cleanup this string-fixer code (#9)
  768. m_ParseContext.XMLElementDepth--;
  769. Bang = wcsrchr(m_buffElementPath, L'!');
  770. INTERNAL_ERROR_CHECK(((Bang == NULL) == (m_ParseContext.XMLElementDepth == 0)));
  771. if (Bang != NULL)
  772. {
  773. m_buffElementPath.Left(Bang - m_buffElementPath);
  774. m_ParseContext.ElementPathCch = m_buffElementPath.Cch();
  775. m_ParseContext.ElementPath = m_buffElementPath;
  776. m_ParseContext.ElementName = wcsrchr(m_buffElementPath, L'!');
  777. if (m_ParseContext.ElementName == NULL)
  778. {
  779. m_ParseContext.ElementName = m_buffElementPath;
  780. m_ParseContext.ElementNameCch = m_buffElementPath.Cch();
  781. }
  782. else
  783. {
  784. m_ParseContext.ElementName++;
  785. m_ParseContext.ElementNameCch = m_buffElementPath.Cch() - (m_ParseContext.ElementName - m_buffElementPath);
  786. }
  787. IFW32FALSE_ORIGINATE_AND_EXIT(
  788. ::SxspHashString(
  789. m_buffElementPath,
  790. m_ParseContext.ElementPathCch,
  791. &m_ParseContext.ElementHash,
  792. false));
  793. }
  794. else
  795. {
  796. m_buffElementPath.Clear();
  797. m_ParseContext.ElementPath = NULL;
  798. m_ParseContext.ElementPathCch = 0;
  799. m_ParseContext.ElementName = NULL;
  800. m_ParseContext.ElementNameCch = 0;
  801. m_ParseContext.ElementHash = 0;
  802. m_ParseContext.XMLElementDepth = 0;
  803. }
  804. }
  805. FN_EPILOG
  806. }
  807. HRESULT
  808. CNodeFactory::Error(
  809. IXMLNodeSource *pSource,
  810. HRESULT hrErrorCode,
  811. USHORT cNumRecs,
  812. XML_NODE_INFO **apNodeInfo
  813. )
  814. {
  815. CSxsPreserveLastError ple;
  816. ::FusionpConvertCOMFailure(hrErrorCode);
  817. ::FusionpSetLastErrorFromHRESULT(hrErrorCode);
  818. this->LogParseError(MSG_SXS_WIN32_ERROR_MSG_WHEN_PARSING_MANIFEST, CEventLogLastError());
  819. ple.Restore();
  820. return NOERROR;
  821. }
  822. HRESULT
  823. CNodeFactory::FirstCreateNodeCall(
  824. IXMLNodeSource *pSource,
  825. PVOID pNodeParent,
  826. USHORT NodeCount,
  827. const SXS_NODE_INFO *prgNodeInfo
  828. )
  829. {
  830. FN_PROLOG_HR
  831. ULONG i = 0;
  832. bool fGotGoodManifestVersion = false;
  833. bool fGotAnyManifestVersion = false;
  834. // It's our first IXMLNodeFactory::CreateNode() call. This had better
  835. // be an <ASSEMBLY MANIFESTVERSION="1.0" ...> deal.
  836. for (i=0; i<NodeCount; i++)
  837. {
  838. if (prgNodeInfo[i].Type == XML_ELEMENT)
  839. {
  840. INTERNAL_ERROR_CHECK(i == 0);
  841. switch (m_ParseType)
  842. {
  843. default:
  844. INTERNAL_ERROR_CHECK(false);
  845. break;
  846. //
  847. // ISSUE: jonwis 3/9/2002 - My goodness, this is gross. Use FusionEqualStrings
  848. // instead. Doing memcmps between strings is totally bogus.
  849. //
  850. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Memcmping here is bogus
  851. case XML_FILE_TYPE_MANIFEST:
  852. case XML_FILE_TYPE_COMPONENT_CONFIGURATION:
  853. if ((prgNodeInfo[i].cchText != (NUMBER_OF(SXS_ASSEMBLY_MANIFEST_STD_ELEMENT_NAME_ASSEMBLY) - 1)) ||
  854. (prgNodeInfo[i].NamespaceStringBuf.Cch() != (NUMBER_OF(SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE) - 1)) ||
  855. (memcmp(prgNodeInfo[i].pszText, SXS_ASSEMBLY_MANIFEST_STD_ELEMENT_NAME_ASSEMBLY, prgNodeInfo[i].cchText * sizeof(WCHAR)) != 0) ||
  856. (memcmp(prgNodeInfo[i].NamespaceStringBuf, SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE, prgNodeInfo[i].NamespaceStringBuf.Cch() * sizeof(WCHAR)) != 0))
  857. {
  858. IFCOMFAILED_EXIT(this->LogParseError(MSG_SXS_MANIFEST_INCORRECT_ROOT_ELEMENT));
  859. }
  860. break;
  861. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Memcmping here is bogus
  862. case XML_FILE_TYPE_APPLICATION_CONFIGURATION:
  863. if ((prgNodeInfo[i].cchText != SXS_APPLICATION_CONFIGURATION_MANIFEST_STD_ELEMENT_NAME_CONFIGURATION_CCH) ||
  864. (prgNodeInfo[i].NamespaceStringBuf.Cch() != 0) ||
  865. (memcmp(prgNodeInfo[i].pszText, SXS_APPLICATION_CONFIGURATION_MANIFEST_STD_ELEMENT_NAME_CONFIGURATION,
  866. SXS_APPLICATION_CONFIGURATION_MANIFEST_STD_ELEMENT_NAME_CONFIGURATION_CCH * sizeof(WCHAR)) != 0))
  867. {
  868. IFCOMFAILED_EXIT(this->LogParseError(MSG_SXS_MANIFEST_INCORRECT_ROOT_ELEMENT));
  869. }
  870. break;
  871. }
  872. }
  873. else if (prgNodeInfo[i].Type == XML_ATTRIBUTE)
  874. {
  875. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Memcmping here is bogus
  876. if ((prgNodeInfo[i].cchText == (NUMBER_OF(SXS_ASSEMBLY_MANIFEST_STD_ATTRIBUTE_NAME_MANIFEST_VERSION) - 1)) &&
  877. (prgNodeInfo[i].NamespaceStringBuf.Cch() == 0) &&
  878. (memcmp(prgNodeInfo[i].pszText, SXS_ASSEMBLY_MANIFEST_STD_ATTRIBUTE_NAME_MANIFEST_VERSION, prgNodeInfo[i].cchText * sizeof(WCHAR)) == 0))
  879. {
  880. fGotAnyManifestVersion = true;
  881. ULONG j = i + 1;
  882. //
  883. // ISSUE: jonwis 3/9/2002 - Any reason these can't be a single if statement?
  884. // - Oh, an NO MEMCMPING STRINGS
  885. //
  886. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Memcmping here is bogus
  887. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Unrolled if (a&&b) is strange, but not wrong
  888. if (j < NodeCount)
  889. {
  890. if (prgNodeInfo[j].Type == XML_PCDATA)
  891. {
  892. if (prgNodeInfo[j].cchText == 3)
  893. {
  894. if (memcmp(prgNodeInfo[j].pszText, L"1.0", prgNodeInfo[j].cchText * sizeof(WCHAR)) == 0)
  895. {
  896. fGotGoodManifestVersion = true;
  897. }
  898. }
  899. }
  900. }
  901. }
  902. }
  903. }
  904. if ((m_ParseType == XML_FILE_TYPE_MANIFEST) ||
  905. (m_ParseType == XML_FILE_TYPE_COMPONENT_CONFIGURATION))
  906. {
  907. if (fGotAnyManifestVersion)
  908. {
  909. if (!fGotGoodManifestVersion)
  910. IFCOMFAILED_EXIT(this->LogParseError(MSG_SXS_MANIFEST_VERSION_ERROR));
  911. }
  912. else
  913. IFCOMFAILED_EXIT(this->LogParseError(MSG_SXS_MANIFEST_VERSION_MISSING));
  914. }
  915. m_Assembly->m_ManifestVersionMajor = 1;
  916. m_Assembly->m_ManifestVersionMinor = 0;
  917. FN_EPILOG
  918. }
  919. HRESULT
  920. CNodeFactory::CreateNode(
  921. IXMLNodeSource *pSource,
  922. PVOID pNodeParent,
  923. USHORT NodeCount,
  924. XML_NODE_INFO **apNodeInfo
  925. )
  926. {
  927. HRESULT hr = S_OK;
  928. FN_TRACE_HR(hr);
  929. ULONG i;
  930. //
  931. // ISSUE: jonwis 3/9/2002 - Consider making both of these smart-pointers to simplify cleanup
  932. //
  933. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Smart pointers would make cleanup cake
  934. PSXS_XML_NODE pXmlNode = NULL;
  935. PSXS_NODE_INFO pSXSNodeInfo = NULL;
  936. SIZE_T cchTemp;
  937. m_ParseContext.LineNumber = pSource->GetLineNumber();
  938. INTERNAL_ERROR_CHECK(NodeCount != 0);
  939. #if DBG
  940. ::FusionpDbgPrintEx(
  941. FUSION_DBG_LEVEL_NODEFACTORY,
  942. "SXS.DLL: " __FUNCTION__ "() entered\n"
  943. " m_ParseContext.XMLElementDepth = %lu\n",
  944. m_ParseContext.XMLElementDepth);
  945. for (i=0; i<NodeCount; i++)
  946. ::SxspDbgPrintXmlNodeInfo(FUSION_DBG_LEVEL_NODEFACTORY, apNodeInfo[i]);
  947. #endif
  948. // Short-circuit PIs, XML-decls, whitespace and comments
  949. if ((apNodeInfo[0]->dwType == XML_PI) ||
  950. (apNodeInfo[0]->dwType == XML_XMLDECL) ||
  951. (apNodeInfo[0]->dwType == XML_COMMENT) ||
  952. (apNodeInfo[0]->dwType == XML_WHITESPACE))
  953. {
  954. FN_SUCCESSFUL_EXIT();
  955. }
  956. IFCOMFAILED_EXIT(m_XMLNamespaceManager.OnCreateNode(pSource, pNodeParent, NodeCount, apNodeInfo));
  957. IFALLOCFAILED_EXIT(pSXSNodeInfo = new SXS_NODE_INFO[NodeCount]);
  958. for (i=0; i<NodeCount; i++)
  959. IFCOMFAILED_EXIT(this->ConvertXMLNodeInfoToSXSNodeInfo(apNodeInfo[i], pSXSNodeInfo[i]));
  960. if (m_fFirstCreateNodeCall)
  961. {
  962. if ((apNodeInfo[0]->dwType == XML_COMMENT) ||
  963. (apNodeInfo[0]->dwType == XML_XMLDECL) ||
  964. (apNodeInfo[0]->dwType == XML_WHITESPACE))
  965. {
  966. hr = S_OK;
  967. goto Cont;
  968. }
  969. m_fFirstCreateNodeCall = FALSE;
  970. IFCOMFAILED_EXIT(this->FirstCreateNodeCall(pSource, pNodeParent, NodeCount, pSXSNodeInfo));
  971. }
  972. Cont:
  973. if (m_cUnknownChildDepth == 0)
  974. {
  975. for (i=0; i<NUMBER_OF(s_rgWorkers); i++)
  976. {
  977. bool fTemp = false;
  978. if ((s_rgWorkers[i].m_xpsOld == eNotParsing) ||
  979. (m_xpsParseState == s_rgWorkers[i].m_xpsOld))
  980. fTemp = true;
  981. const bool fParseStateMatches = fTemp;
  982. fTemp = false;
  983. if (fParseStateMatches)
  984. {
  985. if (s_rgWorkers[i].m_dwType == apNodeInfo[0]->dwType)
  986. fTemp = true;
  987. }
  988. const bool fTypeMatches = fTemp;
  989. fTemp = false;
  990. if (fTypeMatches)
  991. {
  992. if (s_rgWorkers[i].m_cchName == 0)
  993. fTemp = true;
  994. else
  995. {
  996. if (s_rgWorkers[i].m_cchNamespace == pSXSNodeInfo[0].NamespaceStringBuf.Cch())
  997. {
  998. if (s_rgWorkers[i].m_cchName == pSXSNodeInfo[0].cchText)
  999. {
  1000. if (::FusionpCompareStrings(
  1001. s_rgWorkers[i].m_pszNamespace,
  1002. s_rgWorkers[i].m_cchNamespace,
  1003. pSXSNodeInfo[0].NamespaceStringBuf,
  1004. pSXSNodeInfo[0].NamespaceStringBuf.Cch(),
  1005. false) == 0)
  1006. {
  1007. if (::FusionpCompareStrings(
  1008. s_rgWorkers[i].m_pszName,
  1009. s_rgWorkers[i].m_cchName,
  1010. pSXSNodeInfo[0].pszText,
  1011. pSXSNodeInfo[0].cchText,
  1012. false) == 0)
  1013. {
  1014. fTemp = true;
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. if (fTemp)
  1022. {
  1023. m_xpsParseState = s_rgWorkers[i].m_xpsNew;
  1024. IFW32FALSE_EXIT(
  1025. this->ValidateElementAttributes(
  1026. pSXSNodeInfo,
  1027. NodeCount,
  1028. s_rgWorkers[i].m_prgLegalAttributes,
  1029. s_rgWorkers[i].m_cLegalAttributes));
  1030. if (s_rgWorkers[i].m_pfn != NULL)
  1031. IFW32FALSE_EXIT((this->*s_rgWorkers[i].m_pfn)(NodeCount, pSXSNodeInfo));
  1032. break;
  1033. }
  1034. }
  1035. if (i == NUMBER_OF(s_rgWorkers))
  1036. {
  1037. bool fEquals;
  1038. // If we hit an unrecognized element and its namespace is the one we own, error!
  1039. IFW32FALSE_EXIT(
  1040. pSXSNodeInfo[0].NamespaceStringBuf.Win32Equals(
  1041. SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE,
  1042. SXS_ASSEMBLY_MANIFEST_STD_NAMESPACE_CCH,
  1043. fEquals,
  1044. false));
  1045. if (fEquals)
  1046. {
  1047. this->LogParseError(
  1048. MSG_SXS_MANIFEST_ELEMENT_USED_IN_INVALID_CONTEXT,
  1049. CUnicodeString(apNodeInfo[0]->pwcText, apNodeInfo[0]->ulLen),
  1050. CUnicodeString(m_ParseContext.ElementName, m_ParseContext.ElementNameCch));
  1051. ORIGINATE_WIN32_FAILURE_AND_EXIT(ElementInInvalidContext, ERROR_SXS_MANIFEST_PARSE_ERROR);
  1052. }
  1053. // For an unknown child element, the built-in XML parsing should start to ignore the subtree at this point.
  1054. if (apNodeInfo[0]->dwType == XML_ELEMENT)
  1055. m_cUnknownChildDepth = 1;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. if ((NodeCount != 0) &&
  1061. (apNodeInfo[0]->dwType == XML_ELEMENT))
  1062. {
  1063. // We're handling an unknown series of elements; increment the depth.
  1064. m_cUnknownChildDepth++;
  1065. }
  1066. }
  1067. // Fire the right callbacks for XML_ELEMENT, XML_PCDATA and XML_CDATA nodes:
  1068. switch (apNodeInfo[0]->dwType)
  1069. {
  1070. case XML_ELEMENT:
  1071. #if defined(MSG_SXS_MANIFEST_PARSE_NO_INHERIT_CHILDREN_NOT_ALLOWED)
  1072. if (m_cUnknownChildDepth != 0 && m_xpsParseState == eParsing_doc_assembly_noInherit)
  1073. {
  1074. ORIGINATE_HR_FAILURE_AND_EXIT(CNodeFactory::CreateNode, this->LogParseError(MSG_SXS_MANIFEST_PARSE_NO_INHERIT_CHILDREN_NOT_ALLOWED));
  1075. }
  1076. #endif
  1077. if (m_buffElementPath.Cch() != 0)
  1078. IFW32FALSE_EXIT(m_buffElementPath.Win32Append(L"!", 1));
  1079. cchTemp = m_buffElementPath.Cch();
  1080. //
  1081. // ISSUE: jonwis 3/9/2002 - Use mutli-append here, maybe?
  1082. //
  1083. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - A multi-append here will frobble the heap less
  1084. if (pSXSNodeInfo[0].NamespaceStringBuf.Cch() != 0)
  1085. {
  1086. IFW32FALSE_EXIT(m_buffElementPath.Win32Append(pSXSNodeInfo[0].NamespaceStringBuf));
  1087. IFW32FALSE_EXIT(m_buffElementPath.Win32Append(L"^", 1));
  1088. }
  1089. IFW32FALSE_EXIT(m_buffElementPath.Win32Append(pSXSNodeInfo[0].pszText, pSXSNodeInfo[0].cchText));
  1090. m_ParseContext.ElementPathCch = m_buffElementPath.Cch();
  1091. m_ParseContext.ElementPath = m_buffElementPath;
  1092. m_ParseContext.ElementName = static_cast<PCWSTR>(m_buffElementPath) + cchTemp;
  1093. m_ParseContext.ElementNameCch = m_buffElementPath.Cch() - cchTemp;
  1094. IFW32FALSE_EXIT(::SxspHashString(m_buffElementPath, m_buffElementPath.Cch(), &m_ParseContext.ElementHash, true));
  1095. m_ParseContext.XMLElementDepth++;
  1096. //
  1097. // ISSUE: jonwis 3/9/2002 - Maybe there needs to be a more general way of dispatching
  1098. // this sort of stuff off to the contributors, rather than having embedded
  1099. // loops everywhere. Easier to read, easier to maintain (esp. if we end up
  1100. // doing some sort of filtering later.
  1101. //
  1102. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Lots of places seem to do something similar, consider collapsing
  1103. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  1104. {
  1105. IFW32FALSE_EXIT(
  1106. m_ActCtxGenCtx->m_Contributors[i].Fire_ElementParsed(
  1107. m_ActCtxGenCtx,
  1108. m_AssemblyContext,
  1109. &m_ParseContext,
  1110. NodeCount,
  1111. pSXSNodeInfo));
  1112. }
  1113. break;
  1114. case XML_PCDATA:
  1115. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  1116. {
  1117. IFW32FALSE_EXIT(
  1118. m_ActCtxGenCtx->m_Contributors[i].Fire_PCDATAParsed(
  1119. m_ActCtxGenCtx,
  1120. m_AssemblyContext,
  1121. &m_ParseContext,
  1122. apNodeInfo[0]->pwcText,
  1123. apNodeInfo[0]->ulLen));
  1124. }
  1125. break;
  1126. case XML_CDATA:
  1127. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  1128. {
  1129. IFW32FALSE_EXIT(
  1130. m_ActCtxGenCtx->m_Contributors[i].Fire_CDATAParsed(
  1131. m_ActCtxGenCtx,
  1132. m_AssemblyContext,
  1133. &m_ParseContext,
  1134. apNodeInfo[0]->pwcText,
  1135. apNodeInfo[0]->ulLen));
  1136. }
  1137. break;
  1138. }
  1139. hr = NOERROR;
  1140. Exit:
  1141. if (pSXSNodeInfo != NULL)
  1142. FUSION_DELETE_ARRAY(pSXSNodeInfo);
  1143. if (pXmlNode != NULL)
  1144. FUSION_DELETE_SINGLETON(pXmlNode);
  1145. return hr;
  1146. }
  1147. BOOL
  1148. CNodeFactory::SetParseType(
  1149. ULONG ParseType,
  1150. ULONG PathType,
  1151. const CBaseStringBuffer &Path,
  1152. const FILETIME &rftLastWriteTime
  1153. )
  1154. {
  1155. FN_PROLOG_WIN32
  1156. PARAMETER_CHECK(
  1157. (ParseType == XML_FILE_TYPE_MANIFEST) ||
  1158. (ParseType == XML_FILE_TYPE_APPLICATION_CONFIGURATION) ||
  1159. (ParseType == XML_FILE_TYPE_COMPONENT_CONFIGURATION));
  1160. PARAMETER_CHECK(PathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE);
  1161. IFW32FALSE_EXIT(m_buffCurrentFileName.Win32Assign(Path));
  1162. m_ParseContext.SourceFilePathType = PathType;
  1163. m_ParseContext.SourceFile = m_buffCurrentFileName;
  1164. m_ParseContext.SourceFileCch = m_buffCurrentFileName.Cch();
  1165. m_ParseContext.SourceFileLastWriteTime = rftLastWriteTime;
  1166. m_ParseType = ParseType;
  1167. FN_EPILOG
  1168. }
  1169. BOOL
  1170. CNodeFactory::XMLParser_Element_doc_assembly(
  1171. USHORT cNumRecs,
  1172. PCSXS_NODE_INFO prgNodeInfo
  1173. )
  1174. {
  1175. FN_PROLOG_WIN32
  1176. ULONG i;
  1177. ASSERT(cNumRecs != 0);
  1178. ASSERT(prgNodeInfo != NULL);
  1179. if (m_fAssemblyFound)
  1180. {
  1181. CUnicodeString s;
  1182. PCWSTR ManifestPath;
  1183. IFW32FALSE_EXIT(m_Assembly->GetManifestPath(&ManifestPath, NULL));
  1184. s = ManifestPath;
  1185. ORIGINATE_HR_FAILURE_AND_EXIT(CNodeFactory::XMLParser_Element_doc_assembly, this->LogParseError(MSG_SXS_MANIFEST_MULTIPLE_TOP_ASSEMBLY, &s));
  1186. }
  1187. m_fAssemblyFound = true;
  1188. m_fMetadataSatelliteAlreadyFound = false;
  1189. // Now let's tell all the contributors that we're about to begin a parsing session.
  1190. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  1191. {
  1192. IFW32FALSE_EXIT(m_ActCtxGenCtx->m_Contributors[i].Fire_ParseBeginning(
  1193. m_ActCtxGenCtx,
  1194. m_AssemblyContext,
  1195. 0, // FileFlags
  1196. m_ParseType,
  1197. m_ParseContext.SourceFilePathType,
  1198. m_ParseContext.SourceFile,
  1199. m_ParseContext.SourceFileCch,
  1200. m_ParseContext.SourceFileLastWriteTime,
  1201. m_Assembly->m_ManifestVersionMajor,
  1202. m_Assembly->m_ManifestVersionMinor,
  1203. m_Assembly->m_MetadataSatelliteRosterIndex));
  1204. }
  1205. FN_EPILOG
  1206. }
  1207. BOOL
  1208. CNodeFactory::XMLParser_Element_doc_assembly_assemblyIdentity(
  1209. USHORT cNumRecs,
  1210. PCSXS_NODE_INFO prgNodeInfo
  1211. )
  1212. {
  1213. BOOL fSuccess = FALSE;
  1214. FN_TRACE_WIN32(fSuccess);
  1215. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Better cleanup in general here with smart pointers
  1216. PASSEMBLY_IDENTITY AssemblyIdentity = NULL;
  1217. const BOOL fGeneratingActCtx = (m_ActCtxGenCtx->m_ManifestOperation == MANIFEST_OPERATION_GENERATE_ACTIVATION_CONTEXT);
  1218. ULONG i;
  1219. DWORD dwValidateFlags = 0;
  1220. if (m_fIdentityFound)
  1221. {
  1222. this->LogParseError(MSG_SXS_MULTIPLE_IDENTITY, CEventLogString(prgNodeInfo[0].pszText, prgNodeInfo[0].cchText));
  1223. ::FusionpDbgPrintEx(
  1224. FUSION_DBG_LEVEL_ERROR,
  1225. "SXS.DLL: Manifest %ls has multiple identities\n", static_cast<PCWSTR>(m_buffCurrentFileName));
  1226. ORIGINATE_WIN32_FAILURE_AND_EXIT(
  1227. MultipleIdentities,
  1228. ERROR_SXS_MANIFEST_PARSE_ERROR);
  1229. }
  1230. m_fIdentityFound = true;
  1231. IFW32FALSE_EXIT(
  1232. ::SxspCreateAssemblyIdentityFromIdentityElement(
  1233. 0, // DWORD Flags,
  1234. &m_ParseContext,
  1235. ASSEMBLY_IDENTITY_TYPE_DEFINITION, // ULONG Type,
  1236. &AssemblyIdentity, // PASSEMBLY_IDENTITY *AssemblyIdentityOut,
  1237. cNumRecs,
  1238. prgNodeInfo));
  1239. // If the identity that was created is a policy statement, then we
  1240. // set the internal parse type to our special 'intuited' parse type
  1241. // for later checks of missing attributes and whatnot. This does
  1242. // duplicate work in ValidateAssembly that does the same thing, but
  1243. // we need to preemptively set this parse type before we go validating.
  1244. // if (m_IntuitedParseType == eActualParseType_Undetermined)
  1245. {
  1246. BOOL fIsPolicy = FALSE;
  1247. IFW32FALSE_EXIT(::SxspDetermineAssemblyType(AssemblyIdentity, fIsPolicy));
  1248. if (fIsPolicy)
  1249. m_IntuitedParseType = eActualParseType_PolicyManifest;
  1250. else
  1251. m_IntuitedParseType = eActualParseType_Undetermined;
  1252. }
  1253. if ((m_IntuitedParseType == eActualParseType_Manifest) ||
  1254. (m_IntuitedParseType == eActualParseType_PolicyManifest) ||
  1255. (m_ParseType == XML_FILE_TYPE_MANIFEST) ||
  1256. (m_ParseType == XML_FILE_TYPE_COMPONENT_CONFIGURATION))
  1257. {
  1258. dwValidateFlags = eValidateIdentity_VersionRequired;
  1259. }
  1260. IFW32FALSE_EXIT(
  1261. this->ValidateIdentity(
  1262. dwValidateFlags,
  1263. ASSEMBLY_IDENTITY_TYPE_DEFINITION,
  1264. AssemblyIdentity));
  1265. if (fGeneratingActCtx)
  1266. {
  1267. if (m_Assembly->IsRoot())
  1268. {
  1269. // If we're generating the actctx and this is the root assembly, it's possible
  1270. // that we got to it by a filesystem path (e.g. private assembly) rather than
  1271. // an actual reference, so we need to fix up the assembly's identity information
  1272. // appropriately.
  1273. IFW32FALSE_EXIT(m_Assembly->m_ProbedAssemblyInformation.SetProbedIdentity(AssemblyIdentity));
  1274. }
  1275. else
  1276. {
  1277. // If we're generating the actctx and this isn't the root assembly, we need to verify
  1278. // that it's the right one.
  1279. BOOL fEqual;
  1280. IFW32FALSE_EXIT(
  1281. ::SxsAreAssemblyIdentitiesEqual(
  1282. SXS_ARE_ASSEMBLY_IDENTITIES_EQUAL_FLAG_ALLOW_REF_TO_MATCH_DEF,
  1283. m_Assembly->GetAssemblyIdentity(),
  1284. AssemblyIdentity,
  1285. &fEqual));
  1286. if (!fEqual)
  1287. {
  1288. ORIGINATE_HR_FAILURE_AND_EXIT(
  1289. CNodeFactory::XMLParser_Element_doc_assembly_assemblyIdentity,
  1290. this->LogParseError(MSG_SXS_COMPONENT_MANIFEST_PROBED_IDENTITY_MISMATCH));
  1291. // LogParseError sets the last error appropriate to the message logged
  1292. }
  1293. }
  1294. }
  1295. if (m_IntuitedParseType == eActualParseType_PolicyManifest)
  1296. {
  1297. //
  1298. // ISSUE: jonwis 3/11/2002 - Stomps on m_CurrentPolicyStatement if it was non-null. Consider
  1299. // using INTERNAL_ERROR_CHECK to make sure it's NULL first.
  1300. //
  1301. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Track possible leaks here better
  1302. IFALLOCFAILED_EXIT(m_CurrentPolicyStatement = new CPolicyStatement);
  1303. IFW32FALSE_EXIT(m_CurrentPolicyStatement->Initialize());
  1304. }
  1305. // Tell everyone that we're sure who we are...
  1306. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  1307. {
  1308. IFW32FALSE_EXIT(
  1309. m_ActCtxGenCtx->m_Contributors[i].Fire_IdentityDetermined(
  1310. m_ActCtxGenCtx,
  1311. m_AssemblyContext,
  1312. &m_ParseContext,
  1313. AssemblyIdentity));
  1314. }
  1315. // fix up assembly and assembly context so we know where to copy to
  1316. // also save the manifest
  1317. IFW32FALSE_EXIT(m_Assembly->m_ProbedAssemblyInformation.SetAssemblyIdentity(AssemblyIdentity));
  1318. if (m_AssemblyContext->AssemblyIdentity != NULL)
  1319. ::SxsDestroyAssemblyIdentity(const_cast<PASSEMBLY_IDENTITY>(m_AssemblyContext->AssemblyIdentity));
  1320. m_AssemblyContext->AssemblyIdentity = AssemblyIdentity;
  1321. AssemblyIdentity = NULL;
  1322. fSuccess = TRUE;
  1323. Exit:
  1324. if (AssemblyIdentity != NULL)
  1325. ::SxsDestroyAssemblyIdentity(AssemblyIdentity);
  1326. return fSuccess;
  1327. }
  1328. BOOL
  1329. CNodeFactory::XMLParser_Element_doc_assembly_noInherit(
  1330. USHORT cNumRecs,
  1331. PCSXS_NODE_INFO prgNodeInfo
  1332. )
  1333. {
  1334. FN_PROLOG_WIN32
  1335. INTERNAL_ERROR_CHECK(
  1336. (m_ParseType == XML_FILE_TYPE_MANIFEST) ||
  1337. (m_ParseType == XML_FILE_TYPE_APPLICATION_CONFIGURATION) ||
  1338. (m_ParseType == XML_FILE_TYPE_COMPONENT_CONFIGURATION));
  1339. switch (m_ParseType)
  1340. {
  1341. case XML_FILE_TYPE_MANIFEST:
  1342. if (cNumRecs != 1)
  1343. {
  1344. ORIGINATE_HR_FAILURE_AND_EXIT(
  1345. CNodeFactory::XMLParser_Element_doc_assembly_noInherit,
  1346. this->LogParseError(MSG_SXS_MANIFEST_PARSE_NO_INHERIT_ATTRIBUTES_NOT_ALLOWED));
  1347. }
  1348. if (m_ActCtxGenCtx->m_NoInherit)
  1349. {
  1350. ORIGINATE_HR_FAILURE_AND_EXIT(
  1351. CNodeFactory::XMLParser_Element_doc_assembly_noInherit,
  1352. this->LogParseError(MSG_SXS_MANIFEST_PARSE_MULTIPLE_NO_INHERIT));
  1353. }
  1354. if (m_fIdentityFound)
  1355. {
  1356. ORIGINATE_HR_FAILURE_AND_EXIT(
  1357. CNodeFactory::XMLParser_Element_doc_assembly_noInherit,
  1358. this->LogParseError(
  1359. MSG_SXS_MANIFEST_ELEMENT_MUST_OCCUR_BEFORE,
  1360. CEventLogString(L"noInherit"),
  1361. CEventLogString(L"assemblyIdentity")));
  1362. }
  1363. m_ActCtxGenCtx->m_NoInherit = true;
  1364. break;
  1365. case XML_FILE_TYPE_APPLICATION_CONFIGURATION:
  1366. ORIGINATE_HR_FAILURE_AND_EXIT(
  1367. CNodeFactory::XMLParser_Element_doc_assembly_noInherit,
  1368. this->LogParseError(MSG_SXS_POLICY_PARSE_NO_INHERIT_NOT_ALLOWED));
  1369. break;
  1370. default:
  1371. INTERNAL_ERROR_CHECK(FALSE);
  1372. break;
  1373. }
  1374. FN_EPILOG
  1375. }
  1376. BOOL
  1377. CNodeFactory::XMLParser_Element_doc_assembly_noInheritable(
  1378. USHORT cNumRecs,
  1379. PCSXS_NODE_INFO prgNodeInfo
  1380. )
  1381. {
  1382. BOOL fSuccess = FALSE;
  1383. FN_TRACE_WIN32(fSuccess);
  1384. INTERNAL_ERROR_CHECK(
  1385. (m_ParseType == XML_FILE_TYPE_MANIFEST) ||
  1386. (m_ParseType == XML_FILE_TYPE_APPLICATION_CONFIGURATION) ||
  1387. (m_ParseType == XML_FILE_TYPE_COMPONENT_CONFIGURATION));
  1388. switch (m_ParseType)
  1389. {
  1390. case XML_FILE_TYPE_MANIFEST:
  1391. if (cNumRecs != 1)
  1392. {
  1393. this->LogParseError(MSG_SXS_MANIFEST_PARSE_NO_INHERIT_ATTRIBUTES_NOT_ALLOWED);
  1394. goto Exit;
  1395. }
  1396. if (m_fNoInheritableFound)
  1397. {
  1398. this->LogParseError(MSG_SXS_MANIFEST_PARSE_MULTIPLE_NOINHERITABLE);
  1399. goto Exit;
  1400. }
  1401. if (m_fIdentityFound)
  1402. {
  1403. this->LogParseError(
  1404. MSG_SXS_MANIFEST_ELEMENT_MUST_OCCUR_BEFORE,
  1405. CEventLogString(L"noInheritable"),
  1406. CEventLogString(L"assemblyIdentity"));
  1407. goto Exit;
  1408. }
  1409. m_fNoInheritableFound = true;
  1410. break;
  1411. case XML_FILE_TYPE_APPLICATION_CONFIGURATION:
  1412. case XML_FILE_TYPE_COMPONENT_CONFIGURATION:
  1413. this->LogParseError(MSG_SXS_POLICY_PARSE_NO_INHERIT_NOT_ALLOWED);
  1414. goto Exit;
  1415. default:
  1416. ::FusionpSetLastWin32Error(ERROR_INTERNAL_ERROR);
  1417. goto Exit;
  1418. }
  1419. fSuccess = TRUE;
  1420. Exit:
  1421. return fSuccess;
  1422. }
  1423. BOOL
  1424. CNodeFactory::XMLParser_Element_doc_assembly_dependency(
  1425. USHORT cNumRecs,
  1426. PCSXS_NODE_INFO prgNodeInfo
  1427. )
  1428. {
  1429. FN_PROLOG_WIN32
  1430. bool fFound;
  1431. SIZE_T cb;
  1432. m_fIsDependencyOptional = false;
  1433. m_fDependencyChildHit = false;
  1434. m_fIsMetadataSatellite = false;
  1435. IFW32FALSE_EXIT(
  1436. ::SxspGetAttributeValue(
  1437. 0,
  1438. &s_AttributeName_optional,
  1439. prgNodeInfo,
  1440. cNumRecs,
  1441. &m_ParseContext,
  1442. fFound,
  1443. sizeof(m_fIsDependencyOptional),
  1444. &m_fIsDependencyOptional,
  1445. cb,
  1446. &::SxspValidateBoolAttribute,
  1447. 0));
  1448. if (!fFound)
  1449. m_fIsDependencyOptional = false;
  1450. FN_EPILOG
  1451. }
  1452. BOOL
  1453. CNodeFactory::XMLParser_Element_doc_assembly_dependency_dependentAssembly(
  1454. USHORT cNumRecs,
  1455. PCSXS_NODE_INFO prgNodeInfo
  1456. )
  1457. {
  1458. FN_PROLOG_WIN32
  1459. bool fFound;
  1460. SIZE_T cb;
  1461. if (m_fDependencyChildHit == false)
  1462. {
  1463. m_fDependencyChildHit = true;
  1464. }
  1465. else
  1466. {
  1467. ORIGINATE_HR_FAILURE_AND_EXIT(
  1468. CNodeFactory::XMLParser_Element_doc_assembly_dependency_dependentAssembly,
  1469. this->LogParseError(MSG_SXS_MANIFEST_MULTIPLE_DEPENDENTASSEMBLY_IN_DEPENDENCY));
  1470. }
  1471. m_fAssemblyIdentityChildOfDependenctAssemblyHit = false;
  1472. IFW32FALSE_EXIT(
  1473. ::SxspGetAttributeValue(
  1474. 0,
  1475. &s_AttributeName_metadataSatellite,
  1476. prgNodeInfo,
  1477. cNumRecs,
  1478. &m_ParseContext,
  1479. fFound,
  1480. sizeof(m_fIsMetadataSatellite),
  1481. &m_fIsMetadataSatellite,
  1482. cb,
  1483. &::SxspValidateBoolAttribute,
  1484. 0));
  1485. if (!fFound)
  1486. m_fIsMetadataSatellite = false;
  1487. FN_EPILOG
  1488. }
  1489. BOOL
  1490. CNodeFactory::XMLParser_Element_doc_assembly_dependency_dependentAssembly_bindingRedirect(
  1491. USHORT cNumRecs,
  1492. PCSXS_NODE_INFO prgNodeInfo
  1493. )
  1494. {
  1495. BOOL fSuccess = FALSE;
  1496. FN_TRACE_WIN32(fSuccess);
  1497. bool fFound;
  1498. bool fValid;
  1499. SIZE_T cb;
  1500. CSmallStringBuffer buffOldVersion;
  1501. CSmallStringBuffer buffNewVersion;
  1502. INTERNAL_ERROR_CHECK(m_CurrentPolicyStatement != NULL);
  1503. if (m_IntuitedParseType != eActualParseType_PolicyManifest)
  1504. {
  1505. this->LogParseError(MSG_SXS_BINDING_REDIRECTS_ONLY_IN_COMPONENT_CONFIGURATION);
  1506. goto Exit;
  1507. }
  1508. IFW32FALSE_EXIT(
  1509. ::SxspGetAttributeValue(
  1510. SXSP_GET_ATTRIBUTE_VALUE_FLAG_REQUIRED_ATTRIBUTE,
  1511. &s_AttributeName_oldVersion,
  1512. prgNodeInfo,
  1513. cNumRecs,
  1514. &m_ParseContext,
  1515. fFound,
  1516. sizeof(buffOldVersion),
  1517. &buffOldVersion,
  1518. cb,
  1519. NULL,
  1520. 0));
  1521. INTERNAL_ERROR_CHECK(fFound);
  1522. IFW32FALSE_EXIT(
  1523. ::SxspGetAttributeValue(
  1524. SXSP_GET_ATTRIBUTE_VALUE_FLAG_REQUIRED_ATTRIBUTE,
  1525. &s_AttributeName_newVersion,
  1526. prgNodeInfo,
  1527. cNumRecs,
  1528. &m_ParseContext,
  1529. fFound,
  1530. sizeof(buffNewVersion),
  1531. &buffNewVersion,
  1532. cb,
  1533. NULL,
  1534. 0));
  1535. INTERNAL_ERROR_CHECK(fFound);
  1536. IFW32FALSE_EXIT(m_CurrentPolicyStatement->AddRedirect(buffOldVersion, buffNewVersion, fValid));
  1537. if (!fValid)
  1538. {
  1539. this->LogParseError(MSG_SXS_BINDING_REDIRECT_MISSING_REQUIRED_ATTRIBUTES);
  1540. goto Exit;
  1541. }
  1542. fSuccess = TRUE;
  1543. Exit:
  1544. return fSuccess;
  1545. }
  1546. BOOL
  1547. CNodeFactory::XMLParser_Element_doc_assembly_dependency_dependentAssembly_assemblyIdentity(
  1548. USHORT cNumRecs,
  1549. PCSXS_NODE_INFO prgNodeInfo
  1550. )
  1551. {
  1552. FN_PROLOG_WIN32
  1553. CSmartPtrWithNamedDestructor<ASSEMBLY_IDENTITY, ::SxsDestroyAssemblyIdentity> pAssemblyIdentity;
  1554. ULONG ParseType;
  1555. ASSERT(cNumRecs != 0);
  1556. ASSERT(prgNodeInfo != NULL);
  1557. // We're either parsing a manifest or a policy file; what else??
  1558. INTERNAL_ERROR_CHECK(
  1559. (m_ParseType == XML_FILE_TYPE_MANIFEST) ||
  1560. (m_ParseType == XML_FILE_TYPE_APPLICATION_CONFIGURATION) ||
  1561. (m_ParseType == XML_FILE_TYPE_COMPONENT_CONFIGURATION));
  1562. if (m_fAssemblyIdentityChildOfDependenctAssemblyHit == false)
  1563. m_fAssemblyIdentityChildOfDependenctAssemblyHit = true;
  1564. else
  1565. {
  1566. this->LogParseError(MSG_SXS_MANIFEST_MULTIPLE_ASSEMBLYIDENTITY_IN_DEPENDENCYASSEMBLY);
  1567. goto Exit;
  1568. }
  1569. switch (m_IntuitedParseType)
  1570. {
  1571. case eActualParseType_Undetermined:
  1572. ParseType = m_ParseType;
  1573. break;
  1574. case eActualParseType_PolicyManifest:
  1575. ParseType = XML_FILE_TYPE_COMPONENT_CONFIGURATION;
  1576. break;
  1577. case eActualParseType_Manifest:
  1578. ParseType = XML_FILE_TYPE_MANIFEST;
  1579. break;
  1580. default:
  1581. INTERNAL_ERROR_CHECK(FALSE);
  1582. ParseType = m_ParseType;
  1583. break;
  1584. }
  1585. switch (ParseType)
  1586. {
  1587. case XML_FILE_TYPE_MANIFEST:
  1588. IFW32FALSE_EXIT(
  1589. ::SxspCreateAssemblyIdentityFromIdentityElement(
  1590. 0,
  1591. &m_ParseContext,
  1592. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1593. &pAssemblyIdentity,
  1594. cNumRecs,
  1595. prgNodeInfo));
  1596. IFW32FALSE_EXIT(
  1597. this->ValidateIdentity(
  1598. eValidateIdentity_PoliciesNotAllowed| eValidateIdentity_VersionRequired,
  1599. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1600. pAssemblyIdentity));
  1601. //
  1602. // If we're not installing, process the identity...
  1603. //
  1604. // Note that in a strange twist on refcounting, SxspEnqueueAssemblyReference does not
  1605. // hold the reference, it clones it. That's why we don't .Detach from the pAssemblyIdentity
  1606. // smart pointer here.
  1607. //
  1608. if (m_ActCtxGenCtx->m_ManifestOperation == MANIFEST_OPERATION_GENERATE_ACTIVATION_CONTEXT)
  1609. IFW32FALSE_EXIT(::SxspEnqueueAssemblyReference(m_ActCtxGenCtx, m_Assembly, pAssemblyIdentity, m_fIsDependencyOptional, m_fIsMetadataSatellite));
  1610. break;
  1611. case XML_FILE_TYPE_COMPONENT_CONFIGURATION:
  1612. {
  1613. BOOL fValidDependencyAssemblyIdentity = FALSE;
  1614. PCWSTR pszName1 = NULL, pszName2 = NULL;
  1615. SIZE_T cchName1 = 0, cchName2 = 0;
  1616. if (m_CurrentPolicyDependentAssemblyIdentity != NULL)
  1617. {
  1618. this->LogParseError(MSG_SXS_COMPONENT_CONFIGURATION_MANIFESTS_MAY_ONLY_HAVE_ONE_DEPENDENCY);
  1619. goto Exit;
  1620. }
  1621. IFW32FALSE_EXIT(
  1622. ::SxspCreateAssemblyIdentityFromIdentityElement(
  1623. 0,
  1624. &m_ParseContext,
  1625. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1626. &pAssemblyIdentity,
  1627. cNumRecs,
  1628. prgNodeInfo));
  1629. // check the name in dependency-assemblyidentity match with the name in assembly-assemblyidentity
  1630. IFW32FALSE_EXIT(
  1631. ::SxspGetAssemblyIdentityAttributeValue(
  1632. SXSP_GET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_NOT_FOUND_RETURNS_NULL,
  1633. m_Assembly->GetAssemblyIdentity(),
  1634. &s_IdentityAttribute_name,
  1635. &pszName1, // something in a format of "Policy.1212.1221.assemblyname"
  1636. &cchName1));
  1637. IFW32FALSE_EXIT(
  1638. ::SxspGetAssemblyIdentityAttributeValue(
  1639. SXSP_GET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_NOT_FOUND_RETURNS_NULL,
  1640. pAssemblyIdentity,
  1641. &s_IdentityAttribute_name,
  1642. &pszName2, // would be something as "assemblyname"
  1643. &cchName2));
  1644. if ((cchName1 > cchName2) && (cchName2 !=0))
  1645. {
  1646. if ( (*(pszName1 + (cchName1 - cchName2 -1)) == L'.') && (::FusionpCompareStrings(
  1647. pszName1 + (cchName1 - cchName2), cchName2,
  1648. pszName2, cchName2, FALSE // must be case-sensitive for values
  1649. ) == 0 ))
  1650. {
  1651. fValidDependencyAssemblyIdentity = TRUE;
  1652. }
  1653. }
  1654. if (fValidDependencyAssemblyIdentity)
  1655. {
  1656. IFW32FALSE_EXIT(
  1657. this->ValidateIdentity(
  1658. eValidateIdentity_PoliciesNotAllowed | eValidateIdentity_VersionNotAllowed,
  1659. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1660. pAssemblyIdentity));
  1661. // We'll keep track of this so that we can recognize multiple dependentAssembly elements on installation
  1662. // of policies.
  1663. INTERNAL_ERROR_CHECK(m_CurrentPolicyDependentAssemblyIdentity == NULL);
  1664. m_CurrentPolicyDependentAssemblyIdentity = pAssemblyIdentity.Detach();
  1665. }
  1666. else // print a message and ignore this entry
  1667. {
  1668. ::FusionpDbgPrintEx(
  1669. FUSION_DBG_LEVEL_POLICY | FUSION_DBG_LEVEL_INFO,
  1670. "SXS.DLL: unexpected assemblyidentity within dependency tag in component policy \"%ls\"\n",
  1671. m_buffCurrentFileName
  1672. );
  1673. }
  1674. } // end of this case
  1675. break;
  1676. default:
  1677. // Internal error!
  1678. INTERNAL_ERROR_CHECK(FALSE);
  1679. }
  1680. FN_EPILOG
  1681. }
  1682. BOOL
  1683. CNodeFactory::XMLParser_Element_doc_configuration(
  1684. USHORT cNumRecs,
  1685. PCSXS_NODE_INFO prgNodeInfo
  1686. )
  1687. {
  1688. BOOL fSuccess = FALSE;
  1689. FN_TRACE_WIN32(fSuccess);
  1690. ULONG i;
  1691. ASSERT(cNumRecs != 0);
  1692. ASSERT(prgNodeInfo != NULL);
  1693. if (m_fAssemblyFound)
  1694. {
  1695. CUnicodeString s;
  1696. PCWSTR ManifestPath;
  1697. IFW32FALSE_EXIT(m_Assembly->GetManifestPath(&ManifestPath, NULL));
  1698. s = ManifestPath;
  1699. this->LogParseError(MSG_SXS_MANIFEST_MULTIPLE_TOP_ASSEMBLY, &s);
  1700. goto Exit;
  1701. }
  1702. m_fAssemblyFound = true;
  1703. m_fMetadataSatelliteAlreadyFound = false;
  1704. // Now let's tell all the contributors that we're about to begin a parsing session.
  1705. for (i=0; i<m_ActCtxGenCtx->m_ContributorCount; i++)
  1706. {
  1707. IFW32FALSE_EXIT(
  1708. m_ActCtxGenCtx->m_Contributors[i].Fire_ParseBeginning(
  1709. m_ActCtxGenCtx,
  1710. m_AssemblyContext,
  1711. 0, // FileFlags
  1712. m_ParseType,
  1713. m_ParseContext.SourceFilePathType,
  1714. m_ParseContext.SourceFile,
  1715. m_ParseContext.SourceFileCch,
  1716. m_ParseContext.SourceFileLastWriteTime,
  1717. m_Assembly->m_ManifestVersionMajor,
  1718. m_Assembly->m_ManifestVersionMinor,
  1719. m_Assembly->m_MetadataSatelliteRosterIndex));
  1720. }
  1721. fSuccess = TRUE;
  1722. Exit:
  1723. return fSuccess;
  1724. }
  1725. BOOL
  1726. CNodeFactory::XMLParser_Element_doc_configuration_windows(
  1727. USHORT cNumRecs,
  1728. PCSXS_NODE_INFO prgNodeInfo
  1729. )
  1730. {
  1731. BOOL fSuccess = FALSE;
  1732. FN_TRACE_WIN32(fSuccess);
  1733. fSuccess = TRUE;
  1734. // Exit:
  1735. return fSuccess;
  1736. }
  1737. BOOL
  1738. CNodeFactory::XMLParser_Element_doc_configuration_windows_assemblyBinding(
  1739. USHORT cNumRecs,
  1740. PCSXS_NODE_INFO prgNodeInfo
  1741. )
  1742. {
  1743. BOOL fSuccess = FALSE;
  1744. FN_TRACE_WIN32(fSuccess);
  1745. fSuccess = TRUE;
  1746. // Exit:
  1747. return fSuccess;
  1748. }
  1749. BOOL
  1750. CNodeFactory::XMLParser_Element_doc_configuration_windows_assemblyBinding_assemblyIdentity(
  1751. USHORT cNumRecs,
  1752. PCSXS_NODE_INFO prgNodeInfo
  1753. )
  1754. {
  1755. FN_PROLOG_WIN32;
  1756. CSmartPtrWithNamedDestructor<ASSEMBLY_IDENTITY, ::SxsDestroyAssemblyIdentity> pAssemblyIdentity;
  1757. IFW32FALSE_EXIT(
  1758. ::SxspCreateAssemblyIdentityFromIdentityElement(
  1759. 0,
  1760. &m_ParseContext,
  1761. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1762. &pAssemblyIdentity,
  1763. cNumRecs,
  1764. prgNodeInfo));
  1765. IFW32FALSE_EXIT(
  1766. this->ValidateIdentity(
  1767. eValidateIdentity_PoliciesNotAllowed | eValidateIdentity_VersionRequired,
  1768. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1769. pAssemblyIdentity));
  1770. FN_EPILOG;
  1771. }
  1772. BOOL
  1773. CNodeFactory::XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly(
  1774. USHORT cNumRecs,
  1775. PCSXS_NODE_INFO prgNodeInfo
  1776. )
  1777. {
  1778. BOOL fSuccess = FALSE;
  1779. FN_TRACE_WIN32(fSuccess);
  1780. fSuccess = TRUE;
  1781. // Exit:
  1782. return fSuccess;
  1783. }
  1784. BOOL
  1785. CNodeFactory::XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_assemblyIdentity(
  1786. USHORT cNumRecs,
  1787. PCSXS_NODE_INFO prgNodeInfo
  1788. )
  1789. {
  1790. FN_PROLOG_WIN32;
  1791. CSmartPtrWithNamedDestructor<ASSEMBLY_IDENTITY, ::SxsDestroyAssemblyIdentity> pAssemblyIdentity;
  1792. CSmartPtr<CPolicyStatement> pPolicyStatement;
  1793. CPolicyStatement *pFoundPolicyStatement = NULL;
  1794. IFW32FALSE_EXIT(
  1795. ::SxspCreateAssemblyIdentityFromIdentityElement(
  1796. 0,
  1797. &m_ParseContext,
  1798. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1799. &pAssemblyIdentity,
  1800. cNumRecs,
  1801. prgNodeInfo));
  1802. IFW32FALSE_EXIT(
  1803. this->ValidateIdentity(
  1804. eValidateIdentity_PoliciesNotAllowed | eValidateIdentity_VersionNotAllowed,
  1805. ASSEMBLY_IDENTITY_TYPE_REFERENCE,
  1806. pAssemblyIdentity));
  1807. IFW32FALSE_EXIT(
  1808. ::SxspGenerateTextuallyEncodedPolicyIdentityFromAssemblyIdentity(
  1809. SXSP_GENERATE_TEXTUALLY_ENCODED_POLICY_IDENTITY_FROM_ASSEMBLY_IDENTITY_FLAG_OMIT_ENTIRE_VERSION,
  1810. pAssemblyIdentity,
  1811. m_buffCurrentApplicationPolicyIdentityKey,
  1812. NULL));
  1813. IFW32FALSE_EXIT(m_ActCtxGenCtx->m_ApplicationPolicyTable.Find(m_buffCurrentApplicationPolicyIdentityKey, pFoundPolicyStatement));
  1814. if (pFoundPolicyStatement != NULL)
  1815. {
  1816. this->LogParseError(MSG_SXS_APPLICATION_CONFIGURATION_MANIFEST_MAY_ONLY_HAVE_ONE_DEPENDENTASSEMBLY_PER_IDENTITY);
  1817. goto Exit;
  1818. }
  1819. IFALLOCFAILED_EXIT(pPolicyStatement.Win32Allocate(__FILE__, __LINE__));
  1820. IFW32FALSE_EXIT(pPolicyStatement->Initialize());
  1821. IFW32FALSE_EXIT(m_ActCtxGenCtx->m_ApplicationPolicyTable.Insert(m_buffCurrentApplicationPolicyIdentityKey, pPolicyStatement));
  1822. // preset it to be global value about m_fApplyPublisherPolicy,
  1823. // and be reset in dependentAssembly_publisherPolicy function if present
  1824. if ((this->m_ActCtxGenCtx->m_fAppApplyPublisherPolicy == SXS_PUBLISHER_POLICY_APPLY_YES) || (this->m_ActCtxGenCtx->m_fAppApplyPublisherPolicy == SXS_PUBLISHER_POLICY_APPLY_DEFAULT))
  1825. pPolicyStatement->m_fApplyPublisherPolicy = true;
  1826. else
  1827. pPolicyStatement->m_fApplyPublisherPolicy = false;
  1828. m_CurrentPolicyStatement = pPolicyStatement.Detach();
  1829. if (m_CurrentPolicyDependentAssemblyIdentity != NULL)
  1830. {
  1831. ::SxsDestroyAssemblyIdentity(m_CurrentPolicyDependentAssemblyIdentity);
  1832. m_CurrentPolicyDependentAssemblyIdentity = NULL;
  1833. }
  1834. m_CurrentPolicyDependentAssemblyIdentity = pAssemblyIdentity.Detach();
  1835. FN_EPILOG;
  1836. }
  1837. BOOL
  1838. CNodeFactory::XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_publisherPolicy(
  1839. USHORT cNumRecs,
  1840. PCSXS_NODE_INFO prgNodeInfo
  1841. )
  1842. {
  1843. FN_PROLOG_WIN32;
  1844. if (m_CurrentPolicyStatement == NULL)
  1845. {
  1846. this->LogParseError(MSG_SXS_APPLICATION_CONFIGURATION_MANIFEST_DEPENDENTASSEMBLY_MISSING_IDENTITY);
  1847. goto Exit;
  1848. }
  1849. if (this->m_ActCtxGenCtx->m_fAppApplyPublisherPolicy == SXS_PUBLISHER_POLICY_APPLY_NO)
  1850. m_CurrentPolicyStatement->m_fApplyPublisherPolicy = false;
  1851. else
  1852. {
  1853. bool fFound, fApplyPolicy;
  1854. SIZE_T cb;
  1855. IFW32FALSE_EXIT(
  1856. ::SxspGetAttributeValue(
  1857. 0,
  1858. &s_AttributeName_apply,
  1859. prgNodeInfo,
  1860. cNumRecs,
  1861. &m_ParseContext,
  1862. fFound,
  1863. sizeof(fApplyPolicy),
  1864. &fApplyPolicy,
  1865. cb,
  1866. SxspValidateBoolAttribute,
  1867. 0));
  1868. INTERNAL_ERROR_CHECK(fFound); // if not found, syntax error in the manifest
  1869. if (fApplyPolicy == false)
  1870. {
  1871. //
  1872. // if this tag appears, appcompat flags must be set, otherwise it is an error
  1873. //
  1874. if (!(this->m_ActCtxGenCtx->m_Flags & SXS_GENERATE_ACTCTX_APP_RUNNING_IN_SAFEMODE))
  1875. {
  1876. ::FusionpDbgPrintEx(
  1877. FUSION_DBG_LEVEL_ERROR,
  1878. "SXS.DLL: %s() app-level PublisherPolicy try to be set but there is no appcompat flags been set.\n", __FUNCTION__);
  1879. ::SetLastError(ERROR_SXS_MANIFEST_PARSE_ERROR);
  1880. goto Exit;
  1881. }
  1882. }
  1883. m_CurrentPolicyStatement->m_fApplyPublisherPolicy = fApplyPolicy;
  1884. }
  1885. FN_EPILOG;
  1886. }
  1887. BOOL
  1888. CNodeFactory::XMLParser_Element_doc_configuration_windows_assemblyBinding_publisherPolicy(
  1889. USHORT cNumRecs,
  1890. PCSXS_NODE_INFO prgNodeInfo
  1891. )
  1892. {
  1893. FN_PROLOG_WIN32;
  1894. bool fFound, fApplyPolicy;
  1895. SIZE_T cb;
  1896. if (this->m_ActCtxGenCtx->m_fAppApplyPublisherPolicy != SXS_PUBLISHER_POLICY_APPLY_DEFAULT)
  1897. {
  1898. ::FusionpDbgPrintEx(
  1899. FUSION_DBG_LEVEL_ERROR,
  1900. "SXS.DLL: %s() called but app-level PublisherPolicy has already been set.\n", __FUNCTION__);
  1901. ::SetLastError(ERROR_SXS_MANIFEST_PARSE_ERROR);
  1902. goto Exit;
  1903. }
  1904. IFW32FALSE_EXIT(
  1905. ::SxspGetAttributeValue(
  1906. 0,
  1907. &s_AttributeName_apply,
  1908. prgNodeInfo,
  1909. cNumRecs,
  1910. &m_ParseContext,
  1911. fFound,
  1912. sizeof(fApplyPolicy),
  1913. &fApplyPolicy,
  1914. cb,
  1915. SxspValidateBoolAttribute,
  1916. 0));
  1917. INTERNAL_ERROR_CHECK(fFound);
  1918. if (!fApplyPolicy)
  1919. {
  1920. //
  1921. // if this tag set to be "no", appcompat flags must be set, otherwise it is an error
  1922. //
  1923. if (!(this->m_ActCtxGenCtx->m_Flags & SXS_GENERATE_ACTCTX_APP_RUNNING_IN_SAFEMODE))
  1924. {
  1925. ::FusionpDbgPrintEx(
  1926. FUSION_DBG_LEVEL_ERROR,
  1927. "SXS.DLL: %s() app-level PublisherPolicy try to be set but there is no appcompat flags been set.\n", __FUNCTION__);
  1928. ::SetLastError(ERROR_SXS_MANIFEST_PARSE_ERROR);
  1929. goto Exit;
  1930. }
  1931. this->m_ActCtxGenCtx->m_fAppApplyPublisherPolicy = SXS_PUBLISHER_POLICY_APPLY_NO;
  1932. }
  1933. else
  1934. this->m_ActCtxGenCtx->m_fAppApplyPublisherPolicy = SXS_PUBLISHER_POLICY_APPLY_YES;
  1935. FN_EPILOG;
  1936. }
  1937. BOOL
  1938. CNodeFactory::XMLParser_Element_doc_configuration_windows_assemblyBinding_dependentAssembly_bindingRedirect(
  1939. USHORT cNumRecs,
  1940. PCSXS_NODE_INFO prgNodeInfo
  1941. )
  1942. {
  1943. BOOL fSuccess = FALSE;
  1944. FN_TRACE_WIN32(fSuccess);
  1945. CSmallStringBuffer buffOldVersion;
  1946. CSmallStringBuffer buffNewVersion;
  1947. bool fFound;
  1948. bool fValid;
  1949. SIZE_T cb;
  1950. if (m_CurrentPolicyStatement == NULL)
  1951. {
  1952. this->LogParseError(MSG_SXS_APPLICATION_CONFIGURATION_MANIFEST_DEPENDENTASSEMBLY_MISSING_IDENTITY);
  1953. goto Exit;
  1954. }
  1955. IFW32FALSE_EXIT(
  1956. ::SxspGetAttributeValue(
  1957. SXSP_GET_ATTRIBUTE_VALUE_FLAG_REQUIRED_ATTRIBUTE,
  1958. &s_AttributeName_oldVersion,
  1959. prgNodeInfo,
  1960. cNumRecs,
  1961. &m_ParseContext,
  1962. fFound,
  1963. sizeof(buffOldVersion),
  1964. &buffOldVersion,
  1965. cb,
  1966. NULL,
  1967. 0));
  1968. INTERNAL_ERROR_CHECK(fFound);
  1969. IFW32FALSE_EXIT(
  1970. ::SxspGetAttributeValue(
  1971. SXSP_GET_ATTRIBUTE_VALUE_FLAG_REQUIRED_ATTRIBUTE,
  1972. &s_AttributeName_newVersion,
  1973. prgNodeInfo,
  1974. cNumRecs,
  1975. &m_ParseContext,
  1976. fFound,
  1977. sizeof(buffNewVersion),
  1978. &buffNewVersion,
  1979. cb,
  1980. NULL,
  1981. 0));
  1982. INTERNAL_ERROR_CHECK(fFound);
  1983. // If either are not found, log an error
  1984. if (!fFound)
  1985. {
  1986. this->LogParseError(MSG_SXS_BINDING_REDIRECT_MISSING_REQUIRED_ATTRIBUTES);
  1987. goto Exit;
  1988. }
  1989. IFW32FALSE_EXIT(m_CurrentPolicyStatement->AddRedirect(buffOldVersion, buffNewVersion, fValid));
  1990. if (! fValid)
  1991. {
  1992. // log an error
  1993. ::FusionpLogError(
  1994. MSG_SXS_POLICY_VERSION_OVERLAP,
  1995. CEventLogString(m_AssemblyContext->PolicyPath),
  1996. CEventLogString(buffOldVersion),
  1997. CEventLogString(buffNewVersion));
  1998. ORIGINATE_WIN32_FAILURE_AND_EXIT(PolicyVersionOverlap, ERROR_SXS_MANIFEST_PARSE_ERROR);
  1999. }
  2000. fSuccess = TRUE;
  2001. Exit:
  2002. return fSuccess;
  2003. }
  2004. //
  2005. // ISSUE: jonwis 3/11/2002 - Smells like dead code. CPartialAssemblyVersion isn't constrcted anywhere,
  2006. // and this function isn't called by anyone.
  2007. //
  2008. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Dead code, probably
  2009. BOOL
  2010. CNodeFactory::XMLParser_Parse_PartialAssemblyVersion(
  2011. PVOID pvDatum,
  2012. BOOL fAlreadyFound,
  2013. CBaseStringBuffer &rbuff
  2014. )
  2015. {
  2016. return reinterpret_cast<CPartialAssemblyVersion *>(pvDatum)->Parse(rbuff, rbuff.Cch());
  2017. }
  2018. //
  2019. // ISSUE: jonwis 3/11/2002 - Same here... never called anywhere, dead code.
  2020. //
  2021. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Dead code, probably
  2022. BOOL
  2023. CNodeFactory::XMLParser_Parse_String(
  2024. LPVOID pvDatum,
  2025. BOOL fAlreadyFound,
  2026. CBaseStringBuffer &rbuff)
  2027. {
  2028. return ((CBaseStringBuffer *) pvDatum)->Win32Assign(rbuff);
  2029. }
  2030. //
  2031. // ISSUE: jonwis 3/11/2002 - More dead code. Will the madness ever end??
  2032. //
  2033. // NTRAID#NTBUG9 - 572507 - jonwis - 2002/04/25 - Dead code probably
  2034. BOOL
  2035. CNodeFactory::ParseElementAttributes(
  2036. USHORT cNumRecs,
  2037. XML_NODE_INFO **prgpNodeInfo,
  2038. SIZE_T cEntries,
  2039. const AttributeMapEntry *prgEntries
  2040. )
  2041. {
  2042. FN_PROLOG_WIN32
  2043. ULONG i, j;
  2044. for (i=1; i<cNumRecs; i++)
  2045. {
  2046. // Skip things we don't understand.
  2047. if (prgpNodeInfo[i]->dwType != XML_ATTRIBUTE)
  2048. continue;
  2049. for (j=0; j<cEntries; j++)
  2050. {
  2051. if (::FusionpEqualStrings(
  2052. prgEntries[j].m_pszAttributeName,
  2053. prgEntries[j].m_cchAttributeName,
  2054. prgpNodeInfo[i]->pwcText,
  2055. prgpNodeInfo[i]->ulLen,
  2056. false))
  2057. {
  2058. // Because attribute values may be multipart due to entity references,
  2059. // we accumulate the attibute value into buffTemp to start, and then do
  2060. // the parsing/whatever afterwards.
  2061. CStringBuffer buffTemp;
  2062. BOOL *pfIndicator = (BOOL *) (((ULONG_PTR) this) + prgEntries[j].m_offsetIndicator);
  2063. while ((++i < cNumRecs) &&
  2064. (prgpNodeInfo[i]->dwType == XML_PCDATA))
  2065. {
  2066. IFW32FALSE_EXIT(buffTemp.Win32Append(prgpNodeInfo[i]->pwcText, prgpNodeInfo[i]->ulLen));
  2067. }
  2068. // The outer for(;;) loop is going to increment i, so we need to back it up one
  2069. // place...
  2070. i--;
  2071. // Call the appropriate value type handler function...
  2072. if (prgEntries[j].m_pfn != NULL)
  2073. {
  2074. IFW32FALSE_EXIT((this->*(prgEntries[j].m_pfn))(((LPBYTE) this) + prgEntries[j].m_offsetData, *pfIndicator, buffTemp));
  2075. }
  2076. *pfIndicator = TRUE;
  2077. break;
  2078. }
  2079. }
  2080. }
  2081. FN_EPILOG
  2082. }
  2083. HRESULT
  2084. CNodeFactory::LogParseError(
  2085. DWORD dwLastParseError,
  2086. const UNICODE_STRING *p1,
  2087. const UNICODE_STRING *p2,
  2088. const UNICODE_STRING *p3,
  2089. const UNICODE_STRING *p4,
  2090. const UNICODE_STRING *p5,
  2091. const UNICODE_STRING *p6,
  2092. const UNICODE_STRING *p7,
  2093. const UNICODE_STRING *p8,
  2094. const UNICODE_STRING *p9,
  2095. const UNICODE_STRING *p10,
  2096. const UNICODE_STRING *p11,
  2097. const UNICODE_STRING *p12,
  2098. const UNICODE_STRING *p13,
  2099. const UNICODE_STRING *p14,
  2100. const UNICODE_STRING *p15,
  2101. const UNICODE_STRING *p16,
  2102. const UNICODE_STRING *p17,
  2103. const UNICODE_STRING *p18,
  2104. const UNICODE_STRING *p19,
  2105. const UNICODE_STRING *p20
  2106. )
  2107. {
  2108. return
  2109. ::FusionpLogParseError(
  2110. m_ParseContext.SourceFile,
  2111. m_ParseContext.SourceFileCch,
  2112. m_ParseContext.LineNumber,
  2113. dwLastParseError,
  2114. p1, p2, p3, p4, p5,
  2115. p6, p7, p8, p9, p10,
  2116. p11, p12, p13, p14, p15,
  2117. p16, p17, p18, p19, p20);
  2118. }
  2119. VOID
  2120. CNodeFactory::ParseErrorCallback_MissingRequiredAttribute(
  2121. PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  2122. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  2123. )
  2124. {
  2125. // CNodeFactory *pThis = (CNodeFactory *) ErrorContext;
  2126. ::FusionpLogRequiredAttributeMissingParseError(
  2127. ParseContext->SourceFile,
  2128. ParseContext->SourceFileCch,
  2129. ParseContext->LineNumber,
  2130. ParseContext->ElementName,
  2131. ParseContext->ElementNameCch,
  2132. AttributeName->Name,
  2133. AttributeName->NameCch);
  2134. }
  2135. VOID
  2136. CNodeFactory::ParseErrorCallback_InvalidAttributeValue(
  2137. PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  2138. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  2139. )
  2140. {
  2141. // CNodeFactory *pThis = (CNodeFactory *) ErrorContext;
  2142. ::FusionpLogInvalidAttributeValueParseError(
  2143. ParseContext->SourceFile,
  2144. ParseContext->SourceFileCch,
  2145. ParseContext->LineNumber,
  2146. ParseContext->ElementName,
  2147. ParseContext->ElementNameCch,
  2148. AttributeName->Name,
  2149. AttributeName->NameCch);
  2150. }
  2151. VOID
  2152. CNodeFactory::ParseErrorCallback_AttributeNotAllowed(
  2153. PCACTCTXCTB_PARSE_CONTEXT ParseContext,
  2154. IN PCATTRIBUTE_NAME_DESCRIPTOR AttributeName
  2155. )
  2156. {
  2157. // CNodeFactory *pThis = (CNodeFactory *) ErrorContext;
  2158. ::FusionpLogAttributeNotAllowedParseError(
  2159. ParseContext->SourceFile,
  2160. ParseContext->SourceFileCch,
  2161. ParseContext->LineNumber,
  2162. ParseContext->ElementName,
  2163. ParseContext->ElementNameCch,
  2164. AttributeName->Name,
  2165. AttributeName->NameCch);
  2166. }
  2167. VOID
  2168. SxspDbgPrintXmlNodeInfo(
  2169. ULONG Level,
  2170. XML_NODE_INFO *pNode
  2171. )
  2172. {
  2173. CUnicodeString s(pNode->pwcText, pNode->ulLen);
  2174. #if DBG_SXS
  2175. ::FusionpDbgPrintEx(Level, "SXS.DLL: XML_NODE_INFO at %p\n", pNode);
  2176. ::FusionpDbgPrintEx(Level, " dwSize = %d\n", pNode->dwSize);
  2177. ::FusionpDbgPrintEx(Level, " dwType = %d (%s)\n", pNode->dwType, SxspFormatXmlNodeType(pNode->dwType));
  2178. ::FusionpDbgPrintEx(Level, " dwSubType = %d\n", pNode->dwSubType);
  2179. ::FusionpDbgPrintEx(Level, " fTerminal = %d\n", pNode->fTerminal);
  2180. ::FusionpDbgPrintEx(Level, " pwcText = %p (\"%wZ\")\n", pNode->pwcText, &s);
  2181. ::FusionpDbgPrintEx(Level, " ulLen = %d\n", pNode->ulLen);
  2182. ::FusionpDbgPrintEx(Level, " ulNsPrefixLen = %d\n", pNode->ulNsPrefixLen);
  2183. ::FusionpDbgPrintEx(Level, " pNode = %p\n", pNode->pNode);
  2184. ::FusionpDbgPrintEx(Level, " pReserved = %p\n", pNode->pReserved);
  2185. #else
  2186. ::FusionpDbgPrintEx(Level, "SXS.DLL: XML_NODE_INFO at %p: \"%wZ\"\n", pNode, &s);
  2187. #endif
  2188. }
  2189. PCSTR
  2190. SxspFormatXmlNodeType(
  2191. DWORD dwType
  2192. )
  2193. {
  2194. PCSTR Result = "Unknown";
  2195. #define HANDLE_NODE_TYPE(x) case static_cast<DWORD>(x): Result = #x; break;
  2196. switch (dwType)
  2197. {
  2198. HANDLE_NODE_TYPE(XML_ELEMENT)
  2199. HANDLE_NODE_TYPE(XML_ATTRIBUTE)
  2200. HANDLE_NODE_TYPE(XML_PI)
  2201. HANDLE_NODE_TYPE(XML_XMLDECL)
  2202. HANDLE_NODE_TYPE(XML_DOCTYPE)
  2203. HANDLE_NODE_TYPE(XML_DTDATTRIBUTE)
  2204. HANDLE_NODE_TYPE(XML_ENTITYDECL)
  2205. HANDLE_NODE_TYPE(XML_ELEMENTDECL)
  2206. HANDLE_NODE_TYPE(XML_ATTLISTDECL)
  2207. HANDLE_NODE_TYPE(XML_NOTATION)
  2208. HANDLE_NODE_TYPE(XML_GROUP)
  2209. HANDLE_NODE_TYPE(XML_INCLUDESECT)
  2210. HANDLE_NODE_TYPE(XML_PCDATA)
  2211. HANDLE_NODE_TYPE(XML_CDATA)
  2212. HANDLE_NODE_TYPE(XML_IGNORESECT)
  2213. HANDLE_NODE_TYPE(XML_COMMENT)
  2214. HANDLE_NODE_TYPE(XML_ENTITYREF)
  2215. HANDLE_NODE_TYPE(XML_WHITESPACE)
  2216. HANDLE_NODE_TYPE(XML_NAME)
  2217. HANDLE_NODE_TYPE(XML_NMTOKEN)
  2218. HANDLE_NODE_TYPE(XML_STRING)
  2219. HANDLE_NODE_TYPE(XML_PEREF)
  2220. HANDLE_NODE_TYPE(XML_MODEL)
  2221. HANDLE_NODE_TYPE(XML_ATTDEF)
  2222. HANDLE_NODE_TYPE(XML_ATTTYPE)
  2223. HANDLE_NODE_TYPE(XML_ATTPRESENCE)
  2224. HANDLE_NODE_TYPE(XML_DTDSUBSET)
  2225. }
  2226. return Result;
  2227. }
  2228. BOOL
  2229. CNodeFactory::ValidateIdentity(
  2230. DWORD Flags,
  2231. ULONG Type,
  2232. PCASSEMBLY_IDENTITY AssemblyIdentity
  2233. )
  2234. {
  2235. FN_PROLOG_WIN32
  2236. PCWSTR pszTemp = NULL;
  2237. SIZE_T cchTemp = 0;
  2238. bool fSyntaxValid = false;
  2239. bool fError = false;
  2240. BOOL fIsPolicy;
  2241. PARAMETER_CHECK((Flags & ~(
  2242. eValidateIdentity_VersionRequired |
  2243. eValidateIdentity_PoliciesNotAllowed |
  2244. eValidateIdentity_VersionNotAllowed)) == 0);
  2245. PARAMETER_CHECK((Type == ASSEMBLY_IDENTITY_TYPE_DEFINITION) || (Type == ASSEMBLY_IDENTITY_TYPE_REFERENCE));
  2246. PARAMETER_CHECK(AssemblyIdentity != NULL);
  2247. //
  2248. // only one of these flags is allowed
  2249. //
  2250. PARAMETER_CHECK(
  2251. (Flags & (eValidateIdentity_VersionRequired | eValidateIdentity_VersionNotAllowed)) !=
  2252. (eValidateIdentity_VersionRequired | eValidateIdentity_VersionNotAllowed));
  2253. //
  2254. // Get the type of this assembly
  2255. //
  2256. IFW32FALSE_EXIT(::SxspDetermineAssemblyType(AssemblyIdentity, fIsPolicy));
  2257. //
  2258. // If it's policy, then make sure that policies are allowed. Otherwise, fail out.
  2259. //
  2260. if (fIsPolicy)
  2261. {
  2262. m_AssemblyContext->Flags |= ACTCTXCTB_ASSEMBLY_CONTEXT_IS_SYSTEM_POLICY_INSTALLATION;
  2263. if (Flags & eValidateIdentity_PoliciesNotAllowed)
  2264. {
  2265. CUnicodeString usType(pszTemp, cchTemp);
  2266. fError = true;
  2267. ::FusionpDbgPrintEx(
  2268. FUSION_DBG_LEVEL_ERROR,
  2269. "SXS.DLL: Manifest \"%ls\" (line %d) has invalid type attribute \"%wZ\"; report to owner of \"%ls\"\n",
  2270. m_ParseContext.SourceFile,
  2271. m_ParseContext.LineNumber,
  2272. &usType,
  2273. m_ParseContext.SourceFile);
  2274. }
  2275. }
  2276. IFW32FALSE_EXIT(
  2277. ::SxspGetAssemblyIdentityAttributeValue(
  2278. SXSP_GET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_NOT_FOUND_RETURNS_NULL,
  2279. AssemblyIdentity,
  2280. &s_IdentityAttribute_name,
  2281. &pszTemp,
  2282. &cchTemp));
  2283. if (cchTemp == 0)
  2284. {
  2285. ::FusionpDbgPrintEx(
  2286. FUSION_DBG_LEVEL_ERROR,
  2287. "SXS.DLL: Manifest \"%ls\" (line %d) is missing name attribute; report to owner of \"%ls\"\n",
  2288. m_ParseContext.SourceFile,
  2289. m_ParseContext.LineNumber,
  2290. m_ParseContext.SourceFile);
  2291. fError = true;
  2292. }
  2293. IFW32FALSE_EXIT(
  2294. ::SxspGetAssemblyIdentityAttributeValue(
  2295. SXSP_GET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_NOT_FOUND_RETURNS_NULL,
  2296. AssemblyIdentity,
  2297. &s_IdentityAttribute_processorArchitecture,
  2298. &pszTemp,
  2299. &cchTemp));
  2300. IFW32FALSE_EXIT(
  2301. ::SxspGetAssemblyIdentityAttributeValue(
  2302. SXSP_GET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_NOT_FOUND_RETURNS_NULL,
  2303. AssemblyIdentity,
  2304. &s_IdentityAttribute_version,
  2305. &pszTemp,
  2306. &cchTemp));
  2307. if (cchTemp != 0)
  2308. {
  2309. ASSEMBLY_VERSION av;
  2310. IFW32FALSE_EXIT(CFusionParser::ParseVersion(av, pszTemp, cchTemp, fSyntaxValid));
  2311. if (!fSyntaxValid)
  2312. {
  2313. ::FusionpLogInvalidAttributeValueParseError(
  2314. m_ParseContext.SourceFile,
  2315. m_ParseContext.SourceFileCch,
  2316. m_ParseContext.LineNumber,
  2317. m_ParseContext.ElementName,
  2318. m_ParseContext.ElementNameCch,
  2319. s_IdentityAttribute_version);
  2320. ORIGINATE_WIN32_FAILURE_AND_EXIT(InvalidVersionNumber, ERROR_SXS_MANIFEST_PARSE_ERROR);
  2321. }
  2322. }
  2323. if ((Flags & (eValidateIdentity_VersionNotAllowed | eValidateIdentity_VersionRequired)) != 0)
  2324. {
  2325. if ((Flags & eValidateIdentity_VersionNotAllowed) != 0 && cchTemp != 0)
  2326. {
  2327. fError = true;
  2328. ::FusionpDbgPrintEx(
  2329. FUSION_DBG_LEVEL_ERROR,
  2330. "SXS.DLL: Manifest \"%ls\" (line %d) has a version attribute where it may not appear; report to owner of \"%ls\"\n",
  2331. m_ParseContext.SourceFile,
  2332. m_ParseContext.LineNumber,
  2333. m_ParseContext.SourceFile);
  2334. }
  2335. else if ((Flags & eValidateIdentity_VersionRequired) != 0 && cchTemp == 0)
  2336. {
  2337. fError = true;
  2338. ::FusionpDbgPrintEx(
  2339. FUSION_DBG_LEVEL_ERROR,
  2340. "SXS.DLL: Manifest \"%ls\" (line %d) is missing version attribute; report to owner of \"%ls\"\n",
  2341. m_ParseContext.SourceFile,
  2342. m_ParseContext.LineNumber,
  2343. m_ParseContext.SourceFile);
  2344. }
  2345. }
  2346. if (fError)
  2347. {
  2348. ::FusionpDbgPrintEx(
  2349. FUSION_DBG_LEVEL_ERROR,
  2350. "SXS.DLL: Manifest \"%ls\" is missing required attribute or contains disallowed attribute; report to owner of \"%ls\"\n",
  2351. m_ParseContext.SourceFile,
  2352. m_ParseContext.SourceFile);
  2353. ORIGINATE_WIN32_FAILURE_AND_EXIT(InvalidIdentity, ERROR_SXS_MANIFEST_PARSE_ERROR);
  2354. }
  2355. FN_EPILOG
  2356. }
  2357. BOOL
  2358. CNodeFactory::ValidateElementAttributes(
  2359. PCSXS_NODE_INFO prgNodes,
  2360. SIZE_T cNodes,
  2361. PCELEMENT_LEGAL_ATTRIBUTE prgAttributes,
  2362. UCHAR cAttributes
  2363. )
  2364. {
  2365. FN_PROLOG_WIN32
  2366. SIZE_T i;
  2367. UCHAR j;
  2368. UCHAR cRequiredAttributes, cRequiredAttributesFound;
  2369. UCHAR rgRequiredAttributeFoundBitMask[8]; // 8 * 32 = 256
  2370. BOOL fParseFailed = FALSE;
  2371. PARAMETER_CHECK((cNodes == 0) || (prgNodes != NULL));
  2372. PARAMETER_CHECK((cAttributes == 0) || (prgAttributes != NULL));
  2373. cRequiredAttributes = 0;
  2374. cRequiredAttributesFound = 0;
  2375. for (i=0; i<cAttributes; i++)
  2376. if (prgAttributes[i].m_dwFlags & ELEMENT_LEGAL_ATTRIBUTE_FLAG_REQUIRED)
  2377. cRequiredAttributes++;
  2378. rgRequiredAttributeFoundBitMask[0] = 0;
  2379. rgRequiredAttributeFoundBitMask[1] = 0;
  2380. rgRequiredAttributeFoundBitMask[2] = 0;
  2381. rgRequiredAttributeFoundBitMask[3] = 0;
  2382. rgRequiredAttributeFoundBitMask[4] = 0;
  2383. rgRequiredAttributeFoundBitMask[5] = 0;
  2384. rgRequiredAttributeFoundBitMask[6] = 0;
  2385. rgRequiredAttributeFoundBitMask[7] = 0;
  2386. for (i=0; i<cNodes; i++)
  2387. {
  2388. if (prgNodes[i].Type == SXS_ATTRIBUTE)
  2389. {
  2390. const SIZE_T cchText = prgNodes[i].cchText;
  2391. const SIZE_T cchNamespace = prgNodes[i].NamespaceStringBuf.Cch();
  2392. const PCWSTR pszText = prgNodes[i].pszText;
  2393. // Ignore any attributes that start with xml
  2394. if ((cchText >= 3) &&
  2395. ((pszText[0] == L'x') || (pszText[0] == L'X')) &&
  2396. ((pszText[1] == L'm') || (pszText[1] == L'M')) &&
  2397. ((pszText[2] == L'l') || (pszText[2] == L'L')))
  2398. {
  2399. continue;
  2400. }
  2401. if (cchNamespace != 0 )
  2402. {
  2403. continue;
  2404. }
  2405. for (j=0; j<cAttributes; j++)
  2406. {
  2407. if ((prgAttributes[j].m_pName != NULL) &&
  2408. ::FusionpEqualStrings(prgNodes[i].NamespaceStringBuf, cchNamespace, prgAttributes[j].m_pName->Namespace, prgAttributes[j].m_pName->NamespaceCch, false) &&
  2409. ::FusionpEqualStrings(pszText, cchText, prgAttributes[j].m_pName->Name, prgAttributes[j].m_pName->NameCch, false))
  2410. {
  2411. if (prgAttributes[j].m_pfnValidator != NULL)
  2412. {
  2413. CSmallStringBuffer buffValue;
  2414. bool fValid = false;
  2415. SIZE_T cb;
  2416. SIZE_T i2;
  2417. for (i2=i+1; i2<cNodes; i2++)
  2418. {
  2419. if (prgNodes[i2].Type == SXS_PCDATA)
  2420. IFW32FALSE_EXIT(buffValue.Win32Append(prgNodes[i2].pszText, prgNodes[i2].cchText));
  2421. else
  2422. break;
  2423. }
  2424. IFW32FALSE_EXIT(
  2425. (*prgAttributes[j].m_pfnValidator)(
  2426. prgAttributes[j].m_dwValidatorFlags,
  2427. buffValue,
  2428. fValid,
  2429. 0,
  2430. NULL,
  2431. cb));
  2432. if (!fValid)
  2433. {
  2434. ::FusionpLogInvalidAttributeValueParseError(
  2435. m_ParseContext.SourceFile,
  2436. m_ParseContext.SourceFileCch,
  2437. m_ParseContext.LineNumber,
  2438. m_ParseContext.ElementName,
  2439. m_ParseContext.ElementNameCch,
  2440. prgAttributes[j].m_pName->Name,
  2441. prgAttributes[j].m_pName->NameCch);
  2442. ORIGINATE_WIN32_FAILURE_AND_EXIT(InvalidAttributeValue, ERROR_SXS_MANIFEST_PARSE_ERROR);
  2443. }
  2444. }
  2445. if (prgAttributes[j].m_dwFlags & ELEMENT_LEGAL_ATTRIBUTE_FLAG_REQUIRED)
  2446. {
  2447. rgRequiredAttributeFoundBitMask[(j / 32)] |= (1 << (j % 32));
  2448. cRequiredAttributesFound++;
  2449. }
  2450. break;
  2451. }
  2452. }
  2453. if (j == cAttributes)
  2454. {
  2455. // We found an illegal attribute!!
  2456. ::FusionpLogAttributeNotAllowedParseError(
  2457. m_ParseContext.SourceFile,
  2458. m_ParseContext.SourceFileCch,
  2459. m_ParseContext.LineNumber,
  2460. prgNodes[0].pszText,
  2461. prgNodes[0].cchText,
  2462. prgNodes[i].pszText,
  2463. prgNodes[i].cchText);
  2464. // We don't just go to exit here because we want to report all the bad attributes and missing attributes...
  2465. fParseFailed = TRUE;
  2466. }
  2467. }
  2468. }
  2469. if (cRequiredAttributesFound != cRequiredAttributes)
  2470. {
  2471. for (j=0; j<cAttributes; j++)
  2472. {
  2473. if (prgAttributes[j].m_dwFlags & ELEMENT_LEGAL_ATTRIBUTE_FLAG_REQUIRED)
  2474. {
  2475. if ((rgRequiredAttributeFoundBitMask[(j / 32)] & (1 << (j % 32))) == 0)
  2476. {
  2477. ::FusionpLogRequiredAttributeMissingParseError(
  2478. m_ParseContext.SourceFile,
  2479. m_ParseContext.SourceFileCch,
  2480. m_ParseContext.LineNumber,
  2481. prgNodes[0].pszText,
  2482. prgNodes[0].cchText,
  2483. prgAttributes[j].m_pName->Name,
  2484. prgAttributes[j].m_pName->NameCch);
  2485. fParseFailed = TRUE;
  2486. }
  2487. }
  2488. }
  2489. }
  2490. if (fParseFailed)
  2491. ORIGINATE_WIN32_FAILURE_AND_EXIT(ParseError, ERROR_SXS_MANIFEST_PARSE_ERROR);
  2492. FN_EPILOG
  2493. }