HRESULT CpiGetApplicationsCollForPartition( CPI_PARTITION* pPart, ICatalogCollection** ppiAppColl ) { HRESULT hr = S_OK; ICatalogCollection* piPartColl = NULL; ICatalogObject* piPartObj = NULL; // if a previous attempt to locate the collection object failed if (pPart->fObjectNotFound) ExitFunction1(hr = S_FALSE); // get applications collection if (!pPart->piApplicationsColl) { // get partitions collection from catalog hr = CpiGetPartitionsCollection(&piPartColl); ExitOnFailure(hr, "Failed to get partitions collection"); // find application object hr = CpiFindCollectionObject(piPartColl, pPart->wzID, *pPart->wzID ? NULL : pPart->wzName, &piPartObj); ExitOnFailure(hr, "Failed to find partition object"); if (S_FALSE == hr) { pPart->fObjectNotFound = TRUE; ExitFunction(); // exit with hr = S_FALSE } // get roles collection hr = CpiGetCatalogCollection(piPartColl, piPartObj, L"Applications", &pPart->piApplicationsColl); ExitOnFailure(hr, "Failed to get applications collection"); } // return value *ppiAppColl = pPart->piApplicationsColl; (*ppiAppColl)->AddRef(); hr = S_OK; LExit: // clean up ReleaseObject(piPartColl); ReleaseObject(piPartObj); return hr; }
HRESULT CpiGetPartitionsCollection( ICatalogCollection** ppiPartColl ) { HRESULT hr = S_OK; // get collection hr = CpiGetCatalogCollection(L"Partitions", ppiPartColl); ExitOnFailure(hr, "Failed to get catalog collection"); hr = S_OK; LExit: return hr; }
HRESULT CpiGetMethodsCollection( ICatalogCollection* piIntfColl, ICatalogObject* piIntfObj, ICatalogCollection** ppiMethColl ) { HRESULT hr = S_OK; // get interfaces collection hr = CpiGetCatalogCollection(piIntfColl, piIntfObj, L"MethodsForInterface", ppiMethColl); ExitOnFailure(hr, "Failed to get catalog collection"); hr = S_OK; LExit: return hr; }
HRESULT CpiGetInterfacesCollection( ICatalogCollection* piCompColl, ICatalogObject* piCompObj, ICatalogCollection** ppiIntfColl ) { HRESULT hr = S_OK; // get interfaces collection hr = CpiGetCatalogCollection(piCompColl, piCompObj, L"InterfacesForComponent", ppiIntfColl); ExitOnFailure(hr, "Failed to get catalog collection"); hr = S_OK; LExit: return hr; }
HRESULT CpiGetPartitionsCollection( ICatalogCollection** ppiPartColl ) { HRESULT hr = S_OK; if (!gpiPartColl) { // get collection hr = CpiGetCatalogCollection(L"Partitions", &gpiPartColl); ExitOnFailure(hr, "Failed to get partitions collection"); } // return value gpiPartColl->AddRef(); *ppiPartColl = gpiPartColl; hr = S_OK; LExit: return hr; }
HRESULT CpiGetSubscriptionsCollection( LPCWSTR pwzPartID, LPCWSTR pwzAppID, LPCWSTR pwzCompCLSID, ICatalogCollection** ppiSubsColl ) { HRESULT hr = S_OK; ICatalogCollection* piCompColl = NULL; ICatalogObject* piCompObj = NULL; // get components collection hr = CpiGetComponentsCollection(pwzPartID, pwzAppID, &piCompColl); ExitOnFailure(hr, "Failed to get components collection"); if (S_FALSE == hr) ExitFunction(); // components collection not found, exit with hr = S_FALSE // find object hr = CpiFindCollectionObjectByStringKey(piCompColl, pwzCompCLSID, &piCompObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // component not found, exit with hr = S_FALSE // get subscriptions collection hr = CpiGetCatalogCollection(piCompColl, piCompObj, L"SubscriptionsForComponent", ppiSubsColl); ExitOnFailure(hr, "Failed to get catalog collection"); hr = S_OK; LExit: // clean up ReleaseObject(piCompColl); ReleaseObject(piCompObj); return hr; }
HRESULT CpiGetUsersInRoleCollection( LPCWSTR pwzPartID, LPCWSTR pwzAppID, LPCWSTR pwzRoleName, ICatalogCollection** ppiUsrInRoleColl ) { HRESULT hr = S_OK; ICatalogCollection* piRoleColl = NULL; ICatalogObject* piRoleObj = NULL; // get roles collection hr = CpiGetRolesCollection(pwzPartID, pwzAppID, &piRoleColl); ExitOnFailure(hr, "Failed to get roles collection"); if (S_FALSE == hr) ExitFunction(); // roles collection not found, exit with hr = S_FALSE // find object hr = CpiFindCollectionObjectByName(piRoleColl, pwzRoleName, &piRoleObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // role not found, exit with hr = S_FALSE // get roles collection hr = CpiGetCatalogCollection(piRoleColl, piRoleObj, L"UsersInRole", ppiUsrInRoleColl); ExitOnFailure(hr, "Failed to get catalog collection"); hr = S_OK; LExit: // clean up ReleaseObject(piRoleColl); ReleaseObject(piRoleObj); return hr; }
HRESULT CpiGetRolesCollection( LPCWSTR pwzPartID, LPCWSTR pwzAppID, ICatalogCollection** ppiRolesColl ) { HRESULT hr = S_OK; ICatalogCollection* piAppColl = NULL; ICatalogObject* piAppObj = NULL; // get applications collection hr = CpiGetApplicationsCollection(pwzPartID, &piAppColl); ExitOnFailure(hr, "Failed to get applications collection"); if (S_FALSE == hr) ExitFunction(); // applications collection not found, exit with hr = S_FALSE // find object hr = CpiFindCollectionObjectByStringKey(piAppColl, pwzAppID, &piAppObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // application not found, exit with hr = S_FALSE // get roles collection hr = CpiGetCatalogCollection(piAppColl, piAppObj, L"Roles", ppiRolesColl); ExitOnFailure(hr, "Failed to catalog collection"); hr = S_OK; LExit: // clean up ReleaseObject(piAppColl); ReleaseObject(piAppObj); return hr; }
HRESULT CpiGetApplicationsCollection( ICatalogCollection** ppiAppColl ) { HRESULT hr = S_OK; ICOMAdminCatalog* piCatalog = NULL; ICOMAdminCatalog2* piCatalog2 = NULL; ICatalogCollection* piPartColl = NULL; ICatalogObject* piPartObj = NULL; BSTR bstrGlobPartID = NULL; if (!gpiAppColl) { // get catalog hr = CpiGetAdminCatalog(&piCatalog); ExitOnFailure(hr, "Failed to get COM+ admin catalog"); // get ICOMAdminCatalog2 interface hr = piCatalog->QueryInterface(IID_ICOMAdminCatalog2, (void**)&piCatalog2); // COM+ 1.5 or later if (E_NOINTERFACE != hr) { ExitOnFailure(hr, "Failed to get IID_ICOMAdminCatalog2 interface"); // get global partition id hr = piCatalog2->get_GlobalPartitionID(&bstrGlobPartID); ExitOnFailure(hr, "Failed to get global partition id"); // get partitions collection hr = CpiGetPartitionsCollection(&piPartColl); ExitOnFailure(hr, "Failed to get partitions collection"); // find object hr = CpiFindCollectionObject(piPartColl, bstrGlobPartID, NULL, &piPartObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // partition not found, exit with hr = S_FALSE // get applications collection hr = CpiGetCatalogCollection(piPartColl, piPartObj, L"Applications", &gpiAppColl); ExitOnFailure(hr, "Failed to get applications collection"); } // COM+ pre 1.5 else { // get applications collection hr = CpiGetCatalogCollection(L"Applications", &gpiAppColl); ExitOnFailure(hr, "Failed to get applications collection"); } } // return value gpiAppColl->AddRef(); *ppiAppColl = gpiAppColl; hr = S_OK; LExit: // clean up ReleaseObject(piCatalog); ReleaseObject(piCatalog2); ReleaseObject(piPartColl); ReleaseObject(piPartObj); ReleaseBSTR(bstrGlobPartID); return hr; }
HRESULT CpiLogCatalogErrorInfo() { HRESULT hr = S_OK; ICOMAdminCatalog* piCatalog = NULL; ICatalogCollection* piErrColl = NULL; IDispatch* piDisp = NULL; ICatalogObject* piObj = NULL; LPWSTR pwzName = NULL; LPWSTR pwzErrorCode = NULL; LPWSTR pwzMajorRef = NULL; LPWSTR pwzMinorRef = NULL; // get catalog hr = CpiGetAdminCatalog(&piCatalog); ExitOnFailure(hr, "Failed to get COM+ admin catalog"); // get error info collection hr = CpiGetCatalogCollection(L"ErrorInfo", &piErrColl); ExitOnFailure(hr, "Failed to get error info collection"); // loop objects long lCnt; hr = piErrColl->get_Count(&lCnt); ExitOnFailure(hr, "Failed to get to number of items in collection"); for (long i = 0; i < lCnt; i++) { // get ICatalogObject interface hr = piErrColl->get_Item(i, &piDisp); ExitOnFailure(hr, "Failed to get item from partitions collection"); hr = piDisp->QueryInterface(IID_ICatalogObject, (void**)&piObj); ExitOnFailure(hr, "Failed to get IID_ICatalogObject interface"); // get properties hr = CpiGetCollectionObjectValue(piObj, L"Name", &pwzName); ExitOnFailure(hr, "Failed to get name"); hr = CpiGetCollectionObjectValue(piObj, L"ErrorCode", &pwzErrorCode); ExitOnFailure(hr, "Failed to get error code"); hr = CpiGetCollectionObjectValue(piObj, L"MajorRef", &pwzMajorRef); ExitOnFailure(hr, "Failed to get major ref"); hr = CpiGetCollectionObjectValue(piObj, L"MinorRef", &pwzMinorRef); ExitOnFailure(hr, "Failed to get minor ref"); // write to log WcaLog(LOGMSG_STANDARD, "ErrorInfo: Name='%S', ErrorCode='%S', MajorRef='%S', MinorRef='%S'", pwzName, pwzErrorCode, pwzMajorRef, pwzMinorRef); // clean up ReleaseNullObject(piDisp); ReleaseNullObject(piObj); } hr = S_OK; LExit: // clean up ReleaseObject(piCatalog); ReleaseObject(piErrColl); ReleaseObject(piDisp); ReleaseObject(piObj); ReleaseStr(pwzName); ReleaseStr(pwzErrorCode); ReleaseStr(pwzMajorRef); ReleaseStr(pwzMinorRef); return hr; }
HRESULT CpiGetApplicationsCollection( LPCWSTR pwzPartID, ICatalogCollection** ppiAppColl ) { HRESULT hr = S_OK; ICOMAdminCatalog* piCatalog = NULL; ICOMAdminCatalog2* piCatalog2 = NULL; BSTR bstrGlobPartID = NULL; ICatalogCollection* piPartColl = NULL; ICatalogObject* piPartObj = NULL; // get catalog hr = CpiGetAdminCatalog(&piCatalog); ExitOnFailure(hr, "Failed to get COM+ admin catalog"); // get ICOMAdminCatalog2 interface hr = piCatalog->QueryInterface(IID_ICOMAdminCatalog2, (void**)&piCatalog2); // COM+ 1.5 or later if (E_NOINTERFACE != hr) { ExitOnFailure(hr, "Failed to get IID_ICOMAdminCatalog2 interface"); // partition id if (!pwzPartID || !*pwzPartID) { // get global partition id hr = piCatalog2->get_GlobalPartitionID(&bstrGlobPartID); ExitOnFailure(hr, "Failed to get global partition id"); } // get partitions collection hr = CpiGetPartitionsCollection(&piPartColl); ExitOnFailure(hr, "Failed to get partitions collection"); // find object hr = CpiFindCollectionObjectByStringKey(piPartColl, bstrGlobPartID ? bstrGlobPartID : pwzPartID, &piPartObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // partition not found, exit with hr = S_FALSE // get applications collection hr = CpiGetCatalogCollection(piPartColl, piPartObj, L"Applications", ppiAppColl); ExitOnFailure(hr, "Failed to get catalog collection for partition"); } // COM+ pre 1.5 else { // this version of COM+ does not support partitions, make sure a partition was not specified if (pwzPartID && *pwzPartID) ExitOnFailure(hr = E_FAIL, "Partitions are not supported by this version of COM+"); // get applications collection hr = CpiGetCatalogCollection(L"Applications", ppiAppColl); ExitOnFailure(hr, "Failed to get catalog collection"); } hr = S_OK; LExit: // clean up ReleaseObject(piCatalog); ReleaseObject(piCatalog2); ReleaseBSTR(bstrGlobPartID); ReleaseObject(piPartColl); ReleaseObject(piPartObj); return hr; }