Leaked source code of windows server 2003
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.

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