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.

317 lines
7.6 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. BOOL bIsInherit);
  41. };
  42. class CAdminACL
  43. {
  44. friend class CAssocACLACE;
  45. private:
  46. IADs* m_pADs;
  47. IADsSecurityDescriptor* m_pSD;
  48. IADsAccessControlList* m_pDACL;
  49. BOOL bIsInherit;
  50. //
  51. // Indicate all ACEs we enum to WMI.
  52. //
  53. class CACEEnumOperation_IndicateAll : public CACEEnumOperation_Base
  54. {
  55. public:
  56. CACEEnumOperation_IndicateAll(
  57. BSTR i_bstrNameValue,
  58. CWbemServices& i_refNamespace,
  59. IWbemObjectSink& i_refWbemObjectSink,
  60. BOOL bArgIsInherit)
  61. {
  62. m_vNameValue.bstrVal = i_bstrNameValue;
  63. m_vNameValue.vt = VT_BSTR;
  64. m_pNamespace = &i_refNamespace;
  65. m_pWbemObjectSink = &i_refWbemObjectSink;
  66. m_hr = WBEM_S_NO_ERROR;
  67. bLocalIsInherit = bArgIsInherit;
  68. m_hr = m_pNamespace->GetObject(
  69. WMI_CLASS_DATA::s_ACE.pszClassName,
  70. 0,
  71. NULL,
  72. &m_spClass,
  73. NULL);
  74. if(FAILED(m_hr))
  75. {
  76. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", m_hr));
  77. return;
  78. }
  79. }
  80. virtual HRESULT Do(
  81. IADsAccessControlEntry* pACE);
  82. virtual eDone Done() { return eDONE_DONT_KNOW; }
  83. private:
  84. CWbemServices* m_pNamespace;
  85. IWbemObjectSink* m_pWbemObjectSink;
  86. VARIANT m_vNameValue;
  87. BOOL bLocalIsInherit;
  88. HRESULT m_hr;
  89. CComPtr<IWbemClassObject> m_spClass;
  90. };
  91. //
  92. // Find the matching ACE.
  93. //
  94. class CACEEnumOperation_Find : public CACEEnumOperation_Base
  95. {
  96. public:
  97. CACEEnumOperation_Find(
  98. CAdminACL* pAdminACL,
  99. BSTR bstrTrustee)
  100. {
  101. DBG_ASSERT(pAdminACL);
  102. DBG_ASSERT(bstrTrustee);
  103. m_pAdminACL = pAdminACL;
  104. m_bstrTrustee = bstrTrustee;
  105. m_eDone = eDONE_NO;
  106. }
  107. virtual HRESULT Do(
  108. IADsAccessControlEntry* pACE);
  109. virtual eDone Done() { return m_eDone; }
  110. protected:
  111. eDone m_eDone;
  112. CAdminACL* m_pAdminACL;
  113. BSTR m_bstrTrustee;
  114. virtual HRESULT DoOnMatch(
  115. IADsAccessControlEntry* pACE) = 0;
  116. };
  117. //
  118. // Find and return the matching ACE.
  119. //
  120. class CACEEnumOperation_FindAndReturn : public CACEEnumOperation_Find
  121. {
  122. public:
  123. CACEEnumOperation_FindAndReturn(
  124. CAdminACL* pAdminACL,
  125. IWbemClassObject* pObj,
  126. BSTR bstrTrustee,
  127. BOOL bArgIsInherit) :
  128. CACEEnumOperation_Find(pAdminACL, bstrTrustee)
  129. {
  130. DBG_ASSERT(pObj);
  131. m_spObj = pObj;
  132. bLocalIsInherit = bArgIsInherit;
  133. }
  134. protected:
  135. virtual HRESULT DoOnMatch(
  136. IADsAccessControlEntry* pACE)
  137. {
  138. DBG_ASSERT(pACE);
  139. return PopulateWmiACE(m_spObj, pACE, bLocalIsInherit);
  140. }
  141. private:
  142. CComPtr<IWbemClassObject> m_spObj;
  143. BOOL bLocalIsInherit;
  144. };
  145. //
  146. // Find and update the matching ACE.
  147. //
  148. class CACEEnumOperation_FindAndUpdate : public CACEEnumOperation_Find
  149. {
  150. public:
  151. CACEEnumOperation_FindAndUpdate(
  152. CAdminACL* pAdminACL,
  153. IWbemClassObject* pObj,
  154. BSTR bstrTrustee) :
  155. CACEEnumOperation_Find(pAdminACL, bstrTrustee)
  156. {
  157. DBG_ASSERT(pObj);
  158. m_spObj = pObj;
  159. }
  160. protected:
  161. virtual HRESULT DoOnMatch(
  162. IADsAccessControlEntry* pACE)
  163. {
  164. DBG_ASSERT(pACE);
  165. return m_pAdminACL->SetDataOfACE(m_spObj, pACE);
  166. }
  167. private:
  168. CComPtr<IWbemClassObject> m_spObj;
  169. };
  170. //
  171. // Find and remove the matching ACE.
  172. //
  173. class CACEEnumOperation_FindAndRemove : public CACEEnumOperation_Find
  174. {
  175. public:
  176. CACEEnumOperation_FindAndRemove(
  177. CAdminACL* pAdminACL,
  178. BSTR bstrTrustee) :
  179. CACEEnumOperation_Find(pAdminACL, bstrTrustee)
  180. {
  181. }
  182. protected:
  183. virtual HRESULT DoOnMatch(
  184. IADsAccessControlEntry* pACE)
  185. {
  186. DBG_ASSERT(pACE);
  187. CComPtr<IDispatch> spDisp;
  188. HRESULT hr = pACE->QueryInterface(IID_IDispatch,(void**)&spDisp);
  189. if(FAILED(hr))
  190. {
  191. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  192. return hr;
  193. }
  194. hr = m_pAdminACL->m_pDACL->RemoveAce(spDisp);
  195. if(FAILED(hr))
  196. {
  197. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  198. return hr;
  199. }
  200. return hr;
  201. }
  202. };
  203. public:
  204. CAdminACL();
  205. ~CAdminACL();
  206. HRESULT GetObjectAsync(
  207. IWbemClassObject* pObj,
  208. ParsedObjectPath* pParsedObject,
  209. WMI_CLASS* pWMIClass
  210. );
  211. HRESULT PutObjectAsync(
  212. IWbemClassObject* pObj,
  213. ParsedObjectPath* pParsedObject,
  214. WMI_CLASS* pWMIClass
  215. );
  216. HRESULT EnumerateACEsAndIndicate(
  217. BSTR i_bstrNameValue,
  218. CWbemServices& i_refNamespace,
  219. IWbemObjectSink& i_refWbemObjectSink);
  220. HRESULT DeleteObjectAsync(ParsedObjectPath* pParsedObject);
  221. HRESULT OpenSD(
  222. LPCWSTR wszMbPath,
  223. IMSAdminBase2* pAdminBase);
  224. void CloseSD();
  225. HRESULT GetACEEnum(IEnumVARIANT** pEnum);
  226. private:
  227. HRESULT SetSD();
  228. HRESULT CAdminACL::GetAdsPath(
  229. LPCWSTR i_wszMbPath,
  230. BSTR* o_pbstrAdsPath);
  231. //
  232. // ACL stuff
  233. //
  234. HRESULT PopulateWmiAdminACL(IWbemClassObject* pObj);
  235. HRESULT SetADSIAdminACL(
  236. IWbemClassObject* pObj);
  237. //
  238. // ACE stuff
  239. //
  240. HRESULT EnumACEsAndOp(
  241. CACEEnumOperation_Base& refOp);
  242. void GetTrustee(
  243. IWbemClassObject* pObj,
  244. ParsedObjectPath* pPath,
  245. _bstr_t& bstrTrustee);
  246. HRESULT AddACE(
  247. IWbemClassObject* pObj,
  248. _bstr_t& bstrTrustee);
  249. HRESULT NewACE(
  250. IWbemClassObject* pObj,
  251. _bstr_t& bstrTrustee,
  252. IADsAccessControlEntry** ppACE);
  253. HRESULT SetDataOfACE(
  254. IWbemClassObject* pObj,
  255. IADsAccessControlEntry* pACE);
  256. };
  257. #endif