Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. parsepolicy.cpp
  5. Abstract:
  6. Functions to parse configuration (policy) manifests.
  7. Author:
  8. Michael J. Grier (MGrier) January 12, 2001
  9. Revision History:
  10. --*/
  11. #include "stdinc.h"
  12. #include <windows.h>
  13. #include "sxsp.h"
  14. #include "probedassemblyinformation.h"
  15. #include "fusionparser.h"
  16. #include "cteestream.h"
  17. #include "cresourcestream.h"
  18. #include "nodefactory.h"
  19. #include "fusioneventlog.h"
  20. #include "actctxgenctx.h"
  21. extern CHAR NodefactoryTypeName[] = "CNodeFactory";
  22. SxspComponentParsePolicyCore(
  23. ULONG Flags,
  24. PACTCTXGENCTX pGenContext,
  25. const CProbedAssemblyInformation &PolicyAssemblyInformation,
  26. CPolicyStatement *&rpPolicyStatement,
  27. IStream *pSourceStream,
  28. ACTCTXCTB_ASSEMBLY_CONTEXT *pAssemblyContext = NULL
  29. )
  30. {
  31. BOOL fSuccess = FALSE;
  32. FN_TRACE_WIN32(fSuccess);
  33. CSxsPointer<CNodeFactory, NodefactoryTypeName> NodeFactory;
  34. CSmartRef<IXMLParser> pIXmlParser;
  35. PASSEMBLY Assembly = NULL;
  36. CSxsPointerWithNamedDestructor<ASSEMBLY_IDENTITY, &::SxsDestroyAssemblyIdentity> AssemblyIdentity;
  37. ACTCTXCTB_ASSEMBLY_CONTEXT LocalAssemblyContext;
  38. STATSTG Stats;
  39. ULONG i;
  40. rpPolicyStatement = NULL;
  41. PARAMETER_CHECK(pGenContext != NULL);
  42. PARAMETER_CHECK(pSourceStream != NULL);
  43. if (pAssemblyContext == NULL)
  44. {
  45. pAssemblyContext = &LocalAssemblyContext;
  46. }
  47. IFALLOCFAILED_EXIT(Assembly = new ASSEMBLY);
  48. IFW32FALSE_EXIT(Assembly->m_Information.Initialize(PolicyAssemblyInformation));
  49. //
  50. // Copy the assembly identity, stick it into the callback structure
  51. //
  52. IFW32FALSE_EXIT(
  53. ::SxsDuplicateAssemblyIdentity(
  54. 0,
  55. PolicyAssemblyInformation.GetAssemblyIdentity(),
  56. &AssemblyIdentity));
  57. //
  58. // Set up the structure in general
  59. //
  60. pAssemblyContext->AssemblyIdentity = AssemblyIdentity.Detach();
  61. IFW32FALSE_EXIT(
  62. PolicyAssemblyInformation.GetManifestPath(
  63. &pAssemblyContext->ManifestPath,
  64. &pAssemblyContext->ManifestPathCch));
  65. IFCOMFAILED_ORIGINATE_AND_EXIT(pSourceStream->Stat(&Stats, STATFLAG_NONAME));
  66. //
  67. // Set up the node factory
  68. //
  69. IFW32FALSE_EXIT(NodeFactory.Win32Allocate(__FILE__, __LINE__));
  70. IFW32FALSE_EXIT(NodeFactory->Initialize(pGenContext, Assembly, pAssemblyContext));
  71. IFCOMFAILED_ORIGINATE_AND_EXIT(NodeFactory->SetParseType(
  72. XML_FILE_TYPE_COMPONENT_CONFIGURATION,
  73. PolicyAssemblyInformation.GetManifestPathType(),
  74. PolicyAssemblyInformation.GetManifestPath(),
  75. Stats.mtime));
  76. //
  77. // Obtain the parser
  78. //
  79. IFW32FALSE_EXIT(::SxspGetXMLParser(IID_IXMLParser, (PVOID*)&pIXmlParser));
  80. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXmlParser->SetFactory(NodeFactory));
  81. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXmlParser->SetInput(pSourceStream));
  82. //
  83. // And they're off!
  84. //
  85. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXmlParser->Run(-1));
  86. //
  87. // Tell the contributors we want to be done with this file...
  88. //
  89. for (i = 0; i < pGenContext->m_ContributorCount; i++)
  90. {
  91. IFW32FALSE_EXIT(pGenContext->m_Contributors[i].Fire_ParseEnding(pGenContext, pAssemblyContext));
  92. }
  93. rpPolicyStatement = NodeFactory->m_CurrentPolicyStatement;
  94. NodeFactory->m_CurrentPolicyStatement = NULL;
  95. fSuccess = TRUE;
  96. Exit:
  97. {
  98. CSxsPreserveLastError ple;
  99. for (i = 0; i < pGenContext->m_ContributorCount; i++)
  100. {
  101. pGenContext->m_Contributors[i].Fire_ParseEnded(pGenContext, pAssemblyContext);
  102. }
  103. if (Assembly != NULL)
  104. Assembly->Release();
  105. ple.Restore();
  106. }
  107. return fSuccess;
  108. }
  109. BOOL
  110. SxspParseNdpGacComponentPolicy(
  111. ULONG Flags,
  112. PACTCTXGENCTX pGenContext,
  113. const CProbedAssemblyInformation &PolicyAssemblyInformation,
  114. CPolicyStatement *&rpPolicyStatement
  115. )
  116. {
  117. FN_PROLOG_WIN32;
  118. CResourceStream DllStream;
  119. IFW32FALSE_EXIT(
  120. DllStream.Initialize(
  121. PolicyAssemblyInformation.GetManifestPath(),
  122. MAKEINTRESOURCEW(RT_MANIFEST)));
  123. IFW32FALSE_EXIT(SxspComponentParsePolicyCore(
  124. Flags,
  125. pGenContext,
  126. PolicyAssemblyInformation,
  127. rpPolicyStatement,
  128. &DllStream));
  129. FN_EPILOG;
  130. }
  131. BOOL
  132. SxspParseComponentPolicy(
  133. DWORD Flags,
  134. PACTCTXGENCTX pActCtxGenCtx,
  135. const CProbedAssemblyInformation &PolicyAssemblyInformation,
  136. CPolicyStatement *&rpPolicyStatement
  137. )
  138. {
  139. FN_PROLOG_WIN32;
  140. CFileStream FileStream;
  141. IFW32FALSE_EXIT(
  142. FileStream.OpenForRead(
  143. PolicyAssemblyInformation.GetManifestPath(),
  144. CImpersonationData(),
  145. FILE_SHARE_READ,
  146. OPEN_EXISTING,
  147. FILE_FLAG_SEQUENTIAL_SCAN));
  148. IFW32FALSE_EXIT(SxspComponentParsePolicyCore(
  149. Flags,
  150. pActCtxGenCtx,
  151. PolicyAssemblyInformation,
  152. rpPolicyStatement,
  153. &FileStream));
  154. FN_EPILOG;
  155. }
  156. BOOL
  157. SxspParseApplicationPolicy(
  158. DWORD Flags,
  159. PACTCTXGENCTX pActCtxGenCtx,
  160. ULONG ulPolicyPathType,
  161. PCWSTR pszPolicyPath,
  162. SIZE_T cchPolicyPath,
  163. IStream *pIStream
  164. )
  165. {
  166. BOOL fSuccess = FALSE;
  167. FN_TRACE_WIN32(fSuccess);
  168. // declaration order here is partially deliberate, to control cleanup order.
  169. // normally, declaration order is determined by not declaring until you have
  170. // the data to initialize with the ctor, but the use of goto messes that up
  171. CSxsPointer<CNodeFactory, NodefactoryTypeName> NodeFactory;
  172. CSmartRef<IXMLParser> pIXMLParser;
  173. ACTCTXCTB_ASSEMBLY_CONTEXT AssemblyContext;
  174. ULONG i;
  175. PASSEMBLY Assembly = NULL;
  176. CStringBuffer buffPath;
  177. STATSTG statstg;
  178. PARAMETER_CHECK(Flags == 0);
  179. PARAMETER_CHECK(pActCtxGenCtx != NULL);
  180. PARAMETER_CHECK(ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE);
  181. IFALLOCFAILED_EXIT(Assembly = new ASSEMBLY);
  182. IFW32FALSE_EXIT(buffPath.Win32Assign(pszPolicyPath, cchPolicyPath));
  183. IFW32FALSE_EXIT(Assembly->m_Information.Initialize());
  184. AssemblyContext.AssemblyIdentity = NULL;
  185. AssemblyContext.Flags = 0;
  186. AssemblyContext.AssemblyRosterIndex = 1; // hack alert
  187. AssemblyContext.PolicyPathType = ulPolicyPathType;
  188. AssemblyContext.PolicyPath = pszPolicyPath;
  189. AssemblyContext.PolicyPathCch = cchPolicyPath;
  190. AssemblyContext.ManifestPathType = ACTIVATION_CONTEXT_PATH_TYPE_NONE;
  191. AssemblyContext.ManifestPath = NULL;
  192. AssemblyContext.ManifestPathCch = 0;
  193. AssemblyContext.TeeStreamForManifestInstall = NULL;
  194. AssemblyContext.pcmWriterStream = NULL;
  195. AssemblyContext.InstallationInfo = NULL;
  196. AssemblyContext.AssemblySecurityContext = NULL;
  197. AssemblyContext.TextuallyEncodedIdentity = NULL;
  198. AssemblyContext.TextuallyEncodedIdentityCch = 0;
  199. IFW32FALSE_EXIT(NodeFactory.Win32Allocate(__FILE__, __LINE__));
  200. IFW32FALSE_EXIT(NodeFactory->Initialize(pActCtxGenCtx, Assembly, &AssemblyContext));
  201. NodeFactory->m_pApplicationPolicyTable = &pActCtxGenCtx->m_ApplicationPolicyTable;
  202. // Everyone's ready; let's get the XML parser:
  203. IFW32FALSE_EXIT(::SxspGetXMLParser(IID_IXMLParser, (LPVOID *) &pIXMLParser));
  204. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXMLParser->SetFactory(NodeFactory));
  205. IFCOMFAILED_EXIT(pIStream->Stat(&statstg, STATFLAG_NONAME));
  206. // Open up the policy file and try parsing it...
  207. IFW32FALSE_EXIT(
  208. NodeFactory->SetParseType(
  209. XML_FILE_TYPE_APPLICATION_CONFIGURATION,
  210. ulPolicyPathType,
  211. buffPath,
  212. statstg.mtime));
  213. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXMLParser->SetInput(pIStream));
  214. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXMLParser->Run(-1));
  215. NodeFactory->m_CurrentPolicyStatement = NULL;
  216. // Tell the contributors we want to be done with this file...
  217. for (i=0; i<pActCtxGenCtx->m_ContributorCount; i++)
  218. IFW32FALSE_EXIT(pActCtxGenCtx->m_Contributors[i].Fire_ParseEnding(pActCtxGenCtx, &AssemblyContext));
  219. fSuccess = TRUE;
  220. Exit:
  221. CSxsPreserveLastError ple;
  222. // And tell them we're done.
  223. for (i=0; i<pActCtxGenCtx->m_ContributorCount; i++)
  224. pActCtxGenCtx->m_Contributors[i].Fire_ParseEnded(pActCtxGenCtx, &AssemblyContext);
  225. if ( ple.LastError() == ERROR_SXS_MANIFEST_PARSE_ERROR || ple.LastError() == ERROR_SXS_MANIFEST_FORMAT_ERROR)
  226. { // log a general failure eventlog
  227. ::FusionpLogError(MSG_SXS_PARSE_MANIFEST_FAILED);
  228. }
  229. if (Assembly != NULL)
  230. Assembly->Release();
  231. ple.Restore();
  232. return fSuccess;
  233. }