Update of /cvsroot/wix/wix/src/ca/pubca/pcaexec In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15140/src/ca/pubca/pcaexec Modified Files: pcaexec.cpp pcaexec.def pcaexec.mak precomp.h Added Files: cpiappexec.cpp cpiappexec.h cpiapproleexec.cpp cpiapproleexec.h cpiasmexec.cpp cpiasmexec.h cpipartexec.cpp cpipartexec.h cpipartroleexec.cpp cpipartroleexec.h cpisubsexec.cpp cpisubsexec.h cpiutilexec.cpp cpiutilexec.h Log Message: pubca - COM+ CustomActions from Fredrick Grohn compiler - support DIFxApp v2.0 correctly sca - fix builds --- NEW FILE: cpipartexec.cpp --- //------------------------------------------------------------------------------------------------- // <copyright file="cpipartexec.cpp" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. // </copyright> // // <summary> // COM+ partition functions for CustomActions // </summary> //------------------------------------------------------------------------------------------------- #include "precomp.h" // private structs struct CPI_PARTITION_ATTRIBUTES { int iActionType; int iActionCost; LPWSTR pwzKey; LPWSTR pwzID; LPWSTR pwzName; CPI_PROPERTY* pPropList; }; struct CPI_PARTITION_USER_ATTRIBUTES { int iActionType; int iActionCost; LPWSTR pwzKey; LPWSTR pwzAccount; LPWSTR pwzPartID; }; // prototypes for private helper functions static HRESULT ReadPartitionAttributes( LPWSTR* ppwzData, CPI_PARTITION_ATTRIBUTES* pAttrs ); static void FreePartitionAttributes( CPI_PARTITION_ATTRIBUTES* pAttrs ); static HRESULT CreatePartition( CPI_PARTITION_ATTRIBUTES* pAttrs ); static HRESULT RemovePartition( CPI_PARTITION_ATTRIBUTES* pAttrs ); static HRESULT ReadPartitionUserAttributes( LPWSTR* ppwzData, CPI_PARTITION_USER_ATTRIBUTES* pAttrs ); static void FreePartitionUserAttributes( CPI_PARTITION_USER_ATTRIBUTES* pAttrs ); static HRESULT CreatePartitionUser( CPI_PARTITION_USER_ATTRIBUTES* pAttrs ); static HRESULT RemovePartitionUser( CPI_PARTITION_USER_ATTRIBUTES* pAttrs ); // function definitions HRESULT CpiConfigurePartitions( LPWSTR* ppwzData, HANDLE hRollbackFile ) { HRESULT hr = S_OK; CPI_PARTITION_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, FALSE); ExitOnFailure(hr, "Failed to send action start message"); // ger partition count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); // write count to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, iCnt); ExitOnFailure(hr, "Failed to write count to rollback file"); for (int i = 0; i < iCnt; i++) { // read partition attributes from CustomActionData hr = ReadPartitionAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // progress message hr = CpiActionDataMessage(1, attrs.pwzName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // write key to rollback file hr = CpiWriteKeyToRollbackFile(hRollbackFile, attrs.pwzKey); ExitOnFailure(hr, "Failed to write key to rollback file"); // action switch (attrs.iActionType) { case atCreate: hr = CreatePartition(&attrs); ExitOnFailure1(hr, "Failed to create partition, key: %S", attrs.pwzKey); break; case atRemove: hr = RemovePartition(&attrs); ExitOnFailure1(hr, "Failed to remove partition, key: %S", attrs.pwzKey); break; } // write completion status to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, 1); ExitOnFailure(hr, "Failed to write completion status to rollback file"); // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreePartitionAttributes(&attrs); return hr; } HRESULT CpiRollbackConfigurePartitions( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ) { HRESULT hr = S_OK; int iRollbackStatus; CPI_PARTITION_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, NULL == pRollbackDataList); ExitOnFailure(hr, "Failed to send action start message"); // get count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); for (int i = 0; i < iCnt; i++) { // read partition attributes from CustomActionData hr = ReadPartitionAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // rollback status hr = CpiFindRollbackStatus(pRollbackDataList, attrs.pwzKey, &iRollbackStatus); if (S_FALSE == hr) continue; // not found, nothing to rollback // progress message hr = CpiActionDataMessage(1, attrs.pwzName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // action switch (attrs.iActionType) { case atCreate: hr = CreatePartition(&attrs); ExitOnFailure1(hr, "Failed to create partition, key: %S", attrs.pwzKey); break; case atRemove: hr = RemovePartition(&attrs); ExitOnFailure1(hr, "Failed to remove partition, key: %S", attrs.pwzKey); break; } // check rollback status if (0 == iRollbackStatus) continue; // operation did not complete, skip progress // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreePartitionAttributes(&attrs); return hr; } HRESULT CpiConfigurePartitionUsers( LPWSTR* ppwzData, HANDLE hRollbackFile ) { HRESULT hr = S_OK; CPI_PARTITION_USER_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, FALSE); ExitOnFailure(hr, "Failed to send action start message"); // ger partition count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); // write count to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, iCnt); ExitOnFailure(hr, "Failed to write count to rollback file"); for (int i = 0; i < iCnt; i++) { // read partition attributes from CustomActionData hr = ReadPartitionUserAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // progress message hr = CpiActionDataMessage(1, attrs.pwzAccount); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // write key to rollback file hr = CpiWriteKeyToRollbackFile(hRollbackFile, attrs.pwzKey); ExitOnFailure(hr, "Failed to write key to rollback file"); // action switch (attrs.iActionType) { case atCreate: hr = CreatePartitionUser(&attrs); ExitOnFailure1(hr, "Failed to create partition user, key: %S", attrs.pwzKey); break; case atRemove: hr = RemovePartitionUser(&attrs); ExitOnFailure1(hr, "Failed to remove partition user, key: %S", attrs.pwzKey); break; } // write completion status to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, 1); ExitOnFailure(hr, "Failed to write completion status to rollback file"); // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreePartitionUserAttributes(&attrs); return hr; } HRESULT CpiRollbackConfigurePartitionUsers( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ) { HRESULT hr = S_OK; int iRollbackStatus; CPI_PARTITION_USER_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, NULL == pRollbackDataList); ExitOnFailure(hr, "Failed to send action start message"); // get count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); for (int i = 0; i < iCnt; i++) { // read partition attributes from CustomActionData hr = ReadPartitionUserAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // rollback status hr = CpiFindRollbackStatus(pRollbackDataList, attrs.pwzKey, &iRollbackStatus); if (S_FALSE == hr) continue; // not found, nothing to rollback // progress message hr = CpiActionDataMessage(1, attrs.pwzAccount); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // action switch (attrs.iActionType) { case atCreate: hr = CreatePartitionUser(&attrs); ExitOnFailure1(hr, "Failed to create partition user, key: %S", attrs.pwzKey); break; case atRemove: hr = RemovePartitionUser(&attrs); ExitOnFailure1(hr, "Failed to remove partition user, key: %S", attrs.pwzKey); break; } // check rollback status if (0 == iRollbackStatus) continue; // operation did not complete, skip progress // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreePartitionUserAttributes(&attrs); return hr; } // helper function definitions static HRESULT ReadPartitionAttributes( LPWSTR* ppwzData, CPI_PARTITION_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionType); ExitOnFailure(hr, "Failed to read action type"); hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionCost); ExitOnFailure(hr, "Failed to read action cost"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzKey); ExitOnFailure(hr, "Failed to read key"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzID); ExitOnFailure(hr, "Failed to read id"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzName); ExitOnFailure(hr, "Failed to read name"); hr = CpiReadPropertyList(ppwzData, &pAttrs->pPropList); ExitOnFailure(hr, "Failed to read properties"); hr = S_OK; LExit: return hr; } static void FreePartitionAttributes( CPI_PARTITION_ATTRIBUTES* pAttrs ) { ReleaseStr(pAttrs->pwzKey); ReleaseStr(pAttrs->pwzID); ReleaseStr(pAttrs->pwzName); if (pAttrs->pPropList) CpiFreePropertyList(pAttrs->pPropList); } static HRESULT CreatePartition( CPI_PARTITION_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piPartColl = NULL; ICatalogObject* piPartObj = NULL; long lChanges; // get partitions collection hr = CpiGetPartitionsCollection(&piPartColl); ExitOnFailure(hr, "Failed to get partitions collection"); // check if partition exists hr = CpiFindCollectionObjectByStringKey(piPartColl, pAttrs->pwzID, &piPartObj); ExitOnFailure(hr, "Failed to find partition"); if (S_FALSE == hr) { // create partition hr = CpiAddCollectionObject(piPartColl, &piPartObj); ExitOnFailure(hr, "Failed to add partition to collection"); hr = CpiPutCollectionObjectValue(piPartObj, L"ID", pAttrs->pwzID); ExitOnFailure(hr, "Failed to set partition id property"); hr = CpiPutCollectionObjectValue(piPartObj, L"Name", pAttrs->pwzName); ExitOnFailure(hr, "Failed to set partition name property"); } // properties hr = CpiPutCollectionObjectValues(piPartObj, pAttrs->pPropList); ExitOnFailure(hr, "Failed to write properties"); // save changes hr = piPartColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piPartColl); ReleaseObject(piPartObj); return hr; } static HRESULT RemovePartition( CPI_PARTITION_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piPartColl = NULL; long lChanges; // get partitions collection hr = CpiGetPartitionsCollection(&piPartColl); ExitOnFailure(hr, "Failed to get partitions collection"); // remove hr = CpiRemoveCollectionObjectByStringKey(piPartColl, pAttrs->pwzID, TRUE); ExitOnFailure(hr, "Failed to remove partition"); if (S_FALSE == hr) { // partition not found WcaLog(LOGMSG_VERBOSE, "Partition not found, nothing to delete: %S", pAttrs->pwzKey); } // save changes hr = piPartColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piPartColl); return hr; } static HRESULT ReadPartitionUserAttributes( LPWSTR* ppwzData, CPI_PARTITION_USER_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionType); ExitOnFailure(hr, "Failed to read action type"); hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionCost); ExitOnFailure(hr, "Failed to read action cost"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzKey); ExitOnFailure(hr, "Failed to read key"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzAccount); ExitOnFailure(hr, "Failed to read account name"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzPartID); ExitOnFailure(hr, "Failed to read partition id"); hr = S_OK; LExit: return hr; } static void FreePartitionUserAttributes( CPI_PARTITION_USER_ATTRIBUTES* pAttrs ) { ReleaseStr(pAttrs->pwzKey); ReleaseStr(pAttrs->pwzAccount); ReleaseStr(pAttrs->pwzPartID); } static HRESULT CreatePartitionUser( CPI_PARTITION_USER_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piUserColl = NULL; ICatalogObject* piUserObj = NULL; long lChanges; // get partition users collection hr = CpiGetPartitionUsersCollection(&piUserColl); ExitOnFailure(hr, "Failed to get partition users collection"); // remove any existing entry hr = CpiRemoveUserCollectionObject(piUserColl, pAttrs->pwzAccount); ExitOnFailure(hr, "Failed to remove partition user"); if (S_OK == hr) WcaLog(LOGMSG_VERBOSE, "Existing default partition for user was removed, key: %S", pAttrs->pwzKey); // add partition user hr = CpiAddCollectionObject(piUserColl, &piUserObj); ExitOnFailure(hr, "Failed to add partition to collection"); hr = CpiPutCollectionObjectValue(piUserObj, L"AccountName", pAttrs->pwzAccount); ExitOnFailure(hr, "Failed to set account name property"); hr = CpiPutCollectionObjectValue(piUserObj, L"DefaultPartitionID", pAttrs->pwzPartID); ExitOnFailure(hr, "Failed to set default partition id property"); // save changes hr = piUserColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piUserColl); ReleaseObject(piUserObj); return hr; } static HRESULT RemovePartitionUser( CPI_PARTITION_USER_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piUserColl = NULL; long lChanges; // get partition users collection hr = CpiGetPartitionUsersCollection(&piUserColl); ExitOnFailure(hr, "Failed to get partition users collection"); // remove hr = CpiRemoveUserCollectionObject(piUserColl, pAttrs->pwzAccount); ExitOnFailure(hr, "Failed to remove partition user"); if (S_FALSE == hr) WcaLog(LOGMSG_VERBOSE, "Default partition for user not found, nothing to delete, key: %S", pAttrs->pwzKey); // save changes hr = piUserColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piUserColl); return hr; } Index: pcaexec.mak =================================================================== RCS file: /cvsroot/wix/wix/src/ca/pubca/pcaexec/pcaexec.mak,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pcaexec.mak 2 May 2005 05:48:36 -0000 1.1 --- pcaexec.mak 11 May 2005 06:43:45 -0000 1.2 *************** *** 18,21 **** --- 18,28 ---- PCAEXEC_OBJ_FILES=\ pcaexec.obj \ + cpiutilexec.obj \ + cpipartexec.obj \ + cpipartroleexec.obj \ + cpiappexec.obj \ + cpiapproleexec.obj \ + cpiasmexec.obj \ + cpisubsexec.obj \ PCAEXEC_LIBS=\ --- NEW FILE: cpipartexec.h --- #pragma once //------------------------------------------------------------------------------------------------- // <copyright file="cpipartexec.h" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. // </copyright> // // <summary> // COM+ partition functions for CustomActions // </summary> //------------------------------------------------------------------------------------------------- // function prototypes HRESULT CpiConfigurePartitions( LPWSTR* ppwzData, HANDLE hRollbackFile ); HRESULT CpiRollbackConfigurePartitions( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ); HRESULT CpiConfigurePartitionUsers( LPWSTR* ppwzData, HANDLE hRollbackFile ); HRESULT CpiRollbackConfigurePartitionUsers( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ); --- NEW FILE: cpipartroleexec.h --- #pragma once //------------------------------------------------------------------------------------------------- // <copyright file="cpipartroleexec.h" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. // </copyright> // // <summary> // COM+ partition role functions for CustomActions // </summary> //------------------------------------------------------------------------------------------------- // function prototypes HRESULT CpiConfigureUsersInPartitionRoles( LPWSTR* ppwzData, HANDLE hRollbackFile ); HRESULT CpiRollbackConfigureUsersInPartitionRoles( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ); --- NEW FILE: cpiasmexec.h --- #pragma once //------------------------------------------------------------------------------------------------- // <copyright file="cpiasmexec.h" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. // </copyright> // // <summary> // COM+ assembly functions for CustomActions // </summary> //------------------------------------------------------------------------------------------------- // function prototypes HRESULT CpiConfigureAssemblies( LPWSTR* ppwzData, HANDLE hRollbackFile ); HRESULT CpiRollbackConfigureAssemblies( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ); HRESULT CpiConfigureRoleAssignments( LPWSTR* ppwzData, HANDLE hRollbackFile ); HRESULT CpiRollbackConfigureRoleAssignments( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ); --- NEW FILE: cpiapproleexec.cpp --- //------------------------------------------------------------------------------------------------- // <copyright file="cpiapproleexec.cpp" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. // </copyright> // // <summary> // COM+ application role functions for CustomActions // </summary> //------------------------------------------------------------------------------------------------- #include "precomp.h" // private structs struct CPI_APPLICATION_ROLE_ATTRIBUTES { int iActionType; int iActionCost; LPWSTR pwzKey; LPWSTR pwzName; LPWSTR pwzAppID; LPWSTR pwzPartID; CPI_PROPERTY* pPropList; }; struct CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES { int iActionType; int iActionCost; LPWSTR pwzKey; LPWSTR pwzRoleName; LPWSTR pwzAccount; LPWSTR pwzAppID; LPWSTR pwzPartID; }; // prototypes for private helper functions static HRESULT ReadApplicationRoleAttributes( LPWSTR* ppwzData, CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); static void FreeApplicationRoleAttributes( CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); static HRESULT CreateApplicationRole( CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); static HRESULT RemoveApplicationRole( CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); static HRESULT ReadUsersInApplicationRoleAttributes( LPWSTR* ppwzData, CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); static void FreeUsersInApplicationRoleAttributes( CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); static HRESULT CreateUsersInApplicationRole( CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); static HRESULT RemoveUsersInApplicationRole( CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ); // function definitions HRESULT CpiConfigureApplicationRoles( LPWSTR* ppwzData, HANDLE hRollbackFile ) { HRESULT hr = S_OK; CPI_APPLICATION_ROLE_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, FALSE); ExitOnFailure(hr, "Failed to send action start message"); // ger count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); // write count to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, iCnt); ExitOnFailure(hr, "Failed to write count to rollback file"); for (int i = 0; i < iCnt; i++) { // read attributes from CustomActionData hr = ReadApplicationRoleAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // progress message hr = CpiActionDataMessage(1, attrs.pwzName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // write key to rollback file hr = CpiWriteKeyToRollbackFile(hRollbackFile, attrs.pwzKey); ExitOnFailure(hr, "Failed to write key to rollback file"); // action switch (attrs.iActionType) { case atCreate: hr = CreateApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to create role, key: %S", attrs.pwzKey); break; case atRemove: hr = RemoveApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to remove role, key: %S", attrs.pwzKey); break; } // write completion status to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, 1); ExitOnFailure(hr, "Failed to write completion status to rollback file"); // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreeApplicationRoleAttributes(&attrs); return hr; } HRESULT CpiRollbackConfigureApplicationRoles( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ) { HRESULT hr = S_OK; int iRollbackStatus; CPI_APPLICATION_ROLE_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, NULL == pRollbackDataList); ExitOnFailure(hr, "Failed to send action start message"); // get count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); for (int i = 0; i < iCnt; i++) { // read attributes from CustomActionData hr = ReadApplicationRoleAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // rollback status hr = CpiFindRollbackStatus(pRollbackDataList, attrs.pwzKey, &iRollbackStatus); if (S_FALSE == hr) continue; // not found, nothing to rollback // progress message hr = CpiActionDataMessage(1, attrs.pwzName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // action switch (attrs.iActionType) { case atCreate: hr = CreateApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to create role, key: %S", attrs.pwzKey); break; case atRemove: hr = RemoveApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to remove role, key: %S", attrs.pwzKey); break; } // check rollback status if (0 == iRollbackStatus) continue; // operation did not complete, skip progress // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreeApplicationRoleAttributes(&attrs); return hr; } HRESULT CpiConfigureUsersInApplicationRoles( LPWSTR* ppwzData, HANDLE hRollbackFile ) { HRESULT hr = S_OK; CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, FALSE); ExitOnFailure(hr, "Failed to send action start message"); // ger count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); // write count to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, iCnt); ExitOnFailure(hr, "Failed to write count to rollback file"); for (int i = 0; i < iCnt; i++) { // read attributes from CustomActionData hr = ReadUsersInApplicationRoleAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // progress message hr = CpiActionDataMessage(1, attrs.pwzRoleName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // write key to rollback file hr = CpiWriteKeyToRollbackFile(hRollbackFile, attrs.pwzKey); ExitOnFailure(hr, "Failed to write key to rollback file"); // action switch (attrs.iActionType) { case atCreate: hr = CreateUsersInApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to create user in application role, key: %S", attrs.pwzKey); break; case atRemove: hr = RemoveUsersInApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to remove user in application role, key: %S", attrs.pwzKey); break; } // write completion status to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, 1); ExitOnFailure(hr, "Failed to write completion status to rollback file"); // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreeUsersInApplicationRoleAttributes(&attrs); return hr; } HRESULT CpiRollbackConfigureUsersInApplicationRoles( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ) { HRESULT hr = S_OK; int iRollbackStatus; CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, NULL == pRollbackDataList); ExitOnFailure(hr, "Failed to send action start message"); // get count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); for (int i = 0; i < iCnt; i++) { // read attributes from CustomActionData hr = ReadUsersInApplicationRoleAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // rollback status hr = CpiFindRollbackStatus(pRollbackDataList, attrs.pwzKey, &iRollbackStatus); if (S_FALSE == hr) continue; // not found, nothing to rollback // progress message hr = CpiActionDataMessage(1, attrs.pwzRoleName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // action switch (attrs.iActionType) { case atCreate: hr = CreateUsersInApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to create user in application role, key: %S", attrs.pwzKey); break; case atRemove: hr = RemoveUsersInApplicationRole(&attrs); ExitOnFailure1(hr, "Failed to remove user in application role, key: %S", attrs.pwzKey); break; } // check rollback status if (0 == iRollbackStatus) continue; // operation did not complete, skip progress // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreeUsersInApplicationRoleAttributes(&attrs); return hr; } // helper function definitions static HRESULT ReadApplicationRoleAttributes( LPWSTR* ppwzData, CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionType); ExitOnFailure(hr, "Failed to read action type"); hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionCost); ExitOnFailure(hr, "Failed to read action cost"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzKey); ExitOnFailure(hr, "Failed to read key"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzName); ExitOnFailure(hr, "Failed to read name"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzAppID); ExitOnFailure(hr, "Failed to read application id"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzPartID); ExitOnFailure(hr, "Failed to read partition id"); hr = CpiReadPropertyList(ppwzData, &pAttrs->pPropList); ExitOnFailure(hr, "Failed to read properties"); hr = S_OK; LExit: return hr; } static void FreeApplicationRoleAttributes( CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { ReleaseStr(pAttrs->pwzKey); ReleaseStr(pAttrs->pwzName); ReleaseStr(pAttrs->pwzAppID); ReleaseStr(pAttrs->pwzPartID); if (pAttrs->pPropList) CpiFreePropertyList(pAttrs->pPropList); } static HRESULT CreateApplicationRole( CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piRolesColl = NULL; ICatalogObject* piRoleObj = NULL; long lChanges; // get roles collection hr = CpiGetRolesCollection(pAttrs->pwzPartID, pAttrs->pwzAppID, &piRolesColl); if (S_FALSE == hr) hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); ExitOnFailure(hr, "Failed to get roles collection"); // check if role exists hr = CpiFindCollectionObjectByName(piRolesColl, pAttrs->pwzName, &piRoleObj); ExitOnFailure(hr, "Failed to find role"); if (S_FALSE == hr) { // create role hr = CpiAddCollectionObject(piRolesColl, &piRoleObj); ExitOnFailure(hr, "Failed to add role to collection"); hr = CpiPutCollectionObjectValue(piRoleObj, L"Name", pAttrs->pwzName); ExitOnFailure(hr, "Failed to set role name property"); } // properties hr = CpiPutCollectionObjectValues(piRoleObj, pAttrs->pPropList); ExitOnFailure(hr, "Failed to write properties"); // save changes hr = piRolesColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piRolesColl); ReleaseObject(piRoleObj); return hr; } static HRESULT RemoveApplicationRole( CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piRolesColl = NULL; long lChanges; // get roles collection hr = CpiGetRolesCollection(pAttrs->pwzPartID, pAttrs->pwzAppID, &piRolesColl); ExitOnFailure(hr, "Failed to get roles collection"); if (S_FALSE == hr) { // roles collection not found WcaLog(LOGMSG_VERBOSE, "Unable to retrieve roles collection, skipping action, nothing to delete: %S", pAttrs->pwzKey); ExitFunction1(hr = S_OK); } // remove hr = CpiRemoveCollectionObjectByName(piRolesColl, pAttrs->pwzName); ExitOnFailure(hr, "Failed to remove role"); if (S_FALSE == hr) { // role not found WcaLog(LOGMSG_VERBOSE, "Role not found, nothing to delete: %S", pAttrs->pwzKey); } // save changes hr = piRolesColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piRolesColl); return hr; } static HRESULT ReadUsersInApplicationRoleAttributes( LPWSTR* ppwzData, CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionType); ExitOnFailure(hr, "Failed to read action type"); hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionCost); ExitOnFailure(hr, "Failed to read action cost"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzKey); ExitOnFailure(hr, "Failed to read key"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzRoleName); ExitOnFailure(hr, "Failed to read role name"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzAccount); ExitOnFailure(hr, "Failed to read account name"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzAppID); ExitOnFailure(hr, "Failed to read application id"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzPartID); ExitOnFailure(hr, "Failed to read partition id"); hr = S_OK; LExit: return hr; } static void FreeUsersInApplicationRoleAttributes( CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { ReleaseStr(pAttrs->pwzKey); ReleaseStr(pAttrs->pwzRoleName); ReleaseStr(pAttrs->pwzAccount); ReleaseStr(pAttrs->pwzAppID); ReleaseStr(pAttrs->pwzPartID); } static HRESULT CreateUsersInApplicationRole( CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piUsrInRoleColl = NULL; ICatalogObject* piUsrInRoleObj = NULL; long lChanges; // get users in role collection hr = CpiGetUsersInRoleCollection(pAttrs->pwzPartID, pAttrs->pwzAppID, pAttrs->pwzRoleName, &piUsrInRoleColl); if (S_FALSE == hr) hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); ExitOnFailure(hr, "Failed to get users in role collection"); // find any existing entry hr = CpiFindUserCollectionObject(piUsrInRoleColl, pAttrs->pwzAccount, NULL); ExitOnFailure(hr, "Failed to find user in application role"); if (S_OK == hr) { WcaLog(LOGMSG_VERBOSE, "User already assigned to application role, key: %S", pAttrs->pwzKey); ExitFunction(); // exit with hr = S_OK } // add user hr = CpiAddCollectionObject(piUsrInRoleColl, &piUsrInRoleObj); ExitOnFailure(hr, "Failed to add user in role to collection"); hr = CpiPutCollectionObjectValue(piUsrInRoleObj, L"User", pAttrs->pwzAccount); ExitOnFailure(hr, "Failed to set role name property"); // save changes hr = piUsrInRoleColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piUsrInRoleColl); ReleaseObject(piUsrInRoleObj); return hr; } static HRESULT RemoveUsersInApplicationRole( CPI_USER_IN_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piUsrInRoleColl = NULL; long lChanges; // get users in role collection hr = CpiGetUsersInRoleCollection(pAttrs->pwzPartID, pAttrs->pwzAppID, pAttrs->pwzRoleName, &piUsrInRoleColl); ExitOnFailure(hr, "Failed to get users in role collection"); if (S_FALSE == hr) { // users in role collection not found WcaLog(LOGMSG_VERBOSE, "Unable to retrieve users in role collection, skipping action, nothing to delete: %S", pAttrs->pwzKey); ExitFunction1(hr = S_OK); } // remove hr = CpiRemoveUserCollectionObject(piUsrInRoleColl, pAttrs->pwzAccount); ExitOnFailure(hr, "Failed to remove user"); if (S_FALSE == hr) { // role not found WcaLog(LOGMSG_VERBOSE, "User not found, nothing to delete: %S", pAttrs->pwzKey); ExitFunction1(hr = S_OK); } // save changes hr = piUsrInRoleColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piUsrInRoleColl); return hr; } Index: precomp.h =================================================================== RCS file: /cvsroot/wix/wix/src/ca/pubca/pcaexec/precomp.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** precomp.h 2 May 2005 05:48:36 -0000 1.1 --- precomp.h 11 May 2005 06:43:45 -0000 1.2 *************** *** 25,30 **** --- 25,42 ---- #include <msiquery.h> #include <strsafe.h> + #include <comadmin.h> + #include <ntsecapi.h> #include "wcautil.h" #include "memutil.h" #include "strutil.h" + + #include "..\inc\pcacost.h" + #include "..\inc\pcaerr.h" + #include "cpiutilexec.h" + #include "cpipartexec.h" + #include "cpipartroleexec.h" + #include "cpiappexec.h" + #include "cpiapproleexec.h" + #include "cpiasmexec.h" + #include "cpisubsexec.h" --- NEW FILE: cpisubsexec.cpp --- //------------------------------------------------------------------------------------------------- // <copyright file="cpisubsexec.cpp" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. // </copyright> // // <summary> // COM+ subscription functions for CustomActions // </summary> //------------------------------------------------------------------------------------------------- #include "precomp.h" // private structs struct CPI_SUBSCRIPTION_ATTRIBUTES { int iActionType; int iActionCost; LPWSTR pwzKey; LPWSTR pwzID; LPWSTR pwzName; LPWSTR pwzEventCLSID; LPWSTR pwzPublisherID; LPWSTR pwzCompCLSID; LPWSTR pwzAppID; LPWSTR pwzPartID; CPI_PROPERTY* pPropList; }; // prototypes for private helper functions static HRESULT ReadSubscriptionAttributes( LPWSTR* ppwzData, CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ); static void FreeSubscriptionAttributes( CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ); static HRESULT CreateSubscription( CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ); static HRESULT RemoveSubscription( CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ); // function definitions HRESULT CpiConfigureSubscriptions( LPWSTR* ppwzData, HANDLE hRollbackFile ) { HRESULT hr = S_OK; CPI_SUBSCRIPTION_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, FALSE); ExitOnFailure(hr, "Failed to send action start message"); // ger count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); // write count to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, iCnt); ExitOnFailure(hr, "Failed to write count to rollback file"); for (int i = 0; i < iCnt; i++) { // read attributes from CustomActionData hr = ReadSubscriptionAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // progress message hr = CpiActionDataMessage(1, attrs.pwzName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // write key to rollback file hr = CpiWriteKeyToRollbackFile(hRollbackFile, attrs.pwzKey); ExitOnFailure(hr, "Failed to write key to rollback file"); // action switch (attrs.iActionType) { case atCreate: hr = CreateSubscription(&attrs); ExitOnFailure1(hr, "Failed to create subscription, key: %S", attrs.pwzKey); break; case atRemove: hr = RemoveSubscription(&attrs); ExitOnFailure1(hr, "Failed to remove subscription, key: %S", attrs.pwzKey); break; } // write completion status to rollback file hr = CpiWriteIntegerToRollbackFile(hRollbackFile, 1); ExitOnFailure(hr, "Failed to write completion status to rollback file"); // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreeSubscriptionAttributes(&attrs); return hr; } HRESULT CpiRollbackConfigureSubscriptions( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ) { HRESULT hr = S_OK; int iRollbackStatus; CPI_SUBSCRIPTION_ATTRIBUTES attrs; ::ZeroMemory(&attrs, sizeof(attrs)); // read action text hr = CpiActionStartMessage(ppwzData, NULL == pRollbackDataList); ExitOnFailure(hr, "Failed to send action start message"); // ger count int iCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); ExitOnFailure(hr, "Failed to read count"); for (int i = 0; i < iCnt; i++) { // read attributes from CustomActionData hr = ReadSubscriptionAttributes(ppwzData, &attrs); ExitOnFailure(hr, "Failed to read attributes"); // rollback status hr = CpiFindRollbackStatus(pRollbackDataList, attrs.pwzKey, &iRollbackStatus); if (S_FALSE == hr) continue; // not found, nothing to rollback // progress message hr = CpiActionDataMessage(1, attrs.pwzName); ExitOnFailure(hr, "Failed to send progress messages"); if (S_FALSE == hr) ExitFunction(); // action switch (attrs.iActionType) { case atCreate: hr = CreateSubscription(&attrs); ExitOnFailure1(hr, "Failed to create subscription, key: %S", attrs.pwzKey); break; case atRemove: hr = RemoveSubscription(&attrs); ExitOnFailure1(hr, "Failed to remove subscription, key: %S", attrs.pwzKey); break; } // check rollback status if (0 == iRollbackStatus) continue; // operation did not complete, skip progress // progress hr = WcaProgressMessage(attrs.iActionCost, FALSE); ExitOnFailure(hr, "Failed to update progress"); } hr = S_OK; LExit: // clean up FreeSubscriptionAttributes(&attrs); return hr; } // helper function definitions static HRESULT ReadSubscriptionAttributes( LPWSTR* ppwzData, CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionType); ExitOnFailure(hr, "Failed to read action type"); hr = WcaReadIntegerFromCaData(ppwzData, &pAttrs->iActionCost); ExitOnFailure(hr, "Failed to read action cost"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzKey); ExitOnFailure(hr, "Failed to read key"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzID); ExitOnFailure(hr, "Failed to read id"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzName); ExitOnFailure(hr, "Failed to read name"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzEventCLSID); ExitOnFailure(hr, "Failed to read event clsid"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzPublisherID); ExitOnFailure(hr, "Failed to read publisher id"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzCompCLSID); ExitOnFailure(hr, "Failed to read component clsid"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzAppID); ExitOnFailure(hr, "Failed to read application id"); hr = WcaReadStringFromCaData(ppwzData, &pAttrs->pwzPartID); ExitOnFailure(hr, "Failed to read partition id"); hr = CpiReadPropertyList(ppwzData, &pAttrs->pPropList); ExitOnFailure(hr, "Failed to read properties"); hr = S_OK; LExit: return hr; } static void FreeSubscriptionAttributes( CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ) { ReleaseStr(pAttrs->pwzKey); ReleaseStr(pAttrs->pwzID); ReleaseStr(pAttrs->pwzName); ReleaseStr(pAttrs->pwzEventCLSID); ReleaseStr(pAttrs->pwzPublisherID); ReleaseStr(pAttrs->pwzCompCLSID); ReleaseStr(pAttrs->pwzAppID); ReleaseStr(pAttrs->pwzPartID); if (pAttrs->pPropList) CpiFreePropertyList(pAttrs->pPropList); } static HRESULT CreateSubscription( CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piSubsColl = NULL; ICatalogObject* piSubsObj = NULL; long lChanges; // get subscriptions collection hr = CpiGetSubscriptionsCollection(pAttrs->pwzPartID, pAttrs->pwzAppID, pAttrs->pwzCompCLSID, &piSubsColl); if (S_FALSE == hr) hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); ExitOnFailure(hr, "Failed to get subscriptions collection"); // check if subscription exists hr = CpiFindCollectionObjectByStringKey(piSubsColl, pAttrs->pwzID, &piSubsObj); ExitOnFailure(hr, "Failed to find subscription"); if (S_FALSE == hr) { // create role hr = CpiAddCollectionObject(piSubsColl, &piSubsObj); ExitOnFailure(hr, "Failed to add subscription to collection"); hr = CpiPutCollectionObjectValue(piSubsObj, L"ID", pAttrs->pwzID); ExitOnFailure(hr, "Failed to set subscription id property"); hr = CpiPutCollectionObjectValue(piSubsObj, L"Name", pAttrs->pwzName); ExitOnFailure(hr, "Failed to set subscription name property"); if (pAttrs->pwzEventCLSID && *pAttrs->pwzEventCLSID) { hr = CpiPutCollectionObjectValue(piSubsObj, L"EventCLSID", pAttrs->pwzEventCLSID); ExitOnFailure(hr, "Failed to set role event clsid property"); } if (pAttrs->pwzPublisherID && *pAttrs->pwzPublisherID) { hr = CpiPutCollectionObjectValue(piSubsObj, L"PublisherID", pAttrs->pwzPublisherID); ExitOnFailure(hr, "Failed to set role publisher id property"); } } // properties hr = CpiPutCollectionObjectValues(piSubsObj, pAttrs->pPropList); ExitOnFailure(hr, "Failed to write properties"); // save changes hr = piSubsColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piSubsColl); ReleaseObject(piSubsObj); return hr; } static HRESULT RemoveSubscription( CPI_SUBSCRIPTION_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piSubsColl = NULL; long lChanges; // get subscriptions collection hr = CpiGetSubscriptionsCollection(pAttrs->pwzPartID, pAttrs->pwzAppID, pAttrs->pwzCompCLSID, &piSubsColl); ExitOnFailure(hr, "Failed to get subscriptions collection"); if (S_FALSE == hr) { WcaLog(LOGMSG_VERBOSE, "Unable to retrieve subscriptions collection, skipping action - nothing to delete"); ExitFunction1(hr = S_OK); } // remove hr = CpiRemoveCollectionObjectByStringKey(piSubsColl, pAttrs->pwzID, FALSE); ExitOnFailure(hr, "Failed to remove subscriptions"); // save changes hr = piSubsColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); hr = S_OK; LExit: // clean up ReleaseObject(piSubsColl); return hr; } --- NEW FILE: cpisubsexec.h --- #pragma once //------------------------------------------------------------------------------------------------- // <copyright file="cpisubsexec.h" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. // </copyright> // // <summary> // COM+ subscription functions for CustomActions // </summary> //------------------------------------------------------------------------------------------------- // function prototypes HRESULT CpiConfigureSubscriptions( LPWSTR* ppwzData, HANDLE hRollbackFile ); HRESULT CpiRollbackConfigureSubscriptions( LPWSTR* ppwzData, CPI_ROLLBACK_DATA* pRollbackDataList ); Index: pcaexec.cpp =================================================================== RCS file: /cvsroot/wix/wix/src/ca/pubca/pcaexec/pcaexec.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pcaexec.cpp 2 May 2005 05:48:36 -0000 1.1 --- pcaexec.cpp 11 May 2005 06:43:45 -0000 1.2 *************** *** 39,41 **** return TRUE; ! } \ No newline at end of file --- 39,705 ---- return TRUE; ! } ! ! /******************************************************************** ! ComPlusPrepare - CUSTOM ACTION ENTRY POINT ! ! Input: deferred CustomActionData - ComPlusPrepare ! ********************************************************************/ ! extern "C" UINT __stdcall ComPlusPrepare(MSIHANDLE hInstall) ! { ! HRESULT hr = S_OK; ! UINT er = ERROR_SUCCESS; ! ! LPWSTR pwzData = NULL; ! ! HANDLE hRollbackFile = INVALID_HANDLE_VALUE; ! ! // initialize ! hr = WcaInitialize(hInstall, "ComPlusPrepare"); ! ExitOnFailure(hr, "Failed to initialize ComPlusPrepare"); ! ! // get custom action data ! hr = WcaGetProperty(L"CustomActionData", &pwzData); ! ExitOnFailure(hr, "Failed to get CustomActionData"); ! ! // create rollback file ! hRollbackFile = ::CreateFileW(pwzData, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY, NULL); ! if (INVALID_HANDLE_VALUE == hRollbackFile) ! ExitOnFailure1(hr = HRESULT_FROM_WIN32(::GetLastError()), "Failed to create rollback file, name: %S", pwzData); ! ! hr = S_OK; ! ! LExit: ! // clean up ! ReleaseStr(pwzData); ! ! if (INVALID_HANDLE_VALUE != hRollbackFile) ! ::CloseHandle(hRollbackFile); ! ! er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; ! return WcaFinalize(er); ! } ! ! /******************************************************************** ! ComPlusCleanup - CUSTOM ACTION ENTRY POINT ! ! Input: deferred CustomActionData - ComPlusCleanup ! ********************************************************************/ ! extern "C" UINT __stdcall ComPlusCleanup(MSIHANDLE hInstall) ! { ! HRESULT hr = S_OK; ! UINT er = ERROR_SUCCESS; ! ! LPWSTR pwzData = NULL; ! ! // initialize ! hr = WcaInitialize(hInstall, "ComPlusCleanup"); ! ExitOnFailure(hr, "Failed to initialize ComPlusCleanup"); ! ! // get custom action data ! hr = WcaGetProperty(L"CustomActionData", &pwzData); ! ExitOnFailure(hr, "Failed to get CustomActionData"); ! ! // delete rollback file ! if (!::DeleteFileW(pwzData)) ! { ! // error, but not a showstopper ! hr = HRESULT_FROM_WIN32(::GetLastError()); ! WcaLog(LOGMSG_STANDARD, "Failed to delete rollback file, hr: 0x%x, name: %S", hr, pwzData); ! } ! ! hr = S_OK; ! ! LExit: ! // clean up ! ReleaseStr(pwzData); ! ! er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; ! return WcaFinalize(er); ! } ! ! /******************************************************************** ! ComPlusInstallExecute - CUSTOM ACTION ENTRY POINT ! ! Input: deferred CustomActionData - ComPlusInstallExecute ! ********************************************************************/ ! extern "C" UINT __stdcall ComPlusInstallExecute(MSIHANDLE hInstall) ! { ! HRESULT hr = S_OK; ! UINT er = ERROR_SUCCESS; ! ! LPWSTR pwzData = NULL; ! LPWSTR pwzRollbackFileName = NULL; ! ! HANDLE hRollbackFile = INVALID_HANDLE_VALUE; ! ! BOOL fInitializedCom = FALSE; ! ! // initialize ! hr = WcaInitialize(hInstall, "ComPlusInstallExecute"); ! ExitOnFailure(hr, "Failed to initialize ComPlusInstallExecute"); ! ! hr = ::CoInitialize(NULL); ! ExitOnFailure(hr, "Failed to initialize COM"); ! fInitializedCom = TRUE; ! ! CpiInitialize(); ! ! // get custom action data ! hr = WcaGetProperty(L"CustomActionData", &pwzData); ! ExitOnFailure(hr, "Failed to get CustomActionData"); ! ! // open rollback file ! hr = WcaReadStringFromCaData(&pwzData, &pwzRollbackFileName); ! ExitOnFailure(hr, "Failed to read rollback file name"); ! ! hRollbackFile = ::CreateFileW(pwzRollbackFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL); ! if (INVALID_HANDLE_VALUE == hRollbackFile) ! ExitOnFailure1(hr = HRESULT_FROM_WIN32(::GetLastError()), "Failed to open rollback file, name: %S", pwzRollbackFileName); ! ! // create partitions ! hr = CpiConfigurePartitions(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create partitions"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create users in partition roles ! hr = CpiConfigureUsersInPartitionRoles(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create users in partition roles"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create partition users ! hr = CpiConfigurePartitionUsers(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to add partition users"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create applications ! hr = CpiConfigureApplications(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create applications"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create application roles ! hr = CpiConfigureApplicationRoles(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create application roles"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create users in application roles ! hr = CpiConfigureUsersInApplicationRoles(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create users in application roles"); ! if (S_FALSE == hr) ExitFunction(); ! ! // register assemblies ! hr = CpiConfigureAssemblies(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to register assemblies"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create role assignments ! hr = CpiConfigureRoleAssignments(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create role assignments"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create subscriptions ! hr = CpiConfigureSubscriptions(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create subscriptions"); ! if (S_FALSE == hr) ExitFunction(); ! ! hr = S_OK; ! ! LExit: ! // clean up ! ReleaseStr(pwzData); ! ReleaseStr(pwzRollbackFileName); ! ! if (INVALID_HANDLE_VALUE != hRollbackFile) ! ::CloseHandle(hRollbackFile); ! ! // unitialize ! CpiFinalize(); ! ! if (fInitializedCom) ! ::CoUninitialize(); ! ! er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; ! return WcaFinalize(er); ! } ! ! /******************************************************************** ! ComPlusInstallExecuteCommit - CUSTOM ACTION ENTRY POINT ! ! Input: deferred CustomActionData - ComPlusInstallExecuteCommit ! ********************************************************************/ ! extern "C" UINT __stdcall ComPlusInstallExecuteCommit(MSIHANDLE hInstall) ! { ! HRESULT hr = S_OK; ! UINT er = ERROR_SUCCESS; ! ! LPWSTR pwzData = NULL; ! LPWSTR pwzRollbackFileName = NULL; ! ! HANDLE hRollbackFile = INVALID_HANDLE_VALUE; ! ! BOOL fInitializedCom = FALSE; ! ! // initialize ! hr = WcaInitialize(hInstall, "ComPlusInstallExecuteCommit"); ! ExitOnFailure(hr, "Failed to initialize ComPlusInstallExecuteCommit"); ! ! hr = ::CoInitialize(NULL); ! ExitOnFailure(hr, "Failed to initialize COM"); ! fInitializedCom = TRUE; ! ! CpiInitialize(); ! ! // get custom action data ! hr = WcaGetProperty(L"CustomActionData", &pwzData); ! ExitOnFailure(hr, "Failed to get CustomActionData"); ! ! // open rollback file ! hr = WcaReadStringFromCaData(&pwzData, &pwzRollbackFileName); ! ExitOnFailure(hr, "Failed to read rollback file name"); ! ! hRollbackFile = ::CreateFileW(pwzRollbackFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL); ! if (INVALID_HANDLE_VALUE == hRollbackFile) ! ExitOnFailure1(hr = HRESULT_FROM_WIN32(::GetLastError()), "Failed to open rollback file, name: %S", pwzRollbackFileName); ! ! if (INVALID_SET_FILE_POINTER == ::SetFilePointer(hRollbackFile, 0, NULL, FILE_END)) ! ExitOnFailure(hr = HRESULT_FROM_WIN32(::GetLastError()), "Failed to set file pointer"); ! ! // register assemblies ! hr = CpiConfigureAssemblies(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to register assemblies"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create role assignments ! hr = CpiConfigureRoleAssignments(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create role assignments"); ! if (S_FALSE == hr) ExitFunction(); ! ! // create subscriptions ! hr = CpiConfigureSubscriptions(&pwzData, hRollbackFile); ! ExitOnFailure(hr, "Failed to create subscriptions"); ! if (S_FALSE == hr) ExitFunction(); ! ! hr = S_OK; ! ! LExit: ! // clean up ! ReleaseStr(pwzData); ! ! if (INVALID_HANDLE_VALUE != hRollbackFile) ! ::CloseHandle(hRollbackFile); ! ! // unitialize ! CpiFinalize(); ! ! if (fInitializedCom) ! ::CoUninitialize(); ! ! er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; ! return WcaFinalize(er); ! } ! ! /******************************************************************** ! ComPlusRollbackInstallExecute - CUSTOM ACTION ENTRY POINT ! ! Input: deferred CustomActionData - ComPlusRollbackInstallExecute ! ********************************************************************/ ! extern "C" UINT __stdcall ComPlusRollbackInstallExecute(MSIHANDLE hInstall) ! { ! HRESULT hr = S_OK; ! UINT er = ERROR_SUCCESS; ! ! LPWSTR pwzData = NULL; ! LPWSTR pwzRollbackFileName = NULL; ! ! HANDLE hRollbackFile = INVALID_HANDLE_VALUE; ! ! CPI_ROLLBACK_DATA* prdPartitions = NULL; ! CPI_ROLLBACK_DATA* prdUsersInPartitionRoles = NULL; ! CPI_ROLLBACK_DATA* prdPartitionUsers = NULL; ! CPI_ROLLBACK_DATA* prdApplications = NULL; ! CPI_ROLLBACK_DATA* prdApplicationRoles = NULL; ! CPI_ROLLBACK_DATA* prdUsersApplicationRoles = NULL; ! CPI_ROLLBACK_DATA* prdAssemblies = NULL; ! CPI_ROLLBACK_DATA* prdRoleAssignments = NULL; ! CPI_ROLLBACK_DATA* prdSubscriptions = NULL; ! ! BOOL fInitializedCom = FALSE; ! ! // initialize ! hr = WcaInitialize(hInstall, "ComPlusRollbackInstallExecute"); ! ExitOnFailure(hr, "Failed to initialize ComPlusRollbackInstallExecute"); ! ! hr = ::CoInitialize(NULL); ! ExitOnFailure(hr, "Failed to initialize COM"); ! fInitializedCom = TRUE; ! ! CpiInitialize(); ! ! // get custom action data ! hr = WcaGetProperty(L"CustomActionData", &pwzData); ! ExitOnFailure(hr, "Failed to get CustomActionData"); ! ! // open rollback file ! hr = WcaReadStringFromCaData(&pwzData, &pwzRollbackFileName); ! ExitOnFailure(hr, "Failed to read rollback file name"); ! ! hRollbackFile = ::CreateFileW(pwzRollbackFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL); ! if (INVALID_HANDLE_VALUE == hRollbackFile) ! ExitOnFailure1(hr = HRESULT_FROM_WIN32(::GetLastError()), "Failed to open rollback file, name: %S", pwzRollbackFileName); ! ! // read rollback data (execute) ! hr = CpiReadRollbackDataList(hRollbackFile, &prdPartitions); ! ExitOnFailure(hr, "Failed to read partitions rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdUsersInPartitionRoles); ! ExitOnFailure(hr, "Failed to read users in partition roles rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdPartitionUsers); ! ExitOnFailure(hr, "Failed to read partition users rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdApplications); ! ExitOnFailure(hr, "Failed to read applications rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdApplicationRoles); ! ExitOnFailure(hr, "Failed to read application roles rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdUsersApplicationRoles); ! ExitOnFailure(hr, "Failed to read users in application roles rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdAssemblies); ! ExitOnFailure(hr, "Failed to read assemblies rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdRoleAssignments); ! ExitOnFailure(hr, "Failed to read role assignments rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdSubscriptions); ! ExitOnFailure(hr, "Failed to read subscription rollback data"); ! ! // read rollback data (commit) ! hr = CpiReadRollbackDataList(hRollbackFile, &prdAssemblies); ! ExitOnFailure(hr, "Failed to read assemblies rollback data (commit)"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdRoleAssignments); ! ExitOnFailure(hr, "Failed to read role assignments rollback data"); ! hr = CpiReadRollbackDataList(hRollbackFile, &prdSubscriptions); ! ExitOnFailure(hr, "Failed to read subscription rollback data (commit)"); ! ! ::CloseHandle(hRollbackFile); ! hRollbackFile = INVALID_HANDLE_VALUE; !... [truncated message content] |