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.

309 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. adminacl.h
  5. Abstract:
  6. Contains definition of CAdminACL
  7. Author:
  8. ???
  9. Revision History:
  10. Mohit Srivastava 18-Dec-00
  11. --*/
  12. #ifndef _adminacl_h_
  13. #define _adminacl_h_
  14. #include <iads.h>
  15. #include <adshlp.h>
  16. #include <atlbase.h>
  17. #include <comutil.h>
  18. #include <dbgutil.h>
  19. //
  20. // A parameter to the GetACE function. As we enumerate the ACEs,
  21. // we call IACEEnumOperation::Do.
  22. // Then, we call Done to see whether to continue enumeration.
  23. //
  24. class CACEEnumOperation_Base
  25. {
  26. public:
  27. enum eDone
  28. {
  29. eDONE_YES,
  30. eDONE_NO,
  31. eDONE_DONT_KNOW
  32. };
  33. virtual HRESULT Do(
  34. IADsAccessControlEntry* pACE) = 0;
  35. virtual eDone Done() = 0;
  36. protected:
  37. HRESULT PopulateWmiACE(
  38. IWbemClassObject* pObj,
  39. IADsAccessControlEntry* pACE);
  40. };
  41. class CAdminACL
  42. {
  43. friend class CAssocACLACE;
  44. private:
  45. IADs* m_pADs;
  46. IADsSecurityDescriptor* m_pSD;
  47. IADsAccessControlList* m_pDACL;
  48. //
  49. // Indicate all ACEs we enum to WMI.
  50. //
  51. class CACEEnumOperation_IndicateAll : public CACEEnumOperation_Base
  52. {
  53. public:
  54. CACEEnumOperation_IndicateAll(
  55. BSTR i_bstrNameValue,
  56. CWbemServices& i_refNamespace,
  57. IWbemObjectSink& i_refWbemObjectSink)
  58. {
  59. m_vNameValue.bstrVal = i_bstrNameValue;
  60. m_vNameValue.vt = VT_BSTR;
  61. m_pNamespace = &i_refNamespace;
  62. m_pWbemObjectSink = &i_refWbemObjectSink;
  63. m_hr = WBEM_S_NO_ERROR;
  64. m_hr = m_pNamespace->GetObject(
  65. WMI_CLASS_DATA::s_ACE.pszClassName,
  66. 0,
  67. NULL,
  68. &m_spClass,
  69. NULL);
  70. if(FAILED(m_hr))
  71. {
  72. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", m_hr));
  73. return;
  74. }
  75. }
  76. virtual HRESULT Do(
  77. IADsAccessControlEntry* pACE);
  78. virtual eDone Done() { return eDONE_DONT_KNOW; }
  79. private:
  80. CWbemServices* m_pNamespace;
  81. IWbemObjectSink* m_pWbemObjectSink;
  82. VARIANT m_vNameValue;
  83. HRESULT m_hr;
  84. CComPtr<IWbemClassObject> m_spClass;
  85. };
  86. //
  87. // Find the matching ACE.
  88. //
  89. class CACEEnumOperation_Find : public CACEEnumOperation_Base
  90. {
  91. public:
  92. CACEEnumOperation_Find(
  93. CAdminACL* pAdminACL,
  94. BSTR bstrTrustee)
  95. {
  96. DBG_ASSERT(pAdminACL);
  97. DBG_ASSERT(bstrTrustee);
  98. m_pAdminACL = pAdminACL;
  99. m_bstrTrustee = bstrTrustee;
  100. m_eDone = eDONE_NO;
  101. }
  102. virtual HRESULT Do(
  103. IADsAccessControlEntry* pACE);
  104. virtual eDone Done() { return m_eDone; }
  105. protected:
  106. eDone m_eDone;
  107. CAdminACL* m_pAdminACL;
  108. BSTR m_bstrTrustee;
  109. virtual HRESULT DoOnMatch(
  110. IADsAccessControlEntry* pACE) = 0;
  111. };
  112. //
  113. // Find and return the matching ACE.
  114. //
  115. class CACEEnumOperation_FindAndReturn : public CACEEnumOperation_Find
  116. {
  117. public:
  118. CACEEnumOperation_FindAndReturn(
  119. CAdminACL* pAdminACL,
  120. IWbemClassObject* pObj,
  121. BSTR bstrTrustee) :
  122. CACEEnumOperation_Find(pAdminACL, bstrTrustee)
  123. {
  124. DBG_ASSERT(pObj);
  125. m_spObj = pObj;
  126. }
  127. protected:
  128. virtual HRESULT DoOnMatch(
  129. IADsAccessControlEntry* pACE)
  130. {
  131. DBG_ASSERT(pACE);
  132. return PopulateWmiACE(m_spObj, pACE);
  133. }
  134. private:
  135. CComPtr<IWbemClassObject> m_spObj;
  136. };
  137. //
  138. // Find and update the matching ACE.
  139. //
  140. class CACEEnumOperation_FindAndUpdate : public CACEEnumOperation_Find
  141. {
  142. public:
  143. CACEEnumOperation_FindAndUpdate(
  144. CAdminACL* pAdminACL,
  145. IWbemClassObject* pObj,
  146. BSTR bstrTrustee) :
  147. CACEEnumOperation_Find(pAdminACL, bstrTrustee)
  148. {
  149. DBG_ASSERT(pObj);
  150. m_spObj = pObj;
  151. }
  152. protected:
  153. virtual HRESULT DoOnMatch(
  154. IADsAccessControlEntry* pACE)
  155. {
  156. DBG_ASSERT(pACE);
  157. return m_pAdminACL->SetDataOfACE(m_spObj, pACE);
  158. }
  159. private:
  160. CComPtr<IWbemClassObject> m_spObj;
  161. };
  162. //
  163. // Find and remove the matching ACE.
  164. //
  165. class CACEEnumOperation_FindAndRemove : public CACEEnumOperation_Find
  166. {
  167. public:
  168. CACEEnumOperation_FindAndRemove(
  169. CAdminACL* pAdminACL,
  170. BSTR bstrTrustee) :
  171. CACEEnumOperation_Find(pAdminACL, bstrTrustee)
  172. {
  173. }
  174. protected:
  175. virtual HRESULT DoOnMatch(
  176. IADsAccessControlEntry* pACE)
  177. {
  178. DBG_ASSERT(pACE);
  179. CComPtr<IDispatch> spDisp;
  180. HRESULT hr = pACE->QueryInterface(IID_IDispatch,(void**)&spDisp);
  181. if(FAILED(hr))
  182. {
  183. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  184. return hr;
  185. }
  186. hr = m_pAdminACL->m_pDACL->RemoveAce(spDisp);
  187. if(FAILED(hr))
  188. {
  189. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  190. return hr;
  191. }
  192. return hr;
  193. }
  194. };
  195. public:
  196. CAdminACL();
  197. ~CAdminACL();
  198. HRESULT GetObjectAsync(
  199. IWbemClassObject* pObj,
  200. ParsedObjectPath* pParsedObject,
  201. WMI_CLASS* pWMIClass
  202. );
  203. HRESULT PutObjectAsync(
  204. IWbemClassObject* pObj,
  205. ParsedObjectPath* pParsedObject,
  206. WMI_CLASS* pWMIClass
  207. );
  208. HRESULT EnumerateACEsAndIndicate(
  209. BSTR i_bstrNameValue,
  210. CWbemServices& i_refNamespace,
  211. IWbemObjectSink& i_refWbemObjectSink);
  212. HRESULT DeleteObjectAsync(ParsedObjectPath* pParsedObject);
  213. HRESULT OpenSD(
  214. LPCWSTR wszMbPath);
  215. void CloseSD();
  216. HRESULT GetACEEnum(IEnumVARIANT** pEnum);
  217. private:
  218. HRESULT SetSD();
  219. HRESULT CAdminACL::GetAdsPath(
  220. LPCWSTR i_wszMbPath,
  221. BSTR* o_pbstrAdsPath);
  222. //
  223. // ACL stuff
  224. //
  225. HRESULT PopulateWmiAdminACL(IWbemClassObject* pObj);
  226. HRESULT SetADSIAdminACL(
  227. IWbemClassObject* pObj);
  228. //
  229. // ACE stuff
  230. //
  231. HRESULT EnumACEsAndOp(
  232. CACEEnumOperation_Base& refOp);
  233. void GetTrustee(
  234. IWbemClassObject* pObj,
  235. ParsedObjectPath* pPath,
  236. _bstr_t& bstrTrustee);
  237. HRESULT AddACE(
  238. IWbemClassObject* pObj,
  239. _bstr_t& bstrTrustee);
  240. HRESULT NewACE(
  241. IWbemClassObject* pObj,
  242. _bstr_t& bstrTrustee,
  243. IADsAccessControlEntry** ppACE);
  244. HRESULT SetDataOfACE(
  245. IWbemClassObject* pObj,
  246. IADsAccessControlEntry* pACE);
  247. };
  248. #endif