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.

207 lines
6.4 KiB

  1. #include "stdinc.h"
  2. #include "idp.h"
  3. #include "sxsapi.h"
  4. #include "sxsid.h"
  5. #include "smartptr.h"
  6. BOOL
  7. SxspMapAssemblyIdentityToPolicyIdentity(
  8. DWORD Flags,
  9. PCASSEMBLY_IDENTITY AssemblyIdentity,
  10. PASSEMBLY_IDENTITY *pPolicyIdentity
  11. )
  12. {
  13. FN_PROLOG_WIN32
  14. PCWSTR pszTemp = NULL;
  15. SIZE_T cchTemp = 0;
  16. CSmartPtrWithNamedDestructor<ASSEMBLY_IDENTITY, &::SxsDestroyAssemblyIdentity> NewIdentity;
  17. CSmallStringBuffer Name;
  18. bool fFirst = false;
  19. const bool fOmitEntireVersion = ((Flags & SXSP_MAP_ASSEMBLY_IDENTITY_TO_POLICY_IDENTITY_FLAG_OMIT_ENTIRE_VERSION) != 0);
  20. BOOL fIsPolicy = FALSE;
  21. if (pPolicyIdentity)
  22. *pPolicyIdentity = NULL;
  23. PARAMETER_CHECK((Flags & ~(SXSP_MAP_ASSEMBLY_IDENTITY_TO_POLICY_IDENTITY_FLAG_OMIT_ENTIRE_VERSION)) == 0);
  24. PARAMETER_CHECK(AssemblyIdentity != 0);
  25. PARAMETER_CHECK(pPolicyIdentity != NULL);
  26. //
  27. // Duplicate the assembly identity first so we can change it
  28. //
  29. IFW32FALSE_EXIT(
  30. ::SxsDuplicateAssemblyIdentity(
  31. 0,
  32. AssemblyIdentity,
  33. &NewIdentity));
  34. IFW32FALSE_EXIT(::SxspDetermineAssemblyType(AssemblyIdentity, fIsPolicy));
  35. //
  36. // If this was not a policy identity, then swizzle its type
  37. //
  38. if (!fIsPolicy)
  39. {
  40. PCWSTR pcwszOriginalType;
  41. SIZE_T cchOriginalType;
  42. IFW32FALSE_EXIT(
  43. ::SxspGetAssemblyIdentityAttributeValue(
  44. SXSP_GET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_NOT_FOUND_RETURNS_NULL,
  45. AssemblyIdentity,
  46. &s_IdentityAttribute_type,
  47. &pcwszOriginalType,
  48. &cchOriginalType));
  49. if (cchOriginalType == 0)
  50. {
  51. IFW32FALSE_EXIT(
  52. ::SxspSetAssemblyIdentityAttributeValue(
  53. SXSP_SET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_OVERWRITE_EXISTING,
  54. NewIdentity,
  55. &s_IdentityAttribute_type,
  56. ASSEMBLY_TYPE_POLICY,
  57. ASSEMBLY_TYPE_POLICY_CCH));
  58. }
  59. else
  60. {
  61. CSmallStringBuffer MappedName;
  62. IFW32FALSE_EXIT(MappedName.Win32Assign(pcwszOriginalType, cchOriginalType));
  63. IFW32FALSE_EXIT(MappedName.Win32Append(ASSEMBLY_TYPE_POLICY_SUFFIX, ASSEMBLY_TYPE_POLICY_SUFFIX_CCH));
  64. IFW32FALSE_EXIT(
  65. ::SxspSetAssemblyIdentityAttributeValue(
  66. SXSP_SET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_OVERWRITE_EXISTING,
  67. NewIdentity,
  68. &s_IdentityAttribute_type,
  69. MappedName));
  70. }
  71. }
  72. IFW32FALSE_EXIT(Name.Win32Assign(L"Policy.", 7));
  73. if (!fOmitEntireVersion)
  74. {
  75. IFW32FALSE_EXIT(
  76. ::SxspGetAssemblyIdentityAttributeValue(
  77. 0,
  78. AssemblyIdentity,
  79. &s_IdentityAttribute_version,
  80. &pszTemp,
  81. &cchTemp));
  82. fFirst = true;
  83. while (cchTemp != 0)
  84. {
  85. if (pszTemp[--cchTemp] == L'.')
  86. {
  87. if (!fFirst)
  88. break;
  89. fFirst = false;
  90. }
  91. }
  92. // This should not be zero; someone prior to this should have validated the version format
  93. // to include three dots.
  94. INTERNAL_ERROR_CHECK(cchTemp != 0);
  95. IFW32FALSE_EXIT(Name.Win32Append(pszTemp, cchTemp + 1));
  96. }
  97. IFW32FALSE_EXIT(
  98. ::SxspGetAssemblyIdentityAttributeValue(
  99. 0,
  100. AssemblyIdentity,
  101. &s_IdentityAttribute_name,
  102. &pszTemp,
  103. &cchTemp));
  104. IFW32FALSE_EXIT(Name.Win32Append(pszTemp, cchTemp));
  105. IFW32FALSE_EXIT(
  106. ::SxspSetAssemblyIdentityAttributeValue(
  107. SXSP_SET_ASSEMBLY_IDENTITY_ATTRIBUTE_VALUE_FLAG_OVERWRITE_EXISTING,
  108. NewIdentity,
  109. &s_IdentityAttribute_name,
  110. Name));
  111. // finally we whack the version...
  112. IFW32FALSE_EXIT(
  113. ::SxspRemoveAssemblyIdentityAttribute(
  114. SXSP_REMOVE_ASSEMBLY_IDENTITY_ATTRIBUTE_FLAG_NOT_FOUND_SUCCEEDS,
  115. NewIdentity,
  116. &s_IdentityAttribute_version));
  117. if (pPolicyIdentity)
  118. *pPolicyIdentity = NewIdentity.Detach();
  119. FN_EPILOG;
  120. }
  121. BOOL
  122. SxspGenerateTextuallyEncodedPolicyIdentityFromAssemblyIdentity(
  123. DWORD Flags,
  124. PCASSEMBLY_IDENTITY AssemblyIdentity,
  125. CBaseStringBuffer &rbuffEncodedIdentity,
  126. PASSEMBLY_IDENTITY *PolicyIdentityOut
  127. )
  128. {
  129. FN_PROLOG_WIN32
  130. CSmartPtrWithNamedDestructor<ASSEMBLY_IDENTITY, &::SxsDestroyAssemblyIdentity> PolicyIdentity;
  131. DWORD dwMapFlags = 0;
  132. if (PolicyIdentityOut != NULL)
  133. *PolicyIdentityOut = NULL;
  134. PARAMETER_CHECK((Flags & ~(SXSP_GENERATE_TEXTUALLY_ENCODED_POLICY_IDENTITY_FROM_ASSEMBLY_IDENTITY_FLAG_OMIT_ENTIRE_VERSION)) == 0);
  135. PARAMETER_CHECK(AssemblyIdentity != NULL);
  136. if (Flags & SXSP_GENERATE_TEXTUALLY_ENCODED_POLICY_IDENTITY_FROM_ASSEMBLY_IDENTITY_FLAG_OMIT_ENTIRE_VERSION)
  137. dwMapFlags |= SXSP_MAP_ASSEMBLY_IDENTITY_TO_POLICY_IDENTITY_FLAG_OMIT_ENTIRE_VERSION;
  138. IFW32FALSE_EXIT(::SxspMapAssemblyIdentityToPolicyIdentity(dwMapFlags, AssemblyIdentity, &PolicyIdentity));
  139. IFW32FALSE_EXIT(::SxspGenerateTextualIdentity(0, PolicyIdentity, rbuffEncodedIdentity));
  140. if (PolicyIdentityOut != NULL)
  141. {
  142. *PolicyIdentityOut = PolicyIdentity.Detach();
  143. }
  144. FN_EPILOG;
  145. }
  146. //
  147. // the difference between this func and SxsHashAssemblyIdentity() is that for policy,
  148. // version should not be calcaulated as part of hash
  149. //
  150. BOOL
  151. SxspHashAssemblyIdentityForPolicy(
  152. IN DWORD dwFlags,
  153. IN PCASSEMBLY_IDENTITY AssemblyIdentity,
  154. OUT ULONG & IdentityHash)
  155. {
  156. FN_PROLOG_WIN32
  157. CSmartPtrWithNamedDestructor<ASSEMBLY_IDENTITY, ::SxsDestroyAssemblyIdentity> pAssemblyIdentity;
  158. IFW32FALSE_EXIT(
  159. ::SxsDuplicateAssemblyIdentity(
  160. SXS_DUPLICATE_ASSEMBLY_IDENTITY_FLAG_FREEZE,
  161. AssemblyIdentity,
  162. &pAssemblyIdentity));
  163. IFW32FALSE_EXIT(
  164. ::SxspRemoveAssemblyIdentityAttribute(
  165. SXSP_REMOVE_ASSEMBLY_IDENTITY_ATTRIBUTE_FLAG_NOT_FOUND_SUCCEEDS,
  166. pAssemblyIdentity,
  167. &s_IdentityAttribute_version));
  168. IFW32FALSE_EXIT(::SxsHashAssemblyIdentity(0, pAssemblyIdentity, &IdentityHash));
  169. FN_EPILOG
  170. }