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.

571 lines
16 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. AccessControlEntry.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHAccessControlEntry class,
  7. which is used to represent an access control entry.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 03/22/2000
  10. created
  11. ******************************************************************************/
  12. #include "StdAfx.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //
  15. // AccessControlEntry [@AccessMask
  16. // @AceFlags
  17. // @AceType
  18. // @Flags]
  19. //
  20. // Trustee
  21. // ObjectType
  22. // InheritedOjectType
  23. //
  24. ////////////////////////////////////////////////////////////////////////////////
  25. static const CComBSTR s_TAG_ACE ( L"AccessControlEntry" );
  26. static const CComBSTR s_ATTR_ACE_AccessMask ( L"AccessMask" );
  27. static const CComBSTR s_ATTR_ACE_AceFlags ( L"AceFlags" );
  28. static const CComBSTR s_ATTR_ACE_AceType ( L"AceType" );
  29. static const CComBSTR s_ATTR_ACE_Flags ( L"Flags" );
  30. static const CComBSTR s_TAG_Trustee ( L"Trustee" );
  31. static const CComBSTR s_TAG_ObjectType ( L"ObjectType" );
  32. static const CComBSTR s_TAG_InheritedObjectType( L"InheritedObjectType" );
  33. ////////////////////////////////////////////////////////////////////////////////
  34. CPCHAccessControlEntry::CPCHAccessControlEntry()
  35. {
  36. m_dwAccessMask = 0; // DWORD m_dwAccessMask;
  37. m_dwAceFlags = 0; // DWORD m_dwAceFlags;
  38. m_dwAceType = 0; // DWORD m_dwAceType;
  39. m_dwFlags = 0; // DWORD m_dwFlags;
  40. //
  41. // CComBSTR m_bstrTrustee;
  42. // CComBSTR m_bstrObjectType;
  43. // CComBSTR m_bstrInheritedObjectType;
  44. }
  45. CPCHAccessControlEntry::~CPCHAccessControlEntry()
  46. {
  47. }
  48. ////////////////////////////////////////////////////////////////////////////////
  49. STDMETHODIMP CPCHAccessControlEntry::get_AccessMask( /*[out, retval]*/ long *pVal )
  50. {
  51. __HCP_BEGIN_PROPERTY_GET("CPCHAccessControlEntry::get_AccessMask",hr,pVal);
  52. *pVal = m_dwAccessMask;
  53. __HCP_END_PROPERTY(hr);
  54. }
  55. STDMETHODIMP CPCHAccessControlEntry::put_AccessMask( /*[in]*/ long newVal )
  56. {
  57. __HCP_BEGIN_PROPERTY_PUT("CPCHAccessControlEntry::put_AccessMask",hr);
  58. m_dwAccessMask = newVal;
  59. __HCP_END_PROPERTY(hr);
  60. }
  61. ////////////////////
  62. STDMETHODIMP CPCHAccessControlEntry::get_AceType( /*[out, retval]*/ long *pVal )
  63. {
  64. __HCP_BEGIN_PROPERTY_GET("CPCHAccessControlEntry::get_AceType",hr,pVal);
  65. *pVal = m_dwAceType;
  66. __HCP_END_PROPERTY(hr);
  67. }
  68. STDMETHODIMP CPCHAccessControlEntry::put_AceType( /*[in]*/ long newVal )
  69. {
  70. __HCP_BEGIN_PROPERTY_PUT("CPCHAccessControlEntry::put_AceType",hr);
  71. m_dwAceType = newVal;
  72. __HCP_END_PROPERTY(hr);
  73. }
  74. ////////////////////
  75. STDMETHODIMP CPCHAccessControlEntry::get_AceFlags( /*[out, retval]*/ long *pVal )
  76. {
  77. __HCP_BEGIN_PROPERTY_GET("CPCHAccessControlEntry::get_AceFlags",hr,pVal);
  78. *pVal = m_dwAceFlags;
  79. __HCP_END_PROPERTY(hr);
  80. }
  81. STDMETHODIMP CPCHAccessControlEntry::put_AceFlags( /*[in]*/ long newVal )
  82. {
  83. __HCP_BEGIN_PROPERTY_PUT("CPCHAccessControlEntry::put_AceFlags",hr);
  84. m_dwAceFlags = newVal;
  85. __HCP_END_PROPERTY(hr);
  86. }
  87. ////////////////////
  88. STDMETHODIMP CPCHAccessControlEntry::get_Flags( /*[out, retval]*/ long *pVal )
  89. {
  90. __HCP_BEGIN_PROPERTY_GET("CPCHAccessControlEntry::get_Flags",hr,pVal);
  91. *pVal = m_dwFlags;
  92. __HCP_END_PROPERTY(hr);
  93. }
  94. STDMETHODIMP CPCHAccessControlEntry::put_Flags( /*[in]*/ long newVal )
  95. {
  96. __HCP_BEGIN_PROPERTY_PUT("CPCHAccessControlEntry::put_Flags",hr);
  97. m_dwFlags = newVal;
  98. __HCP_END_PROPERTY(hr);
  99. }
  100. ////////////////////
  101. STDMETHODIMP CPCHAccessControlEntry::get_Trustee( /*[out, retval]*/ BSTR *pVal )
  102. {
  103. __HCP_BEGIN_PROPERTY_GET("CPCHAccessControlEntry::get_Trustee",hr,pVal);
  104. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrTrustee, pVal ));
  105. __HCP_END_PROPERTY(hr);
  106. }
  107. STDMETHODIMP CPCHAccessControlEntry::put_Trustee( /*[in]*/ BSTR newVal )
  108. {
  109. __HCP_BEGIN_PROPERTY_PUT("CPCHAccessControlEntry::put_Trustee",hr);
  110. if(newVal)
  111. {
  112. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptorDirect::VerifyPrincipal( newVal ));
  113. }
  114. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::PutBSTR( m_bstrTrustee, newVal, false ));
  115. __HCP_END_PROPERTY(hr);
  116. }
  117. ////////////////////
  118. STDMETHODIMP CPCHAccessControlEntry::get_ObjectType( /*[out, retval]*/ BSTR *pVal )
  119. {
  120. __HCP_BEGIN_PROPERTY_GET("CPCHAccessControlEntry::get_ObjectType",hr,pVal);
  121. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrObjectType, pVal ));
  122. __HCP_END_PROPERTY(hr);
  123. }
  124. STDMETHODIMP CPCHAccessControlEntry::put_ObjectType( /*[in]*/ BSTR newVal )
  125. {
  126. __HCP_BEGIN_PROPERTY_PUT("CPCHAccessControlEntry::put_ObjectType",hr);
  127. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::PutBSTR( m_bstrObjectType, newVal ));
  128. __HCP_END_PROPERTY(hr);
  129. }
  130. ////////////////////
  131. STDMETHODIMP CPCHAccessControlEntry::get_InheritedObjectType( /*[out, retval]*/ BSTR *pVal )
  132. {
  133. __HCP_BEGIN_PROPERTY_GET("CPCHAccessControlEntry::get_InheritedObjectType",hr,pVal);
  134. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrInheritedObjectType, pVal ));
  135. __HCP_END_PROPERTY(hr);
  136. }
  137. STDMETHODIMP CPCHAccessControlEntry::put_InheritedObjectType( /*[in]*/ BSTR newVal )
  138. {
  139. __HCP_BEGIN_PROPERTY_PUT("CPCHAccessControlEntry::put_InheritedObjectType",hr);
  140. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::PutBSTR( m_bstrInheritedObjectType, newVal ));
  141. __HCP_END_PROPERTY(hr);
  142. }
  143. ////////////////////////////////////////////////////////////////////////////////
  144. STDMETHODIMP CPCHAccessControlEntry::IsEquivalent( /*[in ]*/ IPCHAccessControlEntry* pAce ,
  145. /*[out, retval]*/ VARIANT_BOOL *pVal )
  146. {
  147. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::IsEquivalent" );
  148. HRESULT hr;
  149. long lAccessMask;
  150. long lAceFlags;
  151. long lAceType;
  152. long lFlags;
  153. CComBSTR bstrTrustee;
  154. CComBSTR bstrObjectType;
  155. CComBSTR bstrInheritedObjectType;
  156. __MPC_PARAMCHECK_BEGIN(hr)
  157. __MPC_PARAMCHECK_NOTNULL(pAce);
  158. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,VARIANT_FALSE);
  159. __MPC_PARAMCHECK_END();
  160. __MPC_EXIT_IF_METHOD_FAILS(hr, pAce->get_AccessMask( &lAccessMask ));
  161. if(m_dwAccessMask != lAccessMask)
  162. {
  163. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  164. }
  165. __MPC_EXIT_IF_METHOD_FAILS(hr, pAce->get_AceFlags( &lAceFlags ));
  166. if(m_dwAceFlags != lAceFlags)
  167. {
  168. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  169. }
  170. __MPC_EXIT_IF_METHOD_FAILS(hr, pAce->get_AceType( &lAceType ));
  171. if(m_dwAceType != lAceType)
  172. {
  173. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  174. }
  175. __MPC_EXIT_IF_METHOD_FAILS(hr, pAce->get_Flags( &lFlags ));
  176. if(m_dwFlags != lFlags)
  177. {
  178. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  179. }
  180. __MPC_EXIT_IF_METHOD_FAILS(hr, pAce->get_Trustee( &bstrTrustee ));
  181. if(MPC::StrICmp( m_bstrTrustee, bstrTrustee ))
  182. {
  183. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  184. }
  185. __MPC_EXIT_IF_METHOD_FAILS(hr, pAce->get_ObjectType( &bstrObjectType ));
  186. if(MPC::StrICmp( m_bstrObjectType, bstrObjectType ))
  187. {
  188. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  189. }
  190. __MPC_EXIT_IF_METHOD_FAILS(hr, pAce->get_InheritedObjectType( &bstrInheritedObjectType ));
  191. if(MPC::StrICmp( m_bstrInheritedObjectType, bstrInheritedObjectType ))
  192. {
  193. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  194. }
  195. *pVal = VARIANT_TRUE;
  196. hr = S_OK;
  197. __HCP_FUNC_CLEANUP;
  198. __HCP_FUNC_EXIT(hr);
  199. }
  200. STDMETHODIMP CPCHAccessControlEntry::Clone( /*[out, retval]*/ IPCHAccessControlEntry* *pVal )
  201. {
  202. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::Clone" );
  203. HRESULT hr;
  204. MPC::SmartLock<_ThreadModel> lock( this );
  205. CComPtr<CPCHAccessControlEntry> pNew;
  206. CPCHAccessControlEntry* pPtr;
  207. __MPC_PARAMCHECK_BEGIN(hr)
  208. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  209. __MPC_PARAMCHECK_END();
  210. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pNew ));
  211. pPtr = pNew;
  212. pPtr->m_dwAccessMask = m_dwAccessMask;
  213. pPtr->m_dwAceFlags = m_dwAceFlags;
  214. pPtr->m_dwAceType = m_dwAceType;
  215. pPtr->m_dwFlags = m_dwFlags;
  216. pPtr->m_bstrTrustee = m_bstrTrustee;
  217. pPtr->m_bstrObjectType = m_bstrObjectType;
  218. pPtr->m_bstrInheritedObjectType = m_bstrInheritedObjectType;
  219. __MPC_EXIT_IF_METHOD_FAILS(hr, pNew.QueryInterface( pVal ));
  220. hr = S_OK;
  221. __HCP_FUNC_CLEANUP;
  222. __HCP_FUNC_EXIT(hr);
  223. }
  224. ////////////////////////////////////////////////////////////////////////////////
  225. HRESULT CPCHAccessControlEntry::LoadPost( /*[in]*/ MPC::XmlUtil& xml )
  226. {
  227. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::LoadPost" );
  228. HRESULT hr;
  229. MPC::SmartLock<_ThreadModel> lock( this );
  230. CComPtr<IXMLDOMNode> xdnNode;
  231. CComBSTR bstrValue;
  232. LONG lValue;
  233. bool fFound;
  234. //
  235. // Make sure we have something to parse....
  236. //
  237. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetRoot( &xdnNode )); xdnNode.Release();
  238. //
  239. // Clean up before loading.
  240. //
  241. m_dwAccessMask = 0;
  242. m_dwAceFlags = 0;
  243. m_dwAceType = 0;
  244. m_dwFlags = 0;
  245. m_bstrTrustee .Empty();
  246. m_bstrObjectType .Empty();
  247. m_bstrInheritedObjectType.Empty();
  248. //
  249. // Read attributes.
  250. //
  251. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_ACE_AccessMask, lValue, fFound )); if(fFound) m_dwAccessMask = lValue;
  252. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_ACE_AceFlags , lValue, fFound )); if(fFound) m_dwAceFlags = lValue;
  253. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_ACE_AceType , lValue, fFound )); if(fFound) m_dwAceType = lValue;
  254. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_ACE_Flags , lValue, fFound )); if(fFound) m_dwFlags = lValue;
  255. //
  256. // Read values.
  257. //
  258. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetValue( s_TAG_Trustee , bstrValue, fFound )); if(fFound) m_bstrTrustee .Attach( bstrValue.Detach() );
  259. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetValue( s_TAG_ObjectType , bstrValue, fFound )); if(fFound) m_bstrObjectType .Attach( bstrValue.Detach() );
  260. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetValue( s_TAG_InheritedObjectType, bstrValue, fFound )); if(fFound) m_bstrInheritedObjectType.Attach( bstrValue.Detach() );
  261. if(m_bstrTrustee.Length())
  262. {
  263. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptorDirect::VerifyPrincipal( m_bstrTrustee ));
  264. }
  265. hr = S_OK;
  266. __HCP_FUNC_CLEANUP;
  267. __HCP_FUNC_EXIT(hr);
  268. }
  269. STDMETHODIMP CPCHAccessControlEntry::LoadXML( /*[in]*/ IXMLDOMNode* xdnNode )
  270. {
  271. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::LoadXML" );
  272. HRESULT hr;
  273. MPC::XmlUtil xml( xdnNode );
  274. __MPC_PARAMCHECK_BEGIN(hr)
  275. __MPC_PARAMCHECK_NOTNULL(xdnNode);
  276. __MPC_PARAMCHECK_END();
  277. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadPost( xml ));
  278. hr = S_OK;
  279. __HCP_FUNC_CLEANUP;
  280. __HCP_FUNC_EXIT(hr);
  281. }
  282. STDMETHODIMP CPCHAccessControlEntry::LoadXMLAsString( /*[in]*/ BSTR bstrVal )
  283. {
  284. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::LoadXMLAsString" );
  285. HRESULT hr;
  286. MPC::XmlUtil xml;
  287. bool fLoaded;
  288. bool fFound;
  289. __MPC_PARAMCHECK_BEGIN(hr)
  290. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrVal);
  291. __MPC_PARAMCHECK_END();
  292. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.LoadAsString( bstrVal, s_TAG_ACE, fLoaded, &fFound ));
  293. if(fLoaded == false || fFound == false)
  294. {
  295. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_BAD_FORMAT);
  296. }
  297. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadPost( xml ));
  298. hr = S_OK;
  299. __HCP_FUNC_CLEANUP;
  300. __HCP_FUNC_EXIT(hr);
  301. }
  302. STDMETHODIMP CPCHAccessControlEntry::LoadXMLAsStream( /*[in]*/ IUnknown* pStream )
  303. {
  304. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::LoadXMLAsStream" );
  305. HRESULT hr;
  306. MPC::XmlUtil xml;
  307. bool fLoaded;
  308. bool fFound;
  309. __MPC_PARAMCHECK_BEGIN(hr)
  310. __MPC_PARAMCHECK_NOTNULL(pStream);
  311. __MPC_PARAMCHECK_END();
  312. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.LoadAsStream( pStream, s_TAG_ACE, fLoaded, &fFound ));
  313. if(fLoaded == false || fFound == false)
  314. {
  315. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_BAD_FORMAT);
  316. }
  317. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadPost( xml ));
  318. hr = S_OK;
  319. __HCP_FUNC_CLEANUP;
  320. __HCP_FUNC_EXIT(hr);
  321. }
  322. ////////////////////////////////////////////////////////////////////////////////
  323. HRESULT CPCHAccessControlEntry::SavePre( /*[in]*/ MPC::XmlUtil& xml )
  324. {
  325. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::SavePre" );
  326. HRESULT hr;
  327. MPC::SmartLock<_ThreadModel> lock( this );
  328. CComPtr<IXMLDOMNode> xdnNode;
  329. bool fFound;
  330. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.CreateNode( s_TAG_ACE, &xdnNode ));
  331. //
  332. // Write attributes.
  333. //
  334. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_ACE_AccessMask, m_dwAccessMask, fFound, xdnNode ));
  335. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_ACE_AceFlags , m_dwAceFlags , fFound, xdnNode ));
  336. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_ACE_AceType , m_dwAceType , fFound, xdnNode ));
  337. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_ACE_Flags , m_dwFlags , fFound, xdnNode ));
  338. //
  339. // Write values.
  340. //
  341. if(m_bstrTrustee ) __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutValue( s_TAG_Trustee , m_bstrTrustee , fFound, xdnNode ));
  342. if(m_bstrObjectType ) __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutValue( s_TAG_ObjectType , m_bstrObjectType , fFound, xdnNode ));
  343. if(m_bstrInheritedObjectType) __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutValue( s_TAG_InheritedObjectType, m_bstrInheritedObjectType, fFound, xdnNode ));
  344. hr = S_OK;
  345. __HCP_FUNC_CLEANUP;
  346. __HCP_FUNC_EXIT(hr);
  347. }
  348. STDMETHODIMP CPCHAccessControlEntry::SaveXML( /*[in ]*/ IXMLDOMNode* xdnRoot ,
  349. /*[out, retval]*/ IXMLDOMNode* *pxdnNode )
  350. {
  351. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::SaveXML" );
  352. HRESULT hr;
  353. MPC::XmlUtil xml( xdnRoot );
  354. __MPC_PARAMCHECK_BEGIN(hr)
  355. __MPC_PARAMCHECK_NOTNULL(xdnRoot);
  356. __MPC_PARAMCHECK_POINTER_AND_SET(pxdnNode,NULL);
  357. __MPC_PARAMCHECK_END();
  358. __MPC_EXIT_IF_METHOD_FAILS(hr, SavePre( xml ));
  359. hr = S_OK;
  360. __HCP_FUNC_CLEANUP;
  361. __HCP_FUNC_EXIT(hr);
  362. }
  363. STDMETHODIMP CPCHAccessControlEntry::SaveXMLAsString( /*[out, retval]*/ BSTR *bstrVal )
  364. {
  365. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::SaveXMLAsString" );
  366. HRESULT hr;
  367. MPC::XmlUtil xml;
  368. __MPC_PARAMCHECK_BEGIN(hr)
  369. __MPC_PARAMCHECK_POINTER_AND_SET(bstrVal,NULL);
  370. __MPC_PARAMCHECK_END();
  371. __MPC_EXIT_IF_METHOD_FAILS(hr, SavePre( xml ));
  372. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.SaveAsString( bstrVal ));
  373. hr = S_OK;
  374. __HCP_FUNC_CLEANUP;
  375. __HCP_FUNC_EXIT(hr);
  376. }
  377. STDMETHODIMP CPCHAccessControlEntry::SaveXMLAsStream( /*[out, retval]*/ IUnknown* *pStream )
  378. {
  379. __HCP_FUNC_ENTRY( "CPCHAccessControlEntry::SaveXMLAsStream" );
  380. HRESULT hr;
  381. MPC::XmlUtil xml;
  382. __MPC_PARAMCHECK_BEGIN(hr)
  383. __MPC_PARAMCHECK_POINTER_AND_SET(pStream,NULL);
  384. __MPC_PARAMCHECK_END();
  385. __MPC_EXIT_IF_METHOD_FAILS(hr, SavePre( xml ));
  386. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.SaveAsStream( pStream ));
  387. hr = S_OK;
  388. __HCP_FUNC_CLEANUP;
  389. __HCP_FUNC_EXIT(hr);
  390. }