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