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.

181 lines
6.0 KiB

  1. // NTRAID#NTBUG9 - 589788 - 2002/03/26 - xiaoyuw
  2. // (1)Do we still need this? or Darwin has fix their side before 2600 client?
  3. // (2)If we still need this, changing the status of Component could be part of CA
  4. // (3)About getting installer state. the current implementation is very weak:
  5. // it assume there is only two states: install and uninstall. which is not true....
  6. #include "..\inc\stdinc.h"
  7. #include "..\inc\macros.h"
  8. #include "..\inc\common.h"
  9. #include "msi.h"
  10. #include "msiquery.h"
  11. #include "sxsapi.h"
  12. #define CA_SXSPOLICY_INSTALLATION_IDENTIFIER L"Fusion Win32 Policy Installation on XP Client"
  13. #define MAX_BUF 1024
  14. #define CA_SXSPOLICY_WIN32_POLICY_INSTALL_PROMPT L"Win32 Policy Installation for XP Client"
  15. HMODULE g_hdSxs = NULL;
  16. PSXS_INSTALL_W g_procSxsInstallW = NULL;
  17. PSXS_UNINSTALL_ASSEMBLYW g_procSxsUninstallW = NULL;
  18. PSXS_QUERY_MANIFEST_INFORMATION g_procSxsQueryManifestInformation = NULL;
  19. HRESULT UninstallSxsPolicy(PCWSTR szManifestFile)
  20. {
  21. HRESULT hr = S_OK;
  22. SXS_UNINSTALLW UninstallParameters = {sizeof(UninstallParameters)};
  23. SXS_INSTALL_REFERENCEW Reference = {sizeof(Reference)};
  24. BYTE ManifestInformationBuffer[1UL << 16];
  25. PSXS_MANIFEST_INFORMATION_BASIC ManifestBasicInfo = reinterpret_cast<PSXS_MANIFEST_INFORMATION_BASIC>(&ManifestInformationBuffer);
  26. DWORD Disposition = 0;
  27. BOOL Success = FALSE;
  28. if (g_procSxsUninstallW == NULL)
  29. {
  30. if (g_hdSxs == NULL)
  31. {
  32. g_hdSxs = LoadLibraryA("sxs.dll");
  33. if (g_hdSxs == NULL)
  34. SET_HRERR_AND_EXIT(::GetLastError());
  35. }
  36. g_procSxsUninstallW = (PSXS_UNINSTALL_ASSEMBLYW)GetProcAddress(g_hdSxs, "SxsUninstallW");
  37. if (g_procSxsUninstallW == NULL)
  38. SET_HRERR_AND_EXIT(::GetLastError());
  39. }
  40. if (g_procSxsQueryManifestInformation == NULL)
  41. {
  42. g_procSxsQueryManifestInformation = (PSXS_QUERY_MANIFEST_INFORMATION)GetProcAddress(g_hdSxs, "SxsQueryManifestInformation");
  43. if (g_procSxsQueryManifestInformation == NULL)
  44. SET_HRERR_AND_EXIT(::GetLastError());
  45. }
  46. IFFALSE_EXIT(g_procSxsQueryManifestInformation(0, szManifestFile,
  47. SXS_QUERY_MANIFEST_INFORMATION_INFOCLASS_BASIC, 0, sizeof(ManifestInformationBuffer),
  48. ManifestBasicInfo, NULL));
  49. UninstallParameters.dwFlags |= SXS_UNINSTALL_FLAG_REFERENCE_VALID;
  50. UninstallParameters.lpInstallReference = &Reference;
  51. UninstallParameters.lpAssemblyIdentity = ManifestBasicInfo->lpIdentity;
  52. Reference.lpIdentifier = CA_SXSPOLICY_INSTALLATION_IDENTIFIER;
  53. Reference.guidScheme = SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING;
  54. IFFALSE_EXIT(g_procSxsUninstallW(&UninstallParameters, &Disposition));
  55. Exit:
  56. return hr;
  57. }
  58. HRESULT InstallSxsPolicy(PCWSTR szManifestFile)
  59. {
  60. SXS_INSTALLW InstallParameters = {sizeof(InstallParameters)};
  61. SXS_INSTALL_REFERENCEW InstallReference = {sizeof(InstallReference)};
  62. HRESULT hr = S_OK;
  63. if (g_procSxsInstallW == NULL)
  64. {
  65. if (g_hdSxs == NULL)
  66. {
  67. g_hdSxs = LoadLibraryA("sxs.dll");
  68. if (g_hdSxs == NULL)
  69. {
  70. SET_HRERR_AND_EXIT(::GetLastError());
  71. }
  72. }
  73. g_procSxsInstallW = (PSXS_INSTALL_W)GetProcAddress(g_hdSxs, "SxsInstallW");
  74. if (g_procSxsInstallW == NULL)
  75. {
  76. SET_HRERR_AND_EXIT(::GetLastError());
  77. }
  78. }
  79. InstallParameters.dwFlags =
  80. SXS_INSTALL_FLAG_REPLACE_EXISTING |
  81. SXS_INSTALL_FLAG_CODEBASE_URL_VALID |
  82. SXS_INSTALL_FLAG_REFERENCE_VALID |
  83. SXS_INSTALL_FLAG_REFRESH_PROMPT_VALID;
  84. InstallParameters.lpCodebaseURL = szManifestFile;
  85. InstallParameters.lpManifestPath = szManifestFile;
  86. InstallParameters.lpReference = &InstallReference;
  87. InstallParameters.lpRefreshPrompt = CA_SXSPOLICY_WIN32_POLICY_INSTALL_PROMPT ;
  88. InstallReference.guidScheme = SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING;
  89. InstallReference.lpIdentifier = CA_SXSPOLICY_INSTALLATION_IDENTIFIER;
  90. IFFALSE_EXIT((*g_procSxsInstallW)(&InstallParameters));
  91. Exit:
  92. return hr;
  93. }
  94. HRESULT __stdcall CA_Policy_EnumFusionWin32AssemblyCallback(CA_ENM_ASSEMBLY_CALLBACK_INFO * info)
  95. {
  96. enum CA_MIGRATION_MSI_INSTALL_MODE eInstallMode;
  97. CStringBuffer sbManfiestFilename;
  98. HRESULT hr = S_OK;
  99. PARAMETER_CHECK_NTC((info->dwFlags == 0) ||(info->dwFlags == CA_ENM_ASSEMBLY_CALLBACK_INFO_FLAG_IGNORE_MIGRATE_DENY_CHECK));
  100. PARAMETER_CHECK_NTC(info->hInstall != NULL);
  101. PARAMETER_CHECK_NTC(info->pszComponentID != NULL);
  102. PARAMETER_CHECK_NTC(info->pszManifestFileID != NULL);
  103. IFFAILED_EXIT(MSI_GetSourceFileFullPathName(CA_FILEFULLPATHNAME_FILEID_IN_FILE_TABLE, info->hInstall, info->hdb, NULL, info->pszManifestFileID, sbManfiestFilename, info->pszComponentID));
  104. IFFAILED_EXIT(MSI_GetInstallerState(info->hInstall, eInstallMode));
  105. //
  106. // install this API using sxs.dll
  107. //
  108. if (eInstallMode == eInstallProduct)
  109. {
  110. IFFAILED_EXIT(InstallSxsPolicy(sbManfiestFilename));
  111. }
  112. else
  113. {
  114. ASSERT_NTC(eInstallMode == eRemoveProduct);
  115. IFFAILED_EXIT(UninstallSxsPolicy(sbManfiestFilename));
  116. }
  117. Exit:
  118. return hr;
  119. }
  120. HRESULT __stdcall CustomAction_SxsPolicy(MSIHANDLE hInstall)
  121. {
  122. HRESULT hr = S_OK;
  123. #if DBG
  124. MessageBoxA(NULL, "Enjoy Debug for sxs policy installation using msi on xpclient", "ca_policy", MB_OK);
  125. #endif
  126. IFFAILED_EXIT(MSI_EnumWinFuseAssembly(ENUM_ASSEMBLY_FLAG_CHECK_POLICY_ONLY, hInstall, CA_Policy_EnumFusionWin32AssemblyCallback));
  127. Exit:
  128. return hr;
  129. }
  130. BOOL WINAPI DllMain(
  131. HINSTANCE hinstDLL,
  132. DWORD fdwReason,
  133. LPVOID lpvReserved
  134. )
  135. {
  136. if (fdwReason == DLL_PROCESS_DETACH)
  137. {
  138. if (g_hdSxs != NULL)
  139. {
  140. if (lpvReserved != NULL)
  141. {
  142. FreeLibrary(g_hdSxs);
  143. }
  144. g_hdSxs = NULL;
  145. }
  146. }
  147. return TRUE;
  148. }