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.

304 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 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. SxspComponentParsePolicyCore(
  22. ULONG Flags,
  23. PACTCTXGENCTX pGenContext,
  24. const CProbedAssemblyInformation &PolicyAssemblyInformation,
  25. CPolicyStatement *&rpPolicyStatement,
  26. IStream *pSourceStream,
  27. ACTCTXCTB_ASSEMBLY_CONTEXT *pAssemblyContext = NULL
  28. )
  29. {
  30. BOOL fSuccess = FALSE;
  31. FN_TRACE_WIN32(fSuccess);
  32. CSmartPtr<CNodeFactory> NodeFactory;
  33. CSmartRef<IXMLParser> pIXmlParser;
  34. PASSEMBLY Assembly = NULL;
  35. CSmartPtrWithNamedDestructor<ASSEMBLY_IDENTITY, &::SxsDestroyAssemblyIdentity> AssemblyIdentity;
  36. ACTCTXCTB_ASSEMBLY_CONTEXT LocalAssemblyContext;
  37. STATSTG Stats;
  38. ULONG i;
  39. rpPolicyStatement = NULL;
  40. PARAMETER_CHECK(pGenContext != NULL);
  41. PARAMETER_CHECK(pSourceStream != NULL);
  42. if (pAssemblyContext == NULL)
  43. {
  44. pAssemblyContext = &LocalAssemblyContext;
  45. }
  46. IFW32FALSE_EXIT(Assembly = new ASSEMBLY);
  47. IFW32FALSE_EXIT(Assembly->m_ProbedAssemblyInformation.Initialize(PolicyAssemblyInformation));
  48. //
  49. // Copy the assembly identity, stick it into the callback structure
  50. //
  51. IFW32FALSE_EXIT(
  52. ::SxsDuplicateAssemblyIdentity(
  53. 0,
  54. PolicyAssemblyInformation.GetAssemblyIdentity(),
  55. &AssemblyIdentity));
  56. //
  57. // Set up the structure in general
  58. //
  59. pAssemblyContext->AssemblyIdentity = AssemblyIdentity.DetachAndHold();
  60. IFW32FALSE_EXIT(
  61. PolicyAssemblyInformation.GetManifestPath(
  62. &pAssemblyContext->ManifestPath,
  63. &pAssemblyContext->ManifestPathCch));
  64. IFCOMFAILED_ORIGINATE_AND_EXIT(pSourceStream->Stat(&Stats, STATFLAG_NONAME));
  65. //
  66. // Set up the node factory
  67. //
  68. IFW32FALSE_EXIT(NodeFactory.Win32Allocate(__FILE__, __LINE__));
  69. IFW32FALSE_EXIT(NodeFactory->Initialize(pGenContext, Assembly, pAssemblyContext));
  70. IFW32FALSE_EXIT(NodeFactory->SetParseType(
  71. XML_FILE_TYPE_COMPONENT_CONFIGURATION,
  72. PolicyAssemblyInformation.GetManifestPathType(),
  73. PolicyAssemblyInformation.GetManifestPath(),
  74. Stats.mtime));
  75. //
  76. // Obtain the parser
  77. //
  78. IFW32FALSE_EXIT(::SxspGetXMLParser(IID_IXMLParser, (PVOID*)&pIXmlParser));
  79. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXmlParser->SetFactory(NodeFactory));
  80. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXmlParser->SetInput(pSourceStream));
  81. //
  82. // And they're off!
  83. //
  84. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXmlParser->Run(-1));
  85. //
  86. // Tell the contributors we want to be done with this file...
  87. //
  88. for (i = 0; i < pGenContext->m_ContributorCount; i++)
  89. {
  90. IFW32FALSE_EXIT(pGenContext->m_Contributors[i].Fire_ParseEnding(pGenContext, pAssemblyContext));
  91. }
  92. rpPolicyStatement = NodeFactory->m_CurrentPolicyStatement;
  93. NodeFactory->m_CurrentPolicyStatement = NULL;
  94. fSuccess = TRUE;
  95. Exit:
  96. {
  97. CSxsPreserveLastError ple;
  98. for (i = 0; i < pGenContext->m_ContributorCount; i++)
  99. {
  100. pGenContext->m_Contributors[i].Fire_ParseEnded(pGenContext, pAssemblyContext);
  101. }
  102. if (Assembly != NULL)
  103. Assembly->Release();
  104. ple.Restore();
  105. }
  106. return fSuccess;
  107. }
  108. BOOL
  109. SxspParseNdpGacComponentPolicy(
  110. ULONG Flags,
  111. PACTCTXGENCTX pGenContext,
  112. const CProbedAssemblyInformation &PolicyAssemblyInformation,
  113. CPolicyStatement *&rpPolicyStatement
  114. )
  115. {
  116. FN_PROLOG_WIN32
  117. CResourceStream DllStream;
  118. IFW32FALSE_EXIT(
  119. DllStream.Initialize(
  120. PolicyAssemblyInformation.GetManifestPath(),
  121. MAKEINTRESOURCEW(RT_MANIFEST)));
  122. IFW32FALSE_EXIT(SxspComponentParsePolicyCore(
  123. Flags,
  124. pGenContext,
  125. PolicyAssemblyInformation,
  126. rpPolicyStatement,
  127. &DllStream));
  128. FN_EPILOG
  129. }
  130. BOOL
  131. SxspParseComponentPolicy(
  132. DWORD Flags,
  133. PACTCTXGENCTX pActCtxGenCtx,
  134. const CProbedAssemblyInformation &PolicyAssemblyInformation,
  135. CPolicyStatement *&rpPolicyStatement
  136. )
  137. {
  138. FN_PROLOG_WIN32
  139. CFileStream FileStream;
  140. IFW32FALSE_EXIT(
  141. FileStream.OpenForRead(
  142. PolicyAssemblyInformation.GetManifestPath(),
  143. CImpersonationData(),
  144. FILE_SHARE_READ,
  145. OPEN_EXISTING,
  146. FILE_FLAG_SEQUENTIAL_SCAN));
  147. IFW32FALSE_EXIT(SxspComponentParsePolicyCore(
  148. Flags,
  149. pActCtxGenCtx,
  150. PolicyAssemblyInformation,
  151. rpPolicyStatement,
  152. &FileStream));
  153. FN_EPILOG
  154. }
  155. BOOL
  156. SxspParseApplicationPolicy(
  157. DWORD Flags,
  158. PACTCTXGENCTX pActCtxGenCtx,
  159. ULONG ulPolicyPathType,
  160. PCWSTR pszPolicyPath,
  161. SIZE_T cchPolicyPath,
  162. IStream *pIStream
  163. )
  164. {
  165. BOOL fSuccess = FALSE;
  166. FN_TRACE_WIN32(fSuccess);
  167. // declaration order here is partially deliberate, to control cleanup order.
  168. // normally, declaration order is determined by not declaring until you have
  169. // the data to initialize with the ctor, but the use of goto messes that up
  170. CSmartPtr<CNodeFactory> NodeFactory;
  171. CSmartRef<IXMLParser> pIXMLParser;
  172. ACTCTXCTB_ASSEMBLY_CONTEXT AssemblyContext;
  173. ULONG i;
  174. PASSEMBLY Assembly = NULL;
  175. CStringBuffer buffPath;
  176. STATSTG statstg;
  177. PARAMETER_CHECK(pIStream != NULL);
  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_ProbedAssemblyInformation.Initialize(pActCtxGenCtx));
  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. //
  200. // Allocate the smart pointer
  201. //
  202. IFW32FALSE_EXIT(NodeFactory.Win32Allocate(__FILE__, __LINE__));
  203. IFW32FALSE_EXIT(NodeFactory->Initialize(pActCtxGenCtx, Assembly, &AssemblyContext));
  204. NodeFactory->m_pApplicationPolicyTable = &pActCtxGenCtx->m_ApplicationPolicyTable;
  205. // Everyone's ready; let's get the XML parser:
  206. IFW32FALSE_EXIT(::SxspGetXMLParser(IID_IXMLParser, (LPVOID *) &pIXMLParser));
  207. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXMLParser->SetFactory(NodeFactory));
  208. IFCOMFAILED_EXIT(pIStream->Stat(&statstg, STATFLAG_NONAME));
  209. // Open up the policy file and try parsing it...
  210. IFW32FALSE_EXIT(
  211. NodeFactory->SetParseType(
  212. XML_FILE_TYPE_APPLICATION_CONFIGURATION,
  213. ulPolicyPathType,
  214. buffPath,
  215. statstg.mtime));
  216. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXMLParser->SetInput(pIStream));
  217. IFCOMFAILED_ORIGINATE_AND_EXIT(pIXMLParser->Run(-1));
  218. NodeFactory->m_CurrentPolicyStatement = NULL;
  219. // Tell the contributors we want to be done with this file...
  220. for (i=0; i<pActCtxGenCtx->m_ContributorCount; i++)
  221. IFW32FALSE_EXIT(pActCtxGenCtx->m_Contributors[i].Fire_ParseEnding(pActCtxGenCtx, &AssemblyContext));
  222. fSuccess = TRUE;
  223. Exit:
  224. CSxsPreserveLastError ple;
  225. // And tell them we're done.
  226. for (i=0; i<pActCtxGenCtx->m_ContributorCount; i++)
  227. pActCtxGenCtx->m_Contributors[i].Fire_ParseEnded(pActCtxGenCtx, &AssemblyContext);
  228. if ( ple.LastError() == ERROR_SXS_MANIFEST_PARSE_ERROR || ple.LastError() == ERROR_SXS_MANIFEST_FORMAT_ERROR)
  229. { // log a general failure eventlog
  230. ::FusionpLogError(MSG_SXS_PARSE_MANIFEST_FAILED);
  231. }
  232. if (Assembly != NULL)
  233. Assembly->Release();
  234. ple.Restore();
  235. return fSuccess;
  236. }