Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. AssocACLACE.cpp
  5. Abstract:
  6. Implementation of:
  7. CAssocACLACE
  8. Author:
  9. Mohit Srivastava 22-Mar-2001
  10. Revision History:
  11. --*/
  12. #include <dbgutil.h>
  13. #include <atlbase.h>
  14. #include "AssocACLACE.h"
  15. #include "utils.h"
  16. #include "SmartPointer.h"
  17. CAssocACLACE::CAssocACLACE(
  18. CWbemServices* i_pNamespace,
  19. IWbemObjectSink* i_pResponseHandler) :
  20. CAssocBase(i_pNamespace, i_pResponseHandler, &WMI_ASSOCIATION_DATA::s_AdminACLToACE)
  21. {
  22. }
  23. void CAssocACLACE::GetInstances(
  24. SQL_LEVEL_1_RPN_EXPRESSION_EXT* i_pExp) //defaultvalue(NULL)
  25. {
  26. DBG_ASSERT(m_pNamespace);
  27. DBG_ASSERT(i_pExp);
  28. SQL_LEVEL_1_TOKEN* pTokenACL = NULL; // left part of assoc
  29. SQL_LEVEL_1_TOKEN* pTokenACE = NULL; // right part of assoc
  30. //
  31. // Walk thru tokens
  32. // Don't do query if we find OR or NOT
  33. // Record match for left and/or right part of association.
  34. //
  35. bool bDoQuery = true;
  36. ProcessQuery(
  37. i_pExp,
  38. m_pWmiAssoc,
  39. &pTokenACL, // points to i_pExp, does not need to be cleaned up
  40. &pTokenACE, // points to i_pExp, does not need to be cleaned up
  41. &bDoQuery);
  42. if( !bDoQuery || (pTokenACL == NULL && pTokenACE == NULL))
  43. {
  44. GetAllInstances(m_pWmiAssoc);
  45. return;
  46. }
  47. //
  48. // We need to get just a single association instance. If we were provided
  49. // at least a ACL or a ACE part, we have enough information.
  50. //
  51. DBG_ASSERT(pTokenACL != NULL || pTokenACE != NULL);
  52. if(pTokenACL && pTokenACE)
  53. {
  54. Indicate(pTokenACL->vConstValue.bstrVal, pTokenACE->vConstValue.bstrVal);
  55. }
  56. else if(pTokenACE)
  57. {
  58. _bstr_t sbstrPath;
  59. TSmartPointer<ParsedObjectPath> spParsedACLObjPath = NULL;
  60. if (m_PathParser.Parse(pTokenACE->vConstValue.bstrVal, &spParsedACLObjPath)
  61. != CObjectPathParser::NoError)
  62. {
  63. THROW_ON_ERROR(WBEM_E_INVALID_QUERY);
  64. }
  65. KeyRef* pkr = CUtils::GetKey(
  66. spParsedACLObjPath,
  67. m_pWmiAssoc->pcRight->pszKeyName);
  68. sbstrPath = pkr->m_vValue.bstrVal;
  69. //
  70. // Make the ACL Object Path
  71. //
  72. BOOL bRet = true;
  73. bRet = spParsedACLObjPath->SetClassName(
  74. m_pWmiAssoc->pcLeft->pszClassName);
  75. THROW_ON_FALSE(bRet);
  76. VARIANT vtPath;
  77. vtPath.vt = VT_BSTR;
  78. vtPath.bstrVal = sbstrPath;
  79. spParsedACLObjPath->ClearKeys();
  80. bRet = spParsedACLObjPath->AddKeyRef(
  81. m_pWmiAssoc->pcLeft->pszKeyName,
  82. &vtPath);
  83. THROW_ON_FALSE(bRet);
  84. Indicate(spParsedACLObjPath, pTokenACE->vConstValue.bstrVal);
  85. }
  86. else
  87. {
  88. //
  89. // pTokenACL && !pTokenACE
  90. //
  91. CComBSTR sbstr;
  92. TSmartPointer<ParsedObjectPath> spParsedACEObjPath = NULL;
  93. if (m_PathParser.Parse(pTokenACL->vConstValue.bstrVal, &spParsedACEObjPath)
  94. != CObjectPathParser::NoError)
  95. {
  96. THROW_ON_ERROR(WBEM_E_INVALID_QUERY);
  97. }
  98. //
  99. // Start with the ACL part of the association. Convert it to an ACE part.
  100. //
  101. if(!spParsedACEObjPath->SetClassName(m_pWmiAssoc->pcRight->pszClassName))
  102. {
  103. THROW_ON_ERROR(WBEM_E_FAILED);
  104. }
  105. sbstr = m_pWmiAssoc->pcLeft->pszMetabaseKey;
  106. sbstr += L"/";
  107. KeyRef* pkr = CUtils::GetKey(
  108. spParsedACEObjPath,
  109. m_pWmiAssoc->pcLeft->pszKeyName);
  110. DBG_ASSERT(pkr);
  111. sbstr += pkr->m_vValue.bstrVal;
  112. if(sbstr.m_str == NULL)
  113. {
  114. THROW_ON_ERROR(WBEM_E_OUT_OF_MEMORY);
  115. }
  116. //
  117. // CloseSD called automatically
  118. //
  119. CAdminACL AdminAcl;
  120. HRESULT hr = AdminAcl.OpenSD(sbstr);
  121. THROW_ON_ERROR(hr);
  122. CACEEnumOperation_IndicateAllAsAssoc op(
  123. this,
  124. pTokenACL->vConstValue.bstrVal,
  125. spParsedACEObjPath);
  126. hr = AdminAcl.EnumACEsAndOp(/*ref*/ op);
  127. THROW_ON_ERROR(hr);
  128. }
  129. }
  130. HRESULT CAssocACLACE::CACEEnumOperation_IndicateAllAsAssoc::Do(
  131. IADsAccessControlEntry* pACE)
  132. {
  133. DBG_ASSERT(pACE);
  134. CComBSTR sbstrTrustee;
  135. HRESULT hr = pACE->get_Trustee(&sbstrTrustee);
  136. if(FAILED(hr))
  137. {
  138. return hr;
  139. }
  140. //
  141. // add keyref
  142. //
  143. VARIANT vTrustee;
  144. vTrustee.bstrVal = sbstrTrustee;
  145. vTrustee.vt = VT_BSTR;
  146. THROW_ON_FALSE(m_pParsedACEObjPath->AddKeyRefEx(L"Trustee",&vTrustee));
  147. m_pAssocACLACE->Indicate(m_bstrACLObjPath, m_pParsedACEObjPath);
  148. return hr;
  149. }