diff options
| author | Rob Mensching <rob@firegiant.com> | 2021-05-04 11:41:55 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2021-05-04 11:41:55 -0700 |
| commit | 337124bed6a57b40fca11c5c2f5b554f570522a6 (patch) | |
| tree | 06e8552b11852309a2275e4bd63ee61320061876 /src/ext/ComPlus/ca/cpsched.cpp | |
| parent | eab57c2ddebc3dc8cebc22f5337f50062f415c0d (diff) | |
| download | wix-337124bed6a57b40fca11c5c2f5b554f570522a6.tar.gz wix-337124bed6a57b40fca11c5c2f5b554f570522a6.tar.bz2 wix-337124bed6a57b40fca11c5c2f5b554f570522a6.zip | |
Move ComPlus.wixext into ext
Diffstat (limited to 'src/ext/ComPlus/ca/cpsched.cpp')
| -rw-r--r-- | src/ext/ComPlus/ca/cpsched.cpp | 566 |
1 files changed, 566 insertions, 0 deletions
diff --git a/src/ext/ComPlus/ca/cpsched.cpp b/src/ext/ComPlus/ca/cpsched.cpp new file mode 100644 index 00000000..ebc547ae --- /dev/null +++ b/src/ext/ComPlus/ca/cpsched.cpp | |||
| @@ -0,0 +1,566 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | |||
| 6 | #ifdef _WIN64 | ||
| 7 | #define CP_COMPLUSROLLBACKINSTALLPREPARE L"ComPlusRollbackInstallPrepare_64" | ||
| 8 | #define CP_COMPLUSINSTALLPREPARE L"ComPlusInstallPrepare_64" | ||
| 9 | #define CP_COMPLUSROLLBACKINSTALLEXECUTE L"ComPlusRollbackInstallExecute_64" | ||
| 10 | #define CP_COMPLUSINSTALLEXECUTE L"ComPlusInstallExecute_64" | ||
| 11 | #define CP_COMPLUSINSTALLEXECUTECOMMIT L"ComPlusInstallExecuteCommit_64" | ||
| 12 | #define CP_COMPLUSINSTALLCOMMIT L"ComPlusInstallCommit_64" | ||
| 13 | #define CP_COMPLUSROLLBACKINSTALLPREPARE L"ComPlusRollbackInstallPrepare_64" | ||
| 14 | #define CP_COMPLUSINSTALLPREPARE L"ComPlusInstallPrepare_64" | ||
| 15 | #define CP_COMPLUSROLLBACKUNINSTALLEXECUTE L"ComPlusRollbackUninstallExecute_64" | ||
| 16 | #define CP_COMPLUSUNINSTALLEXECUTE L"ComPlusUninstallExecute_64" | ||
| 17 | #define CP_COMPLUSINSTALLCOMMIT L"ComPlusInstallCommit_64" | ||
| 18 | #else | ||
| 19 | #define CP_COMPLUSROLLBACKINSTALLPREPARE L"ComPlusRollbackInstallPrepare" | ||
| 20 | #define CP_COMPLUSINSTALLPREPARE L"ComPlusInstallPrepare" | ||
| 21 | #define CP_COMPLUSROLLBACKINSTALLEXECUTE L"ComPlusRollbackInstallExecute" | ||
| 22 | #define CP_COMPLUSINSTALLEXECUTE L"ComPlusInstallExecute" | ||
| 23 | #define CP_COMPLUSINSTALLEXECUTECOMMIT L"ComPlusInstallExecuteCommit" | ||
| 24 | #define CP_COMPLUSINSTALLCOMMIT L"ComPlusInstallCommit" | ||
| 25 | #define CP_COMPLUSROLLBACKINSTALLPREPARE L"ComPlusRollbackInstallPrepare" | ||
| 26 | #define CP_COMPLUSINSTALLPREPARE L"ComPlusInstallPrepare" | ||
| 27 | #define CP_COMPLUSROLLBACKUNINSTALLEXECUTE L"ComPlusRollbackUninstallExecute" | ||
| 28 | #define CP_COMPLUSUNINSTALLEXECUTE L"ComPlusUninstallExecute" | ||
| 29 | #define CP_COMPLUSINSTALLCOMMIT L"ComPlusInstallCommit" | ||
| 30 | #endif | ||
| 31 | |||
| 32 | /******************************************************************** | ||
| 33 | ConfigureComPlusInstall - CUSTOM ACTION ENTRY POINT for installing COM+ components | ||
| 34 | |||
| 35 | ********************************************************************/ | ||
| 36 | extern "C" UINT __stdcall ConfigureComPlusInstall(MSIHANDLE hInstall) | ||
| 37 | { | ||
| 38 | HRESULT hr = S_OK; | ||
| 39 | UINT er = ERROR_SUCCESS; | ||
| 40 | |||
| 41 | BOOL fInitializedCom = FALSE; | ||
| 42 | |||
| 43 | ICOMAdminCatalog* piCatalog = NULL; | ||
| 44 | |||
| 45 | CPI_PARTITION_LIST partList; | ||
| 46 | CPI_PARTITION_ROLE_LIST partRoleList; | ||
| 47 | CPI_USER_IN_PARTITION_ROLE_LIST usrInPartRoleList; | ||
| 48 | CPI_PARTITION_USER_LIST partUsrList; | ||
| 49 | CPI_APPLICATION_LIST appList; | ||
| 50 | CPI_APPLICATION_ROLE_LIST appRoleList; | ||
| 51 | CPI_USER_IN_APPLICATION_ROLE_LIST usrInAppRoleList; | ||
| 52 | CPI_ASSEMBLY_LIST asmList; | ||
| 53 | CPI_SUBSCRIPTION_LIST subList; | ||
| 54 | |||
| 55 | LPWSTR pwzRollbackFileName = NULL; | ||
| 56 | LPWSTR pwzActionData = NULL; | ||
| 57 | LPWSTR pwzRollbackActionData = NULL; | ||
| 58 | LPWSTR pwzCommitActionData = NULL; | ||
| 59 | |||
| 60 | int iVersionNT = 0; | ||
| 61 | int iProgress = 0; | ||
| 62 | int iCommitProgress = 0; | ||
| 63 | |||
| 64 | ::ZeroMemory(&partList, sizeof(CPI_PARTITION_LIST)); | ||
| 65 | ::ZeroMemory(&partRoleList, sizeof(CPI_PARTITION_ROLE_LIST)); | ||
| 66 | ::ZeroMemory(&usrInPartRoleList, sizeof(CPI_USER_IN_PARTITION_ROLE_LIST)); | ||
| 67 | ::ZeroMemory(&partUsrList, sizeof(CPI_PARTITION_USER_LIST)); | ||
| 68 | ::ZeroMemory(&appList, sizeof(CPI_APPLICATION_LIST)); | ||
| 69 | ::ZeroMemory(&appRoleList, sizeof(CPI_APPLICATION_ROLE_LIST)); | ||
| 70 | ::ZeroMemory(&usrInAppRoleList, sizeof(CPI_USER_IN_APPLICATION_ROLE_LIST)); | ||
| 71 | ::ZeroMemory(&asmList, sizeof(CPI_ASSEMBLY_LIST)); | ||
| 72 | ::ZeroMemory(&subList, sizeof(CPI_SUBSCRIPTION_LIST)); | ||
| 73 | |||
| 74 | // initialize | ||
| 75 | hr = WcaInitialize(hInstall, "ConfigureComPlusInstall"); | ||
| 76 | ExitOnFailure(hr, "Failed to initialize"); | ||
| 77 | |||
| 78 | hr = ::CoInitialize(NULL); | ||
| 79 | ExitOnFailure(hr, "Failed to initialize COM"); | ||
| 80 | fInitializedCom = TRUE; | ||
| 81 | |||
| 82 | CpiSchedInitialize(); | ||
| 83 | |||
| 84 | // check for the prerequsite tables | ||
| 85 | if (!CpiTableExists(cptComPlusPartition) && !CpiTableExists(cptComPlusApplication) && !CpiTableExists(cptComPlusAssembly)) | ||
| 86 | { | ||
| 87 | WcaLog(LOGMSG_VERBOSE, "skipping install COM+ CustomAction, no ComPlusPartition, ComPlusApplication or ComPlusAssembly table present"); | ||
| 88 | ExitFunction1(hr = S_FALSE); | ||
| 89 | } | ||
| 90 | |||
| 91 | // make sure we can access the COM+ admin catalog | ||
| 92 | do { | ||
| 93 | hr = CpiSchedGetAdminCatalog(&piCatalog); | ||
| 94 | if (FAILED(hr)) | ||
| 95 | { | ||
| 96 | WcaLog(LOGMSG_STANDARD, "Failed to get COM+ admin catalog"); | ||
| 97 | er = WcaErrorMessage(msierrComPlusCannotConnect, hr, INSTALLMESSAGE_ERROR | MB_ABORTRETRYIGNORE, 0); | ||
| 98 | switch (er) | ||
| 99 | { | ||
| 100 | case IDABORT: | ||
| 101 | ExitFunction(); // exit with hr from CpiGetAdminCatalog() to kick off a rollback | ||
| 102 | case IDRETRY: | ||
| 103 | hr = S_FALSE; | ||
| 104 | break; | ||
| 105 | case IDIGNORE: | ||
| 106 | default: | ||
| 107 | ExitFunction1(hr = S_OK); // pretend everything is okay and bail | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } while (S_FALSE == hr); | ||
| 111 | |||
| 112 | // get NT version | ||
| 113 | hr = WcaGetIntProperty(L"VersionNT", &iVersionNT); | ||
| 114 | ExitOnFailure(hr, "Failed to get VersionNT property"); | ||
| 115 | |||
| 116 | // read elements | ||
| 117 | if (502 <= iVersionNT && CpiTableExists(cptComPlusPartition)) | ||
| 118 | { | ||
| 119 | hr = CpiPartitionsRead(&partList); | ||
| 120 | MessageExitOnFailure(hr, msierrComPlusPartitionReadFailed, "Failed to read ComPlusPartitions table"); | ||
| 121 | } | ||
| 122 | |||
| 123 | if (502 <= iVersionNT && CpiTableExists(cptComPlusPartitionRole)) | ||
| 124 | { | ||
| 125 | hr = CpiPartitionRolesRead(&partList, &partRoleList); | ||
| 126 | MessageExitOnFailure(hr, msierrComPlusPartitionRoleReadFailed, "Failed to read ComPlusPartitionRole table"); | ||
| 127 | } | ||
| 128 | |||
| 129 | if (502 <= iVersionNT && (CpiTableExists(cptComPlusUserInPartitionRole) || CpiTableExists(cptComPlusGroupInPartitionRole))) | ||
| 130 | { | ||
| 131 | hr = CpiUsersInPartitionRolesRead(&partRoleList, &usrInPartRoleList); | ||
| 132 | MessageExitOnFailure(hr, msierrComPlusUserInPartitionRoleReadFailed, "Failed to read ComPlusUserInPartitionRole table"); | ||
| 133 | } | ||
| 134 | |||
| 135 | if (502 <= iVersionNT && CpiTableExists(cptComPlusPartitionUser)) | ||
| 136 | { | ||
| 137 | hr = CpiPartitionUsersRead(&partList, &partUsrList); | ||
| 138 | MessageExitOnFailure(hr, msierrComPlusPartitionUserReadFailed, "Failed to read ComPlusPartitionUser table"); | ||
| 139 | } | ||
| 140 | |||
| 141 | if (CpiTableExists(cptComPlusApplication)) | ||
| 142 | { | ||
| 143 | hr = CpiApplicationsRead(&partList, &appList); | ||
| 144 | MessageExitOnFailure(hr, msierrComPlusApplicationReadFailed, "Failed to read ComPlusApplication table"); | ||
| 145 | } | ||
| 146 | |||
| 147 | if (CpiTableExists(cptComPlusApplicationRole)) | ||
| 148 | { | ||
| 149 | hr = CpiApplicationRolesRead(&appList, &appRoleList); | ||
| 150 | MessageExitOnFailure(hr, msierrComPlusApplicationRoleReadFailed, "Failed to read ComPlusApplicationRole table"); | ||
| 151 | } | ||
| 152 | |||
| 153 | if (CpiTableExists(cptComPlusUserInApplicationRole) || CpiTableExists(cptComPlusGroupInApplicationRole)) | ||
| 154 | { | ||
| 155 | hr = CpiUsersInApplicationRolesRead(&appRoleList, &usrInAppRoleList); | ||
| 156 | MessageExitOnFailure(hr, msierrComPlusUserInApplicationRoleReadFailed, "Failed to read ComPlusUserInApplicationRole table"); | ||
| 157 | } | ||
| 158 | |||
| 159 | if (CpiTableExists(cptComPlusAssembly)) | ||
| 160 | { | ||
| 161 | hr = CpiAssembliesRead(&appList, &appRoleList, &asmList); | ||
| 162 | MessageExitOnFailure(hr, msierrComPlusAssembliesReadFailed, "Failed to read ComPlusAssembly table"); | ||
| 163 | } | ||
| 164 | |||
| 165 | if (CpiTableExists(cptComPlusSubscription)) | ||
| 166 | { | ||
| 167 | hr = CpiSubscriptionsRead(&asmList, &subList); | ||
| 168 | MessageExitOnFailure(hr, msierrComPlusSubscriptionReadFailed, "Failed to read ComPlusSubscription table"); | ||
| 169 | } | ||
| 170 | |||
| 171 | // verify elements | ||
| 172 | hr = CpiPartitionsVerifyInstall(&partList); | ||
| 173 | ExitOnFailure(hr, "Failed to verify partitions"); | ||
| 174 | |||
| 175 | hr = CpiApplicationsVerifyInstall(&appList); | ||
| 176 | ExitOnFailure(hr, "Failed to verify applications"); | ||
| 177 | |||
| 178 | hr = CpiApplicationRolesVerifyInstall(&appRoleList); | ||
| 179 | ExitOnFailure(hr, "Failed to verify application roles"); | ||
| 180 | |||
| 181 | hr = CpiAssembliesVerifyInstall(&asmList); | ||
| 182 | ExitOnFailure(hr, "Failed to verify assemblies"); | ||
| 183 | |||
| 184 | if (subList.iInstallCount) | ||
| 185 | { | ||
| 186 | hr = CpiSubscriptionsVerifyInstall(&subList); | ||
| 187 | ExitOnFailure(hr, "Failed to verify subscriptions"); | ||
| 188 | } | ||
| 189 | |||
| 190 | // schedule | ||
| 191 | if (partList.iInstallCount || appList.iInstallCount || usrInAppRoleList.iInstallCount || | ||
| 192 | appRoleList.iInstallCount || asmList.iInstallCount || asmList.iRoleInstallCount || subList.iInstallCount) | ||
| 193 | { | ||
| 194 | // create rollback file name | ||
| 195 | hr = CpiGetTempFileName(&pwzRollbackFileName); | ||
| 196 | ExitOnFailure(hr, "Failed to get rollback file name"); | ||
| 197 | |||
| 198 | // schedule rollback prepare custom action | ||
| 199 | hr = WcaDoDeferredAction(CP_COMPLUSROLLBACKINSTALLPREPARE, pwzRollbackFileName, 0); | ||
| 200 | ExitOnFailure(hr, "Failed to schedule ComPlusRollbackInstallPrepare"); | ||
| 201 | |||
| 202 | // schedule prepare custom action | ||
| 203 | hr = WcaDoDeferredAction(CP_COMPLUSINSTALLPREPARE, pwzRollbackFileName, 0); | ||
| 204 | ExitOnFailure(hr, "Failed to schedule ComPlusInstallPrepare"); | ||
| 205 | |||
| 206 | // schedule rollback custom action | ||
| 207 | hr = WcaWriteStringToCaData(pwzRollbackFileName, &pwzRollbackActionData); | ||
| 208 | ExitOnFailure(hr, "Failed to add rollback file name to rollback custom action data"); | ||
| 209 | |||
| 210 | hr = CpiSubscriptionsInstall(&subList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 211 | ExitOnFailure(hr, "Failed to install subscriptions"); | ||
| 212 | hr = CpiRoleAssignmentsInstall(&asmList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 213 | ExitOnFailure(hr, "Failed to install assemblies"); | ||
| 214 | hr = CpiAssembliesInstall(&asmList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 215 | ExitOnFailure(hr, "Failed to install assemblies"); | ||
| 216 | hr = CpiUsersInApplicationRolesInstall(&usrInAppRoleList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 217 | ExitOnFailure(hr, "Failed to install users in application roles"); | ||
| 218 | hr = CpiApplicationRolesInstall(&appRoleList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 219 | ExitOnFailure(hr, "Failed to install application roles"); | ||
| 220 | hr = CpiApplicationsInstall(&appList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 221 | ExitOnFailure(hr, "Failed to install applications"); | ||
| 222 | hr = CpiPartitionUsersInstall(&partUsrList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 223 | ExitOnFailure(hr, "Failed to install partition users"); | ||
| 224 | hr = CpiUsersInPartitionRolesInstall(&usrInPartRoleList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 225 | ExitOnFailure(hr, "Failed to install users in partition roles"); | ||
| 226 | hr = CpiPartitionsInstall(&partList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 227 | ExitOnFailure(hr, "Failed to install partitions"); | ||
| 228 | |||
| 229 | hr = WcaDoDeferredAction(CP_COMPLUSROLLBACKINSTALLEXECUTE, pwzRollbackActionData, 0); | ||
| 230 | ExitOnFailure(hr, "Failed to schedule ComPlusRollbackInstallExecute"); | ||
| 231 | |||
| 232 | // schedule install custom action | ||
| 233 | hr = WcaWriteStringToCaData(pwzRollbackFileName, &pwzActionData); | ||
| 234 | ExitOnFailure(hr, "Failed to add rollback file name to custom action data"); | ||
| 235 | |||
| 236 | hr = CpiPartitionsInstall(&partList, rmDeferred, &pwzActionData, &iProgress); | ||
| 237 | ExitOnFailure(hr, "Failed to install partitions"); | ||
| 238 | hr = CpiUsersInPartitionRolesInstall(&usrInPartRoleList, rmDeferred, &pwzActionData, &iProgress); | ||
| 239 | ExitOnFailure(hr, "Failed to install users in partition roles"); | ||
| 240 | hr = CpiPartitionUsersInstall(&partUsrList, rmDeferred, &pwzActionData, &iProgress); | ||
| 241 | ExitOnFailure(hr, "Failed to install partition users"); | ||
| 242 | hr = CpiApplicationsInstall(&appList, rmDeferred, &pwzActionData, &iProgress); | ||
| 243 | ExitOnFailure(hr, "Failed to install applications"); | ||
| 244 | hr = CpiApplicationRolesInstall(&appRoleList, rmDeferred, &pwzActionData, &iProgress); | ||
| 245 | ExitOnFailure(hr, "Failed to install application roles"); | ||
| 246 | hr = CpiUsersInApplicationRolesInstall(&usrInAppRoleList, rmDeferred, &pwzActionData, &iProgress); | ||
| 247 | ExitOnFailure(hr, "Failed to install users in application roles"); | ||
| 248 | hr = CpiAssembliesInstall(&asmList, rmDeferred, &pwzActionData, &iProgress); | ||
| 249 | ExitOnFailure(hr, "Failed to install assemblies"); | ||
| 250 | hr = CpiRoleAssignmentsInstall(&asmList, rmDeferred, &pwzActionData, &iProgress); | ||
| 251 | ExitOnFailure(hr, "Failed to install assemblies"); | ||
| 252 | hr = CpiSubscriptionsInstall(&subList, rmDeferred, &pwzActionData, &iProgress); | ||
| 253 | ExitOnFailure(hr, "Failed to install subscriptions"); | ||
| 254 | |||
| 255 | hr = WcaDoDeferredAction(CP_COMPLUSINSTALLEXECUTE, pwzActionData, iProgress); | ||
| 256 | ExitOnFailure(hr, "Failed to schedule ComPlusInstallExecute"); | ||
| 257 | |||
| 258 | // schedule install commit custom action | ||
| 259 | hr = WcaWriteStringToCaData(pwzRollbackFileName, &pwzCommitActionData); | ||
| 260 | ExitOnFailure(hr, "Failed to add rollback file name to commit custom action data"); | ||
| 261 | |||
| 262 | hr = CpiAssembliesInstall(&asmList, rmCommit, &pwzCommitActionData, &iCommitProgress); | ||
| 263 | ExitOnFailure(hr, "Failed to install assemblies"); | ||
| 264 | hr = CpiRoleAssignmentsInstall(&asmList, rmCommit, &pwzCommitActionData, &iCommitProgress); | ||
| 265 | ExitOnFailure(hr, "Failed to install assemblies"); | ||
| 266 | hr = CpiSubscriptionsInstall(&subList, rmCommit, &pwzCommitActionData, &iCommitProgress); | ||
| 267 | ExitOnFailure(hr, "Failed to install subscriptions"); | ||
| 268 | |||
| 269 | hr = WcaDoDeferredAction(CP_COMPLUSINSTALLEXECUTECOMMIT, pwzCommitActionData, iCommitProgress); | ||
| 270 | ExitOnFailure(hr, "Failed to schedule ComPlusInstallExecuteCommit"); | ||
| 271 | |||
| 272 | // schedule commit custom action | ||
| 273 | hr = WcaDoDeferredAction(CP_COMPLUSINSTALLCOMMIT, pwzRollbackFileName, 0); | ||
| 274 | ExitOnFailure(hr, "Failed to schedule ComPlusInstallCommit"); | ||
| 275 | } | ||
| 276 | |||
| 277 | hr = S_OK; | ||
| 278 | |||
| 279 | LExit: | ||
| 280 | // clean up | ||
| 281 | ReleaseObject(piCatalog); | ||
| 282 | |||
| 283 | ReleaseStr(pwzRollbackFileName); | ||
| 284 | ReleaseStr(pwzActionData); | ||
| 285 | ReleaseStr(pwzRollbackActionData); | ||
| 286 | ReleaseStr(pwzCommitActionData); | ||
| 287 | |||
| 288 | CpiPartitionListFree(&partList); | ||
| 289 | CpiPartitionRoleListFree(&partRoleList); | ||
| 290 | CpiUserInPartitionRoleListFree(&usrInPartRoleList); | ||
| 291 | CpiPartitionUserListFree(&partUsrList); | ||
| 292 | CpiApplicationListFree(&appList); | ||
| 293 | CpiApplicationRoleListFree(&appRoleList); | ||
| 294 | CpiUserInApplicationRoleListFree(&usrInAppRoleList); | ||
| 295 | CpiAssemblyListFree(&asmList); | ||
| 296 | CpiSubscriptionListFree(&subList); | ||
| 297 | |||
| 298 | // unitialize | ||
| 299 | CpiSchedFinalize(); | ||
| 300 | |||
| 301 | if (fInitializedCom) | ||
| 302 | ::CoUninitialize(); | ||
| 303 | |||
| 304 | er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; | ||
| 305 | return WcaFinalize(er); | ||
| 306 | } | ||
| 307 | |||
| 308 | |||
| 309 | /******************************************************************** | ||
| 310 | ConfigureComPlusUninstall - CUSTOM ACTION ENTRY POINT for uninstalling COM+ components | ||
| 311 | |||
| 312 | ********************************************************************/ | ||
| 313 | extern "C" UINT __stdcall ConfigureComPlusUninstall(MSIHANDLE hInstall) | ||
| 314 | { | ||
| 315 | HRESULT hr = S_OK; | ||
| 316 | UINT er = ERROR_SUCCESS; | ||
| 317 | |||
| 318 | BOOL fInitializedCom = FALSE; | ||
| 319 | |||
| 320 | ICOMAdminCatalog* piCatalog = NULL; | ||
| 321 | |||
| 322 | CPI_PARTITION_LIST partList; | ||
| 323 | CPI_PARTITION_ROLE_LIST partRoleList; | ||
| 324 | CPI_USER_IN_PARTITION_ROLE_LIST usrInPartRoleList; | ||
| 325 | CPI_PARTITION_USER_LIST partUsrList; | ||
| 326 | CPI_APPLICATION_LIST appList; | ||
| 327 | CPI_APPLICATION_ROLE_LIST appRoleList; | ||
| 328 | CPI_USER_IN_APPLICATION_ROLE_LIST usrInAppRoleList; | ||
| 329 | CPI_ASSEMBLY_LIST asmList; | ||
| 330 | CPI_SUBSCRIPTION_LIST subList; | ||
| 331 | |||
| 332 | LPWSTR pwzRollbackFileName = NULL; | ||
| 333 | LPWSTR pwzActionData = NULL; | ||
| 334 | LPWSTR pwzRollbackActionData = NULL; | ||
| 335 | |||
| 336 | int iVersionNT = 0; | ||
| 337 | int iProgress = 0; | ||
| 338 | |||
| 339 | ::ZeroMemory(&partList, sizeof(CPI_PARTITION_LIST)); | ||
| 340 | ::ZeroMemory(&partRoleList, sizeof(CPI_PARTITION_ROLE_LIST)); | ||
| 341 | ::ZeroMemory(&usrInPartRoleList, sizeof(CPI_USER_IN_PARTITION_ROLE_LIST)); | ||
| 342 | ::ZeroMemory(&partUsrList, sizeof(CPI_PARTITION_USER_LIST)); | ||
| 343 | ::ZeroMemory(&appList, sizeof(CPI_APPLICATION_LIST)); | ||
| 344 | ::ZeroMemory(&appRoleList, sizeof(CPI_APPLICATION_ROLE_LIST)); | ||
| 345 | ::ZeroMemory(&usrInAppRoleList, sizeof(CPI_USER_IN_APPLICATION_ROLE_LIST)); | ||
| 346 | ::ZeroMemory(&asmList, sizeof(CPI_ASSEMBLY_LIST)); | ||
| 347 | ::ZeroMemory(&subList, sizeof(CPI_SUBSCRIPTION_LIST)); | ||
| 348 | |||
| 349 | // initialize | ||
| 350 | hr = WcaInitialize(hInstall, "ConfigureComPlusUninstall"); | ||
| 351 | ExitOnFailure(hr, "Failed to initialize"); | ||
| 352 | |||
| 353 | hr = ::CoInitialize(NULL); | ||
| 354 | ExitOnFailure(hr, "Failed to initialize COM"); | ||
| 355 | fInitializedCom = TRUE; | ||
| 356 | |||
| 357 | CpiSchedInitialize(); | ||
| 358 | |||
| 359 | // check for the prerequsite tables | ||
| 360 | if (!CpiTableExists(cptComPlusPartition) && !CpiTableExists(cptComPlusApplication) && !CpiTableExists(cptComPlusAssembly)) | ||
| 361 | { | ||
| 362 | WcaLog(LOGMSG_VERBOSE, "skipping uninstall COM+ CustomAction, no ComPlusPartition, ComPlusApplication or ComPlusAssembly table present"); | ||
| 363 | ExitFunction1(hr = S_FALSE); | ||
| 364 | } | ||
| 365 | |||
| 366 | // make sure we can access the COM+ admin catalog | ||
| 367 | do { | ||
| 368 | hr = CpiSchedGetAdminCatalog(&piCatalog); | ||
| 369 | if (FAILED(hr)) | ||
| 370 | { | ||
| 371 | WcaLog(LOGMSG_STANDARD, "Failed to get COM+ admin catalog"); | ||
| 372 | er = WcaErrorMessage(msierrComPlusCannotConnect, hr, INSTALLMESSAGE_ERROR | MB_ABORTRETRYIGNORE, 0); | ||
| 373 | switch (er) | ||
| 374 | { | ||
| 375 | case IDABORT: | ||
| 376 | ExitFunction(); // exit with hr from CpiGetAdminCatalog() to kick off a rollback | ||
| 377 | case IDRETRY: | ||
| 378 | hr = S_FALSE; | ||
| 379 | break; | ||
| 380 | case IDIGNORE: | ||
| 381 | default: | ||
| 382 | ExitFunction1(hr = S_OK); // pretend everything is okay and bail | ||
| 383 | } | ||
| 384 | } | ||
| 385 | } while (S_FALSE == hr); | ||
| 386 | |||
| 387 | // get NT version | ||
| 388 | hr = WcaGetIntProperty(L"VersionNT", &iVersionNT); | ||
| 389 | ExitOnFailure(hr, "Failed to get VersionNT property"); | ||
| 390 | |||
| 391 | // read elements | ||
| 392 | if (502 <= iVersionNT && CpiTableExists(cptComPlusPartition)) | ||
| 393 | { | ||
| 394 | hr = CpiPartitionsRead(&partList); | ||
| 395 | MessageExitOnFailure(hr, msierrComPlusPartitionReadFailed, "Failed to read ComPlusPartitions table"); | ||
| 396 | } | ||
| 397 | |||
| 398 | if (502 <= iVersionNT && CpiTableExists(cptComPlusPartitionRole)) | ||
| 399 | { | ||
| 400 | hr = CpiPartitionRolesRead(&partList, &partRoleList); | ||
| 401 | MessageExitOnFailure(hr, msierrComPlusPartitionRoleReadFailed, "Failed to read ComPlusPartitionRole table"); | ||
| 402 | } | ||
| 403 | |||
| 404 | if (502 <= iVersionNT && (CpiTableExists(cptComPlusUserInPartitionRole) || CpiTableExists(cptComPlusGroupInPartitionRole))) | ||
| 405 | { | ||
| 406 | hr = CpiUsersInPartitionRolesRead(&partRoleList, &usrInPartRoleList); | ||
| 407 | MessageExitOnFailure(hr, msierrComPlusUserInPartitionRoleReadFailed, "Failed to read ComPlusUserInPartitionRole table"); | ||
| 408 | } | ||
| 409 | |||
| 410 | if (502 <= iVersionNT && CpiTableExists(cptComPlusPartitionUser)) | ||
| 411 | { | ||
| 412 | hr = CpiPartitionUsersRead(&partList, &partUsrList); | ||
| 413 | MessageExitOnFailure(hr, msierrComPlusPartitionUserReadFailed, "Failed to read ComPlusPartitionUser table"); | ||
| 414 | } | ||
| 415 | |||
| 416 | if (CpiTableExists(cptComPlusApplication)) | ||
| 417 | { | ||
| 418 | hr = CpiApplicationsRead(&partList, &appList); | ||
| 419 | MessageExitOnFailure(hr, msierrComPlusApplicationReadFailed, "Failed to read ComPlusApplication table"); | ||
| 420 | } | ||
| 421 | |||
| 422 | if (CpiTableExists(cptComPlusApplicationRole)) | ||
| 423 | { | ||
| 424 | hr = CpiApplicationRolesRead(&appList, &appRoleList); | ||
| 425 | MessageExitOnFailure(hr, msierrComPlusApplicationRoleReadFailed, "Failed to read ComPlusApplicationRole table"); | ||
| 426 | } | ||
| 427 | |||
| 428 | if (CpiTableExists(cptComPlusUserInApplicationRole) || CpiTableExists(cptComPlusGroupInApplicationRole)) | ||
| 429 | { | ||
| 430 | hr = CpiUsersInApplicationRolesRead(&appRoleList, &usrInAppRoleList); | ||
| 431 | MessageExitOnFailure(hr, msierrComPlusUserInApplicationRoleReadFailed, "Failed to read ComPlusUserInApplicationRole table"); | ||
| 432 | } | ||
| 433 | |||
| 434 | if (CpiTableExists(cptComPlusAssembly)) | ||
| 435 | { | ||
| 436 | hr = CpiAssembliesRead(&appList, &appRoleList, &asmList); | ||
| 437 | MessageExitOnFailure(hr, msierrComPlusAssembliesReadFailed, "Failed to read ComPlusAssembly table"); | ||
| 438 | } | ||
| 439 | |||
| 440 | if (CpiTableExists(cptComPlusSubscription)) | ||
| 441 | { | ||
| 442 | hr = CpiSubscriptionsRead(&asmList, &subList); | ||
| 443 | MessageExitOnFailure(hr, msierrComPlusSubscriptionReadFailed, "Failed to read ComPlusSubscription table"); | ||
| 444 | } | ||
| 445 | |||
| 446 | // verify elements | ||
| 447 | hr = CpiPartitionsVerifyUninstall(&partList); | ||
| 448 | ExitOnFailure(hr, "Failed to verify partitions"); | ||
| 449 | |||
| 450 | hr = CpiApplicationsVerifyUninstall(&appList); | ||
| 451 | ExitOnFailure(hr, "Failed to verify applications"); | ||
| 452 | |||
| 453 | hr = CpiApplicationRolesVerifyUninstall(&appRoleList); | ||
| 454 | ExitOnFailure(hr, "Failed to verify application roles"); | ||
| 455 | |||
| 456 | hr = CpiAssembliesVerifyUninstall(&asmList); | ||
| 457 | ExitOnFailure(hr, "Failed to verify assemblies"); | ||
| 458 | |||
| 459 | if (subList.iUninstallCount) | ||
| 460 | { | ||
| 461 | hr = CpiSubscriptionsVerifyUninstall(&subList); | ||
| 462 | ExitOnFailure(hr, "Failed to verify subscriptions"); | ||
| 463 | } | ||
| 464 | |||
| 465 | // schedule | ||
| 466 | if (partList.iUninstallCount || appList.iUninstallCount || appRoleList.iUninstallCount || | ||
| 467 | usrInAppRoleList.iUninstallCount || asmList.iUninstallCount || asmList.iRoleUninstallCount || subList.iUninstallCount) | ||
| 468 | { | ||
| 469 | // create rollback file name | ||
| 470 | hr = CpiGetTempFileName(&pwzRollbackFileName); | ||
| 471 | ExitOnFailure(hr, "Failed to get rollback file name"); | ||
| 472 | |||
| 473 | // schedule rollback prepare custom action | ||
| 474 | hr = WcaDoDeferredAction(CP_COMPLUSROLLBACKINSTALLPREPARE, pwzRollbackFileName, 0); | ||
| 475 | ExitOnFailure(hr, "Failed to schedule ComPlusRollbackInstallPrepare"); | ||
| 476 | |||
| 477 | // schedule prepare custom action | ||
| 478 | hr = WcaDoDeferredAction(CP_COMPLUSINSTALLPREPARE, pwzRollbackFileName, 0); | ||
| 479 | ExitOnFailure(hr, "Failed to schedule ComPlusInstallPrepare"); | ||
| 480 | |||
| 481 | // schedule rollback custom action | ||
| 482 | hr = WcaWriteStringToCaData(pwzRollbackFileName, &pwzRollbackActionData); | ||
| 483 | ExitOnFailure(hr, "Failed to add rollback file name to rollback custom action data"); | ||
| 484 | |||
| 485 | hr = CpiPartitionsUninstall(&partList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 486 | ExitOnFailure(hr, "Failed to uninstall partitions"); | ||
| 487 | hr = CpiUsersInPartitionRolesUninstall(&usrInPartRoleList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 488 | ExitOnFailure(hr, "Failed to uninstall users in partition roles"); | ||
| 489 | hr = CpiPartitionUsersUninstall(&partUsrList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 490 | ExitOnFailure(hr, "Failed to uninstall partition users"); | ||
| 491 | hr = CpiApplicationsUninstall(&appList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 492 | ExitOnFailure(hr, "Failed to uninstall applications"); | ||
| 493 | hr = CpiApplicationRolesUninstall(&appRoleList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 494 | ExitOnFailure(hr, "Failed to uninstall application roles"); | ||
| 495 | hr = CpiUsersInApplicationRolesUninstall(&usrInAppRoleList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 496 | ExitOnFailure(hr, "Failed to uninstall users in application roles"); | ||
| 497 | hr = CpiAssembliesUninstall(&asmList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 498 | ExitOnFailure(hr, "Failed to uninstall assemblies"); | ||
| 499 | hr = CpiRoleAssignmentsUninstall(&asmList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 500 | ExitOnFailure(hr, "Failed to uninstall assemblies"); | ||
| 501 | hr = CpiSubscriptionsUninstall(&subList, rmRollback, &pwzRollbackActionData, NULL); | ||
| 502 | ExitOnFailure(hr, "Failed to uninstall subscriptions"); | ||
| 503 | |||
| 504 | hr = WcaDoDeferredAction(CP_COMPLUSROLLBACKUNINSTALLEXECUTE, pwzRollbackActionData, 0); | ||
| 505 | ExitOnFailure(hr, "Failed to schedule ComPlusRollbackUninstallExecute"); | ||
| 506 | |||
| 507 | // schedule install custom action | ||
| 508 | hr = WcaWriteStringToCaData(pwzRollbackFileName, &pwzActionData); | ||
| 509 | ExitOnFailure(hr, "Failed to add rollback file name to custom action data"); | ||
| 510 | |||
| 511 | hr = CpiSubscriptionsUninstall(&subList, rmDeferred, &pwzActionData, &iProgress); | ||
| 512 | ExitOnFailure(hr, "Failed to uninstall subscriptions"); | ||
| 513 | hr = CpiRoleAssignmentsUninstall(&asmList, rmDeferred, &pwzActionData, &iProgress); | ||
| 514 | ExitOnFailure(hr, "Failed to uninstall assemblies"); | ||
| 515 | hr = CpiAssembliesUninstall(&asmList, rmDeferred, &pwzActionData, &iProgress); | ||
| 516 | ExitOnFailure(hr, "Failed to uninstall assemblies"); | ||
| 517 | hr = CpiUsersInApplicationRolesUninstall(&usrInAppRoleList, rmDeferred, &pwzActionData, &iProgress); | ||
| 518 | ExitOnFailure(hr, "Failed to uninstall users in application roles"); | ||
| 519 | hr = CpiApplicationRolesUninstall(&appRoleList, rmDeferred, &pwzActionData, &iProgress); | ||
| 520 | ExitOnFailure(hr, "Failed to uninstall application roles"); | ||
| 521 | hr = CpiApplicationsUninstall(&appList, rmDeferred, &pwzActionData, &iProgress); | ||
| 522 | ExitOnFailure(hr, "Failed to uninstall applications"); | ||
| 523 | hr = CpiPartitionUsersUninstall(&partUsrList, rmDeferred, &pwzActionData, &iProgress); | ||
| 524 | ExitOnFailure(hr, "Failed to uninstall partition users"); | ||
| 525 | hr = CpiUsersInPartitionRolesUninstall(&usrInPartRoleList, rmDeferred, &pwzActionData, &iProgress); | ||
| 526 | ExitOnFailure(hr, "Failed to uninstall users in partition roles"); | ||
| 527 | hr = CpiPartitionsUninstall(&partList, rmDeferred, &pwzActionData, &iProgress); | ||
| 528 | ExitOnFailure(hr, "Failed to uninstall partitions"); | ||
| 529 | |||
| 530 | hr = WcaDoDeferredAction(CP_COMPLUSUNINSTALLEXECUTE, pwzActionData, iProgress); | ||
| 531 | ExitOnFailure(hr, "Failed to schedule ComPlusUninstallExecute"); | ||
| 532 | |||
| 533 | // schedule commit custom action | ||
| 534 | hr = WcaDoDeferredAction(CP_COMPLUSINSTALLCOMMIT, pwzRollbackFileName, 0); | ||
| 535 | ExitOnFailure(hr, "Failed to schedule ComPlusInstallCommit"); | ||
| 536 | } | ||
| 537 | |||
| 538 | hr = S_OK; | ||
| 539 | |||
| 540 | LExit: | ||
| 541 | // clean up | ||
| 542 | ReleaseObject(piCatalog); | ||
| 543 | |||
| 544 | ReleaseStr(pwzRollbackFileName); | ||
| 545 | ReleaseStr(pwzActionData); | ||
| 546 | ReleaseStr(pwzRollbackActionData); | ||
| 547 | |||
| 548 | CpiPartitionListFree(&partList); | ||
| 549 | CpiPartitionRoleListFree(&partRoleList); | ||
| 550 | CpiUserInPartitionRoleListFree(&usrInPartRoleList); | ||
| 551 | CpiPartitionUserListFree(&partUsrList); | ||
| 552 | CpiApplicationListFree(&appList); | ||
| 553 | CpiApplicationRoleListFree(&appRoleList); | ||
| 554 | CpiUserInApplicationRoleListFree(&usrInAppRoleList); | ||
| 555 | CpiAssemblyListFree(&asmList); | ||
| 556 | CpiSubscriptionListFree(&subList); | ||
| 557 | |||
| 558 | // unitialize | ||
| 559 | CpiSchedFinalize(); | ||
| 560 | |||
| 561 | if (fInitializedCom) | ||
| 562 | ::CoUninitialize(); | ||
| 563 | |||
| 564 | er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; | ||
| 565 | return WcaFinalize(er); | ||
| 566 | } | ||
