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.

1300 lines
39 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SecurityDescriptor.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHSecurityDescriptor class,
  7. which is used to represent a security descriptor.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 03/22/2000
  10. created
  11. ******************************************************************************/
  12. #include "StdAfx.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //
  15. // SecurityDescriptor [@Revision
  16. // @Control
  17. // @OwnerDefaulted
  18. // @GroupDefaulted
  19. // @DaclDefaulted
  20. // @SaclDefaulted]
  21. //
  22. // Owner
  23. // Group
  24. // DiscretionaryAcl
  25. // SystemAcl
  26. //
  27. ////////////////////////////////////////////////////////////////////////////////
  28. static const CComBSTR s_TAG_SD ( L"SecurityDescriptor" );
  29. static const CComBSTR s_ATTR_SD_Revision ( L"Revision" );
  30. static const CComBSTR s_ATTR_SD_Control ( L"Control" );
  31. static const CComBSTR s_ATTR_SD_OwnerDefaulted( L"OwnerDefaulted" );
  32. static const CComBSTR s_ATTR_SD_GroupDefaulted( L"GroupDefaulted" );
  33. static const CComBSTR s_ATTR_SD_DaclDefaulted ( L"DaclDefaulted" );
  34. static const CComBSTR s_ATTR_SD_SaclDefaulted ( L"SaclDefaulted" );
  35. static const CComBSTR s_TAG_Owner ( L"Owner" );
  36. static const CComBSTR s_TAG_Group ( L"Group" );
  37. static const CComBSTR s_TAG_DiscretionaryAcl ( L"DiscretionaryAcl" );
  38. static const CComBSTR s_TAG_SystemAcl ( L"SystemAcl" );
  39. static const CComBSTR s_XQL_DiscretionaryAcl ( L"DiscretionaryAcl/AccessControlList" );
  40. static const CComBSTR s_XQL_SystemAcl ( L"SystemAcl/AccessControlList" );
  41. ////////////////////////////////////////////////////////////////////////////////
  42. static const MPC::StringToBitField s_arrCredentialMap[] =
  43. {
  44. { L"SYSTEM" , MPC::IDENTITY_SYSTEM , MPC::IDENTITY_SYSTEM , -1 },
  45. { L"LOCALSYSTEM" , MPC::IDENTITY_SYSTEM , MPC::IDENTITY_SYSTEM , -1 },
  46. { L"ADMINISTRATOR" , MPC::IDENTITY_ADMIN , MPC::IDENTITY_ADMIN , -1 },
  47. { L"ADMINISTRATORS", MPC::IDENTITY_ADMINS , MPC::IDENTITY_ADMINS , -1 },
  48. { L"POWERUSERS" , MPC::IDENTITY_POWERUSERS, MPC::IDENTITY_POWERUSERS, -1 },
  49. { L"USERS" , MPC::IDENTITY_USERS , MPC::IDENTITY_USERS , -1 },
  50. { L"GUESTS" , MPC::IDENTITY_GUESTS , MPC::IDENTITY_GUESTS , -1 },
  51. { NULL }
  52. };
  53. static const MPC::StringToBitField s_arrAccessMap[] =
  54. {
  55. { L"DELETE" , DELETE , DELETE , -1 },
  56. { L"READ_CONTROL" , READ_CONTROL , READ_CONTROL , -1 },
  57. { L"WRITE_DAC" , WRITE_DAC , WRITE_DAC , -1 },
  58. { L"WRITE_OWNER" , WRITE_OWNER , WRITE_OWNER , -1 },
  59. { L"SYNCHRONIZE" , SYNCHRONIZE , SYNCHRONIZE , -1 },
  60. { L"STANDARD_RIGHTS_REQUIRED", STANDARD_RIGHTS_REQUIRED, STANDARD_RIGHTS_REQUIRED, -1 },
  61. { L"STANDARD_RIGHTS_READ" , STANDARD_RIGHTS_READ , STANDARD_RIGHTS_READ , -1 },
  62. { L"STANDARD_RIGHTS_WRITE" , STANDARD_RIGHTS_WRITE , STANDARD_RIGHTS_WRITE , -1 },
  63. { L"STANDARD_RIGHTS_EXECUTE" , STANDARD_RIGHTS_EXECUTE , STANDARD_RIGHTS_EXECUTE , -1 },
  64. { L"STANDARD_RIGHTS_ALL" , STANDARD_RIGHTS_ALL , STANDARD_RIGHTS_ALL , -1 },
  65. { L"ACCESS_SYSTEM_SECURITY" , ACCESS_SYSTEM_SECURITY , ACCESS_SYSTEM_SECURITY , -1 },
  66. { L"ACCESS_READ" , ACCESS_READ , ACCESS_READ , -1 },
  67. { L"ACCESS_WRITE" , ACCESS_WRITE , ACCESS_WRITE , -1 },
  68. { L"ACCESS_CREATE" , ACCESS_CREATE , ACCESS_CREATE , -1 },
  69. { L"ACCESS_EXEC" , ACCESS_EXEC , ACCESS_EXEC , -1 },
  70. { L"ACCESS_DELETE" , ACCESS_DELETE , ACCESS_DELETE , -1 },
  71. { L"ACCESS_ATRIB" , ACCESS_ATRIB , ACCESS_ATRIB , -1 },
  72. { L"ACCESS_PERM" , ACCESS_PERM , ACCESS_PERM , -1 },
  73. { L"GENERIC_READ" , GENERIC_READ , GENERIC_READ , -1 },
  74. { L"GENERIC_WRITE" , GENERIC_WRITE , GENERIC_WRITE , -1 },
  75. { L"GENERIC_EXECUTE" , GENERIC_EXECUTE , GENERIC_EXECUTE , -1 },
  76. { L"GENERIC_ALL" , GENERIC_ALL , GENERIC_ALL , -1 },
  77. { L"KEY_QUERY_VALUE" , KEY_QUERY_VALUE , KEY_QUERY_VALUE , -1 },
  78. { L"KEY_SET_VALUE" , KEY_SET_VALUE , KEY_SET_VALUE , -1 },
  79. { L"KEY_CREATE_SUB_KEY" , KEY_CREATE_SUB_KEY , KEY_CREATE_SUB_KEY , -1 },
  80. { L"KEY_ENUMERATE_SUB_KEYS" , KEY_ENUMERATE_SUB_KEYS , KEY_ENUMERATE_SUB_KEYS , -1 },
  81. { L"KEY_NOTIFY" , KEY_NOTIFY , KEY_NOTIFY , -1 },
  82. { L"KEY_CREATE_LINK" , KEY_CREATE_LINK , KEY_CREATE_LINK , -1 },
  83. { L"KEY_WOW64_RES" , KEY_WOW64_RES , KEY_WOW64_RES , -1 },
  84. { L"KEY_READ" , KEY_READ , KEY_READ , -1 },
  85. { L"KEY_WRITE" , KEY_WRITE , KEY_WRITE , -1 },
  86. { L"KEY_EXECUTE" , KEY_EXECUTE , KEY_EXECUTE , -1 },
  87. { L"KEY_ALL_ACCESS" , KEY_ALL_ACCESS , KEY_ALL_ACCESS , -1 },
  88. { NULL }
  89. };
  90. ////////////////////////////////////////////////////////////////////////////////
  91. CPCHSecurityDescriptor::CPCHSecurityDescriptor()
  92. {
  93. m_dwRevision = 0; // DWORD m_dwRevision;
  94. m_dwControl = 0; // DWORD m_dwControl;
  95. //
  96. // CComBSTR m_bstrOwner;
  97. m_fOwnerDefaulted = false; // bool m_fOwnerDefaulted;
  98. //
  99. // CComBSTR m_bstrGroup;
  100. m_fGroupDefaulted = false; // bool m_fGroupDefaulted;
  101. //
  102. // CComPtr<IPCHAccessControlList> m_DACL;
  103. m_fDaclDefaulted = false; // bool m_fDaclDefaulted;
  104. //
  105. // CComPtr<IPCHAccessControlList> m_SACL;
  106. m_fSaclDefaulted = false; // bool m_fSaclDefaulted;
  107. }
  108. CPCHSecurityDescriptor::~CPCHSecurityDescriptor()
  109. {
  110. }
  111. ////////////////////////////////////////////////////////////////////////////////
  112. HRESULT CPCHSecurityDescriptor::GetForFile( /*[in ]*/ LPCWSTR szFilename ,
  113. /*[out, retval]*/ IPCHSecurityDescriptor* *psdObj )
  114. {
  115. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::GetForFile" );
  116. HRESULT hr;
  117. CPCHSecurityDescriptorDirect sdd;
  118. CComPtr<CPCHSecurityDescriptor> obj;
  119. __MPC_PARAMCHECK_BEGIN(hr)
  120. __MPC_PARAMCHECK_POINTER_AND_SET(psdObj,NULL);
  121. __MPC_PARAMCHECK_END();
  122. //
  123. // Get the security descriptor for the file.
  124. //
  125. if(FAILED(sdd.GetForFile( szFilename, sdd.s_SecInfo_ALL )))
  126. {
  127. //
  128. // If we fail to load the SACL, retry without...
  129. //
  130. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.GetForFile( szFilename, sdd.s_SecInfo_MOST ));
  131. }
  132. //
  133. // Convert it to COM.
  134. //
  135. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  136. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertSDToCOM( obj ));
  137. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( psdObj ));
  138. hr = S_OK;
  139. __HCP_FUNC_CLEANUP;
  140. __HCP_FUNC_EXIT(hr);
  141. }
  142. HRESULT CPCHSecurityDescriptor::SetForFile( /*[in]*/ LPCWSTR szFilename ,
  143. /*[in]*/ IPCHSecurityDescriptor* sdObj )
  144. {
  145. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::SetForFile" );
  146. HRESULT hr;
  147. CPCHSecurityDescriptorDirect sdd;
  148. __MPC_PARAMCHECK_BEGIN(hr)
  149. __MPC_PARAMCHECK_NOTNULL(sdObj);
  150. __MPC_PARAMCHECK_END();
  151. //
  152. // Convert security descriptor from COM.
  153. //
  154. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertSDFromCOM( sdObj ));
  155. //
  156. // Set the security descriptor for the file.
  157. //
  158. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.SetForFile( szFilename, sdd.GetSACL() ? sdd.s_SecInfo_ALL : sdd.s_SecInfo_MOST ));
  159. hr = S_OK;
  160. __HCP_FUNC_CLEANUP;
  161. __HCP_FUNC_EXIT(hr);
  162. }
  163. HRESULT CPCHSecurityDescriptor::GetForRegistry( /*[in ]*/ LPCWSTR szKey ,
  164. /*[out, retval]*/ IPCHSecurityDescriptor* *psdObj )
  165. {
  166. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::GetForRegistry" );
  167. HRESULT hr;
  168. CPCHSecurityDescriptorDirect sdd;
  169. CComPtr<CPCHSecurityDescriptor> obj;
  170. __MPC_PARAMCHECK_BEGIN(hr)
  171. __MPC_PARAMCHECK_POINTER_AND_SET(psdObj,NULL);
  172. __MPC_PARAMCHECK_END();
  173. //
  174. // Get the SD from the key.
  175. //
  176. if(FAILED(sdd.GetForRegistry( szKey, sdd.s_SecInfo_ALL )))
  177. {
  178. //
  179. // If we fail to load the SACL, retry without...
  180. //
  181. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.GetForRegistry( szKey, sdd.s_SecInfo_MOST ));
  182. }
  183. //
  184. // Convert it to COM.
  185. //
  186. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  187. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertSDToCOM( obj ));
  188. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( psdObj ));
  189. hr = S_OK;
  190. __HCP_FUNC_CLEANUP;
  191. __HCP_FUNC_EXIT(hr);
  192. }
  193. HRESULT CPCHSecurityDescriptor::SetForRegistry( /*[in]*/ LPCWSTR szKey ,
  194. /*[in]*/ IPCHSecurityDescriptor* sdObj )
  195. {
  196. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::SetForRegistry" );
  197. HRESULT hr;
  198. CPCHSecurityDescriptorDirect sdd;
  199. __MPC_PARAMCHECK_BEGIN(hr)
  200. __MPC_PARAMCHECK_NOTNULL(sdObj);
  201. __MPC_PARAMCHECK_END();
  202. //
  203. // Convert security descriptor from COM.
  204. //
  205. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertSDFromCOM( sdObj ));
  206. //
  207. // Set the security descriptor for the registry key.
  208. //
  209. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.SetForRegistry( szKey, sdd.GetSACL() ? sdd.s_SecInfo_ALL : sdd.s_SecInfo_MOST ));
  210. hr = S_OK;
  211. __HCP_FUNC_CLEANUP;
  212. __HCP_FUNC_EXIT(hr);
  213. }
  214. ////////////////////////////////////////////////////////////////////////////////
  215. STDMETHODIMP CPCHSecurityDescriptor::get_Revision( /*[out, retval]*/ long *pVal )
  216. {
  217. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_Revision",hr,pVal);
  218. *pVal = m_dwRevision;
  219. __HCP_END_PROPERTY(hr);
  220. }
  221. STDMETHODIMP CPCHSecurityDescriptor::put_Revision( /*[in]*/ long newVal )
  222. {
  223. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_Revision",hr);
  224. m_dwRevision = newVal;
  225. __HCP_END_PROPERTY(hr);
  226. }
  227. ////////////////////
  228. STDMETHODIMP CPCHSecurityDescriptor::get_Control( /*[out, retval]*/ long *pVal )
  229. {
  230. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_Control",hr,pVal);
  231. *pVal = m_dwControl;
  232. __HCP_END_PROPERTY(hr);
  233. }
  234. STDMETHODIMP CPCHSecurityDescriptor::put_Control( /*[in]*/ long newVal )
  235. {
  236. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_Control",hr);
  237. m_dwControl = newVal;
  238. __HCP_END_PROPERTY(hr);
  239. }
  240. ////////////////////
  241. STDMETHODIMP CPCHSecurityDescriptor::get_Owner( /*[out, retval]*/ BSTR *pVal )
  242. {
  243. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_Owner",hr,pVal);
  244. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrOwner, pVal ));
  245. __HCP_END_PROPERTY(hr);
  246. }
  247. STDMETHODIMP CPCHSecurityDescriptor::put_Owner( /*[in]*/ BSTR newVal )
  248. {
  249. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_Owner",hr);
  250. if(newVal)
  251. {
  252. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptorDirect::VerifyPrincipal( newVal ));
  253. }
  254. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::PutBSTR( m_bstrOwner, newVal ));
  255. __HCP_END_PROPERTY(hr);
  256. }
  257. ////////////////////
  258. STDMETHODIMP CPCHSecurityDescriptor::get_OwnerDefaulted( /*[out, retval]*/ VARIANT_BOOL *pVal )
  259. {
  260. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_OwnerDefaulted",hr,pVal);
  261. *pVal = m_fOwnerDefaulted ? VARIANT_TRUE : VARIANT_FALSE;
  262. __HCP_END_PROPERTY(hr);
  263. }
  264. STDMETHODIMP CPCHSecurityDescriptor::put_OwnerDefaulted( /*[in]*/ VARIANT_BOOL newVal )
  265. {
  266. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_OwnerDefaulted",hr);
  267. m_fOwnerDefaulted = (newVal == VARIANT_TRUE);
  268. __HCP_END_PROPERTY(hr);
  269. }
  270. ////////////////////
  271. STDMETHODIMP CPCHSecurityDescriptor::get_Group( /*[out, retval]*/ BSTR *pVal )
  272. {
  273. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_Group",hr,pVal);
  274. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrGroup, pVal ));
  275. __HCP_END_PROPERTY(hr);
  276. }
  277. STDMETHODIMP CPCHSecurityDescriptor::put_Group( /*[in]*/ BSTR newVal )
  278. {
  279. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_Group",hr);
  280. if(newVal)
  281. {
  282. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptorDirect::VerifyPrincipal( newVal ));
  283. }
  284. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::PutBSTR( m_bstrGroup, newVal ));
  285. __HCP_END_PROPERTY(hr);
  286. }
  287. ////////////////////
  288. STDMETHODIMP CPCHSecurityDescriptor::get_GroupDefaulted( /*[out, retval]*/ VARIANT_BOOL *pVal )
  289. {
  290. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_GroupDefaulted",hr,pVal);
  291. *pVal = m_fGroupDefaulted ? VARIANT_TRUE : VARIANT_FALSE;
  292. __HCP_END_PROPERTY(hr);
  293. }
  294. STDMETHODIMP CPCHSecurityDescriptor::put_GroupDefaulted( /*[in]*/ VARIANT_BOOL newVal )
  295. {
  296. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_GroupDefaulted",hr);
  297. m_fGroupDefaulted = (newVal == VARIANT_TRUE);
  298. __HCP_END_PROPERTY(hr);
  299. }
  300. ////////////////////
  301. STDMETHODIMP CPCHSecurityDescriptor::get_DiscretionaryAcl( /*[out, retval]*/ IPCHAccessControlList* *pVal )
  302. {
  303. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_DiscretionaryAcl",hr,pVal);
  304. __MPC_EXIT_IF_METHOD_FAILS(hr, m_DACL.CopyTo( pVal ));
  305. __HCP_END_PROPERTY(hr);
  306. }
  307. STDMETHODIMP CPCHSecurityDescriptor::put_DiscretionaryAcl( /*[in]*/ IPCHAccessControlList* newVal )
  308. {
  309. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_DiscretionaryAcl",hr);
  310. m_DACL = newVal;
  311. __HCP_END_PROPERTY(hr);
  312. }
  313. ////////////////////
  314. STDMETHODIMP CPCHSecurityDescriptor::get_DaclDefaulted( /*[out, retval]*/ VARIANT_BOOL *pVal )
  315. {
  316. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_DaclDefaulted",hr,pVal);
  317. *pVal = m_fDaclDefaulted ? VARIANT_TRUE : VARIANT_FALSE;
  318. __HCP_END_PROPERTY(hr);
  319. }
  320. STDMETHODIMP CPCHSecurityDescriptor::put_DaclDefaulted( /*[in]*/ VARIANT_BOOL newVal )
  321. {
  322. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_DaclDefaulted",hr);
  323. m_fDaclDefaulted = (newVal == VARIANT_TRUE);
  324. __HCP_END_PROPERTY(hr);
  325. }
  326. ////////////////////
  327. STDMETHODIMP CPCHSecurityDescriptor::get_SystemAcl( /*[out, retval]*/ IPCHAccessControlList* *pVal )
  328. {
  329. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_SystemAcl",hr,pVal);
  330. __MPC_EXIT_IF_METHOD_FAILS(hr, m_SACL.CopyTo( pVal ));
  331. __HCP_END_PROPERTY(hr);
  332. }
  333. STDMETHODIMP CPCHSecurityDescriptor::put_SystemAcl( /*[in]*/ IPCHAccessControlList* newVal )
  334. {
  335. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_SystemAcl",hr);
  336. m_SACL = newVal;
  337. __HCP_END_PROPERTY(hr);
  338. }
  339. ////////////////////
  340. STDMETHODIMP CPCHSecurityDescriptor::get_SaclDefaulted( /*[out, retval]*/ VARIANT_BOOL *pVal )
  341. {
  342. __HCP_BEGIN_PROPERTY_GET("CPCHSecurityDescriptor::get_SaclDefaulted",hr,pVal);
  343. *pVal = m_fSaclDefaulted ? VARIANT_TRUE : VARIANT_FALSE;
  344. __HCP_END_PROPERTY(hr);
  345. }
  346. STDMETHODIMP CPCHSecurityDescriptor::put_SaclDefaulted( /*[in]*/ VARIANT_BOOL newVal )
  347. {
  348. __HCP_BEGIN_PROPERTY_PUT("CPCHSecurityDescriptor::put_SaclDefaulted",hr);
  349. m_fSaclDefaulted = (newVal == VARIANT_TRUE);
  350. __HCP_END_PROPERTY(hr);
  351. }
  352. ////////////////////////////////////////////////////////////////////////////////
  353. STDMETHODIMP CPCHSecurityDescriptor::Clone( /*[out, retval]*/ IPCHSecurityDescriptor* *pVal )
  354. {
  355. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::Clone" );
  356. HRESULT hr;
  357. MPC::SmartLock<_ThreadModel> lock( this );
  358. CComPtr<CPCHSecurityDescriptor> pNew;
  359. CPCHSecurityDescriptor* pPtr;
  360. __MPC_PARAMCHECK_BEGIN(hr)
  361. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  362. __MPC_PARAMCHECK_END();
  363. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pNew ));
  364. pPtr = pNew;
  365. pPtr->m_dwRevision = m_dwRevision;
  366. pPtr->m_dwControl = m_dwControl;
  367. pPtr->m_bstrOwner = m_bstrOwner;
  368. pPtr->m_fOwnerDefaulted = m_fOwnerDefaulted;
  369. pPtr->m_bstrGroup = m_bstrGroup;
  370. pPtr->m_fGroupDefaulted = m_fGroupDefaulted;
  371. pPtr->m_fDaclDefaulted = m_fDaclDefaulted;
  372. pPtr->m_fSaclDefaulted = m_fSaclDefaulted;
  373. if(m_DACL) __MPC_EXIT_IF_METHOD_FAILS(hr, m_DACL->Clone( &pPtr->m_DACL ));
  374. if(m_SACL) __MPC_EXIT_IF_METHOD_FAILS(hr, m_SACL->Clone( &pPtr->m_SACL ));
  375. __MPC_EXIT_IF_METHOD_FAILS(hr, pNew.QueryInterface( pVal ));
  376. hr = S_OK;
  377. __HCP_FUNC_CLEANUP;
  378. __HCP_FUNC_EXIT(hr);
  379. }
  380. ////////////////////////////////////////////////////////////////////////////////
  381. HRESULT CPCHSecurityDescriptor::LoadPost( /*[in]*/ MPC::XmlUtil& xml )
  382. {
  383. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::LoadPost" );
  384. HRESULT hr;
  385. MPC::SmartLock<_ThreadModel> lock( this );
  386. CComPtr<IXMLDOMNode> xdnNode;
  387. CComBSTR bstrValue;
  388. LONG lValue;
  389. bool fFound;
  390. //
  391. // Make sure we have something to parse....
  392. //
  393. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetRoot( &xdnNode )); xdnNode.Release();
  394. //
  395. // Clean up before loading.
  396. //
  397. m_dwRevision = 0;
  398. m_dwControl = 0;
  399. m_bstrOwner.Empty();
  400. m_fOwnerDefaulted = false;
  401. m_bstrGroup.Empty();
  402. m_fGroupDefaulted = false;
  403. m_DACL.Release();
  404. m_fDaclDefaulted = false;
  405. m_SACL.Release();
  406. m_fSaclDefaulted = false;
  407. //
  408. // Read attributes.
  409. //
  410. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_SD_Revision , lValue, fFound )); if(fFound) m_dwRevision = lValue;
  411. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_SD_Control , lValue, fFound )); if(fFound) m_dwControl = lValue;
  412. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_SD_OwnerDefaulted, lValue, fFound )); if(fFound) m_fOwnerDefaulted = (lValue != 0);
  413. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_SD_GroupDefaulted, lValue, fFound )); if(fFound) m_fGroupDefaulted = (lValue != 0);
  414. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_SD_DaclDefaulted , lValue, fFound )); if(fFound) m_fDaclDefaulted = (lValue != 0);
  415. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, s_ATTR_SD_SaclDefaulted , lValue, fFound )); if(fFound) m_fSaclDefaulted = (lValue != 0);
  416. //
  417. // Read values.
  418. //
  419. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetValue( s_TAG_Owner, bstrValue, fFound )); if(fFound) m_bstrOwner.Attach( bstrValue.Detach() );
  420. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetValue( s_TAG_Group, bstrValue, fFound )); if(fFound) m_bstrGroup.Attach( bstrValue.Detach() );
  421. //
  422. // Read ACLS.
  423. //
  424. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetNode( s_XQL_DiscretionaryAcl, &xdnNode ));
  425. if(xdnNode)
  426. {
  427. CComPtr<CPCHAccessControlList> acl;
  428. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &acl ));
  429. __MPC_EXIT_IF_METHOD_FAILS(hr, acl->LoadXML( xdnNode ));
  430. m_DACL = acl; xdnNode.Release();
  431. }
  432. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetNode( s_XQL_SystemAcl, &xdnNode ));
  433. if(xdnNode)
  434. {
  435. CComPtr<CPCHAccessControlList> acl;
  436. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &acl ));
  437. __MPC_EXIT_IF_METHOD_FAILS(hr, acl->LoadXML( xdnNode ));
  438. m_SACL = acl;
  439. }
  440. if(m_bstrOwner.Length())
  441. {
  442. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptorDirect::VerifyPrincipal( m_bstrOwner ));
  443. }
  444. if(m_bstrGroup.Length())
  445. {
  446. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptorDirect::VerifyPrincipal( m_bstrGroup ));
  447. }
  448. hr = S_OK;
  449. __HCP_FUNC_CLEANUP;
  450. __HCP_FUNC_EXIT(hr);
  451. }
  452. STDMETHODIMP CPCHSecurityDescriptor::LoadXML( /*[in]*/ IXMLDOMNode* xdnNode )
  453. {
  454. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::LoadXML" );
  455. HRESULT hr;
  456. MPC::XmlUtil xml( xdnNode );
  457. __MPC_PARAMCHECK_BEGIN(hr)
  458. __MPC_PARAMCHECK_NOTNULL(xdnNode);
  459. __MPC_PARAMCHECK_END();
  460. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadPost( xml ));
  461. hr = S_OK;
  462. __HCP_FUNC_CLEANUP;
  463. __HCP_FUNC_EXIT(hr);
  464. }
  465. STDMETHODIMP CPCHSecurityDescriptor::LoadXMLAsString( /*[in]*/ BSTR bstrVal )
  466. {
  467. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::LoadXMLAsString" );
  468. HRESULT hr;
  469. MPC::XmlUtil xml;
  470. bool fLoaded;
  471. bool fFound;
  472. __MPC_PARAMCHECK_BEGIN(hr)
  473. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrVal);
  474. __MPC_PARAMCHECK_END();
  475. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.LoadAsString( bstrVal, s_TAG_SD, fLoaded, &fFound ));
  476. if(fLoaded == false || fFound == false)
  477. {
  478. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_BAD_FORMAT);
  479. }
  480. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadPost( xml ));
  481. hr = S_OK;
  482. __HCP_FUNC_CLEANUP;
  483. __HCP_FUNC_EXIT(hr);
  484. }
  485. STDMETHODIMP CPCHSecurityDescriptor::LoadXMLAsStream( /*[in]*/ IUnknown* pStream )
  486. {
  487. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::LoadXMLAsStream" );
  488. HRESULT hr;
  489. MPC::XmlUtil xml;
  490. bool fLoaded;
  491. bool fFound;
  492. __MPC_PARAMCHECK_BEGIN(hr)
  493. __MPC_PARAMCHECK_NOTNULL(pStream);
  494. __MPC_PARAMCHECK_END();
  495. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.LoadAsStream( pStream, s_TAG_SD, fLoaded, &fFound ));
  496. if(fLoaded == false || fFound == false)
  497. {
  498. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_BAD_FORMAT);
  499. }
  500. __MPC_EXIT_IF_METHOD_FAILS(hr, LoadPost( xml ));
  501. hr = S_OK;
  502. __HCP_FUNC_CLEANUP;
  503. __HCP_FUNC_EXIT(hr);
  504. }
  505. ////////////////////////////////////////////////////////////////////////////////
  506. HRESULT CPCHSecurityDescriptor::SavePre( /*[in]*/ MPC::XmlUtil& xml )
  507. {
  508. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::SavePre" );
  509. HRESULT hr;
  510. MPC::SmartLock<_ThreadModel> lock( this );
  511. CComPtr<IXMLDOMNode> xdnNode;
  512. bool fFound;
  513. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.CreateNode( s_TAG_SD, &xdnNode ));
  514. //
  515. // Write attributes.
  516. //
  517. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_SD_Revision , m_dwRevision , fFound, xdnNode ));
  518. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_SD_Control , m_dwControl , fFound, xdnNode ));
  519. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_SD_OwnerDefaulted, m_fOwnerDefaulted, fFound, xdnNode ));
  520. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_SD_GroupDefaulted, m_fGroupDefaulted, fFound, xdnNode ));
  521. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_SD_DaclDefaulted , m_fDaclDefaulted , fFound, xdnNode ));
  522. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutAttribute( NULL, s_ATTR_SD_SaclDefaulted , m_fSaclDefaulted , fFound, xdnNode ));
  523. //
  524. // Write values.
  525. //
  526. if(m_bstrOwner) __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutValue( s_TAG_Owner, m_bstrOwner, fFound, xdnNode ));
  527. if(m_bstrGroup) __MPC_EXIT_IF_METHOD_FAILS(hr, xml.PutValue( s_TAG_Group, m_bstrGroup, fFound, xdnNode ));
  528. //
  529. // Write ACLS.
  530. //
  531. if(m_DACL)
  532. {
  533. CComPtr<IXMLDOMNode> xdnSubNode;
  534. CComPtr<IXMLDOMNode> xdnSubSubNode;
  535. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.CreateNode( s_TAG_DiscretionaryAcl, &xdnSubNode, xdnNode ));
  536. __MPC_EXIT_IF_METHOD_FAILS(hr, m_DACL->SaveXML( xdnSubNode, &xdnSubSubNode ));
  537. }
  538. if(m_SACL)
  539. {
  540. CComPtr<IXMLDOMNode> xdnSubNode;
  541. CComPtr<IXMLDOMNode> xdnSubSubNode;
  542. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.CreateNode( s_TAG_SystemAcl, &xdnSubNode, xdnNode ));
  543. __MPC_EXIT_IF_METHOD_FAILS(hr, m_SACL->SaveXML( xdnSubNode, &xdnSubSubNode ));
  544. }
  545. hr = S_OK;
  546. __HCP_FUNC_CLEANUP;
  547. __HCP_FUNC_EXIT(hr);
  548. }
  549. STDMETHODIMP CPCHSecurityDescriptor::SaveXML( /*[in ]*/ IXMLDOMNode* xdnRoot ,
  550. /*[out, retval]*/ IXMLDOMNode* *pxdnNode )
  551. {
  552. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::SaveXML" );
  553. HRESULT hr;
  554. MPC::XmlUtil xml( xdnRoot );
  555. __MPC_PARAMCHECK_BEGIN(hr)
  556. __MPC_PARAMCHECK_NOTNULL(xdnRoot);
  557. __MPC_PARAMCHECK_POINTER_AND_SET(pxdnNode,NULL);
  558. __MPC_PARAMCHECK_END();
  559. __MPC_EXIT_IF_METHOD_FAILS(hr, SavePre( xml ));
  560. hr = S_OK;
  561. __HCP_FUNC_CLEANUP;
  562. __HCP_FUNC_EXIT(hr);
  563. }
  564. STDMETHODIMP CPCHSecurityDescriptor::SaveXMLAsString( /*[out, retval]*/ BSTR *bstrVal )
  565. {
  566. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::SaveXMLAsString" );
  567. HRESULT hr;
  568. MPC::XmlUtil xml;
  569. __MPC_PARAMCHECK_BEGIN(hr)
  570. __MPC_PARAMCHECK_POINTER_AND_SET(bstrVal,NULL);
  571. __MPC_PARAMCHECK_END();
  572. __MPC_EXIT_IF_METHOD_FAILS(hr, SavePre( xml ));
  573. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.SaveAsString( bstrVal ));
  574. hr = S_OK;
  575. __HCP_FUNC_CLEANUP;
  576. __HCP_FUNC_EXIT(hr);
  577. }
  578. STDMETHODIMP CPCHSecurityDescriptor::SaveXMLAsStream( /*[out, retval]*/ IUnknown* *pStream )
  579. {
  580. __HCP_FUNC_ENTRY( "CPCHSecurityDescriptor::SaveXMLAsStream" );
  581. HRESULT hr;
  582. MPC::XmlUtil xml;
  583. __MPC_PARAMCHECK_BEGIN(hr)
  584. __MPC_PARAMCHECK_POINTER_AND_SET(pStream,NULL);
  585. __MPC_PARAMCHECK_END();
  586. __MPC_EXIT_IF_METHOD_FAILS(hr, SavePre( xml ));
  587. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.SaveAsStream( pStream ));
  588. hr = S_OK;
  589. __HCP_FUNC_CLEANUP;
  590. __HCP_FUNC_EXIT(hr);
  591. }
  592. ////////////////////////////////////////////////////////////////////////////////
  593. ////////////////////////////////////////////////////////////////////////////////
  594. CPCHSecurity* CPCHSecurity::s_GLOBAL( NULL );
  595. HRESULT CPCHSecurity::InitializeSystem()
  596. {
  597. if(s_GLOBAL) return S_OK;
  598. return MPC::CreateInstanceCached( &CPCHSecurity::s_GLOBAL );
  599. }
  600. void CPCHSecurity::FinalizeSystem()
  601. {
  602. if(s_GLOBAL)
  603. {
  604. s_GLOBAL->Release(); s_GLOBAL = NULL;
  605. }
  606. }
  607. ////////////////////////////////////////////////////////////////////////////////
  608. STDMETHODIMP CPCHSecurity::CreateObject_SecurityDescriptor( /*[out, retval]*/ IPCHSecurityDescriptor* *pSD )
  609. {
  610. __HCP_FUNC_ENTRY( "CPCHSecurity::CreateObject_SecurityDescriptor" );
  611. HRESULT hr;
  612. CComPtr<CPCHSecurityDescriptor> obj;
  613. __MPC_PARAMCHECK_BEGIN(hr)
  614. __MPC_PARAMCHECK_POINTER_AND_SET(pSD,NULL);
  615. __MPC_PARAMCHECK_END();
  616. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  617. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( pSD ));
  618. hr = S_OK;
  619. __HCP_FUNC_CLEANUP;
  620. __HCP_FUNC_EXIT(hr);
  621. }
  622. STDMETHODIMP CPCHSecurity::CreateObject_AccessControlList( /*[out, retval]*/ IPCHAccessControlList* *pACL )
  623. {
  624. __HCP_FUNC_ENTRY( "CPCHSecurity::CreateObject_AccessControlList" );
  625. HRESULT hr;
  626. CComPtr<CPCHAccessControlList> obj;
  627. __MPC_PARAMCHECK_BEGIN(hr)
  628. __MPC_PARAMCHECK_POINTER_AND_SET(pACL,NULL);
  629. __MPC_PARAMCHECK_END();
  630. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  631. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( pACL ));
  632. hr = S_OK;
  633. __HCP_FUNC_CLEANUP;
  634. __HCP_FUNC_EXIT(hr);
  635. }
  636. STDMETHODIMP CPCHSecurity::CreateObject_AccessControlEntry( /*[out, retval]*/ IPCHAccessControlEntry* *pACE )
  637. {
  638. __HCP_FUNC_ENTRY( "CPCHSecurity::CreateObject_AccessControlEntry" );
  639. HRESULT hr;
  640. CComPtr<CPCHAccessControlEntry> obj;
  641. __MPC_PARAMCHECK_BEGIN(hr)
  642. __MPC_PARAMCHECK_POINTER_AND_SET(pACE,NULL);
  643. __MPC_PARAMCHECK_END();
  644. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  645. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( pACE ));
  646. hr = S_OK;
  647. __HCP_FUNC_CLEANUP;
  648. __HCP_FUNC_EXIT(hr);
  649. }
  650. ////////////////////
  651. STDMETHODIMP CPCHSecurity::GetUserName( /*[in] */ BSTR bstrPrincipal ,
  652. /*[out, retval]*/ BSTR *retVal )
  653. {
  654. __HCP_FUNC_ENTRY( "CPCHSecurity::GetUserName" );
  655. HRESULT hr;
  656. MPC::wstring strName;
  657. __MPC_PARAMCHECK_BEGIN(hr)
  658. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrPrincipal);
  659. __MPC_PARAMCHECK_POINTER_AND_SET(retVal,NULL);
  660. __MPC_PARAMCHECK_END();
  661. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SecurityDescriptor::GetAccountName( bstrPrincipal, strName ));
  662. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( strName.c_str(), retVal ));
  663. hr = S_OK;
  664. __HCP_FUNC_CLEANUP;
  665. __HCP_FUNC_EXIT(hr);
  666. }
  667. STDMETHODIMP CPCHSecurity::GetUserDomain( /*[in] */ BSTR bstrPrincipal ,
  668. /*[out, retval]*/ BSTR *retVal )
  669. {
  670. __HCP_FUNC_ENTRY( "CPCHSecurity::GetUserDomain" );
  671. HRESULT hr;
  672. MPC::wstring strName;
  673. __MPC_PARAMCHECK_BEGIN(hr)
  674. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrPrincipal);
  675. __MPC_PARAMCHECK_POINTER_AND_SET(retVal,NULL);
  676. __MPC_PARAMCHECK_END();
  677. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SecurityDescriptor::GetAccountDomain( bstrPrincipal, strName ));
  678. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( strName.c_str(), retVal ));
  679. hr = S_OK;
  680. __HCP_FUNC_CLEANUP;
  681. __HCP_FUNC_EXIT(hr);
  682. }
  683. STDMETHODIMP CPCHSecurity::GetUserDisplayName( /*[in] */ BSTR bstrPrincipal ,
  684. /*[out, retval]*/ BSTR *retVal )
  685. {
  686. __HCP_FUNC_ENTRY( "CPCHSecurity::GetUserDisplayName" );
  687. HRESULT hr;
  688. MPC::wstring strName;
  689. __MPC_PARAMCHECK_BEGIN(hr)
  690. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrPrincipal);
  691. __MPC_PARAMCHECK_POINTER_AND_SET(retVal,NULL);
  692. __MPC_PARAMCHECK_END();
  693. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SecurityDescriptor::GetAccountDisplayName( bstrPrincipal, strName ));
  694. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( strName.c_str(), retVal ));
  695. hr = S_OK;
  696. __HCP_FUNC_CLEANUP;
  697. __HCP_FUNC_EXIT(hr);
  698. }
  699. ////////////////////
  700. STDMETHODIMP CPCHSecurity::CheckCredentials( /*[in] */ BSTR bstrCredentials ,
  701. /*[out, retval]*/ VARIANT_BOOL *retVal )
  702. {
  703. __HCP_FUNC_ENTRY( "CPCHSecurity::CheckCredentials" );
  704. HRESULT hr;
  705. CComBSTR bstrUser;
  706. DWORD dwAllowedIdentity;
  707. DWORD dwDesiredIdentity;
  708. __MPC_PARAMCHECK_BEGIN(hr)
  709. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrCredentials);
  710. __MPC_PARAMCHECK_POINTER_AND_SET(retVal,VARIANT_FALSE);
  711. __MPC_PARAMCHECK_END();
  712. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::ConvertStringToBitField( bstrCredentials, dwDesiredIdentity, s_arrCredentialMap ));
  713. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetCallerPrincipal( /*fImpersonate*/true, bstrUser, &dwAllowedIdentity ));
  714. *retVal = (dwAllowedIdentity & dwDesiredIdentity) ? VARIANT_TRUE : VARIANT_FALSE;
  715. hr = S_OK;
  716. __HCP_FUNC_CLEANUP;
  717. __HCP_FUNC_EXIT(hr);
  718. }
  719. ////////////////////
  720. HRESULT CPCHSecurity::CheckAccess( /*[in]*/ VARIANT& vDesiredAccess ,
  721. /*[in]*/ MPC::SecurityDescriptor& sd ,
  722. /*[out]*/ VARIANT_BOOL& retVal )
  723. {
  724. __HCP_FUNC_ENTRY( "CPCHSecurity::CheckAccessToSD" );
  725. HRESULT hr;
  726. MPC::AccessCheck ac;
  727. DWORD dwDesired;
  728. DWORD dwGranted;
  729. BOOL fGranted;
  730. if(vDesiredAccess.vt == VT_I4)
  731. {
  732. dwDesired = vDesiredAccess.lVal;
  733. }
  734. else if(vDesiredAccess.vt == VT_BSTR)
  735. {
  736. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::ConvertStringToBitField( vDesiredAccess.bstrVal, dwDesired, s_arrAccessMap ));
  737. }
  738. else
  739. {
  740. __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  741. }
  742. __MPC_EXIT_IF_METHOD_FAILS(hr, ac.GetTokenFromImpersonation());
  743. __MPC_EXIT_IF_METHOD_FAILS(hr, ac.Verify( dwDesired, fGranted, dwGranted, sd ));
  744. if(fGranted) retVal = VARIANT_TRUE;
  745. hr = S_OK;
  746. __HCP_FUNC_CLEANUP;
  747. __HCP_FUNC_EXIT(hr);
  748. }
  749. STDMETHODIMP CPCHSecurity::CheckAccessToSD( /*[in]*/ VARIANT vDesiredAccess,
  750. /*[in]*/ IPCHSecurityDescriptor* sd ,
  751. /*[out, retval]*/ VARIANT_BOOL *retVal )
  752. {
  753. __HCP_FUNC_ENTRY( "CPCHSecurity::CheckAccessToSD" );
  754. HRESULT hr;
  755. CPCHSecurityDescriptorDirect sdd;
  756. __MPC_PARAMCHECK_BEGIN(hr)
  757. __MPC_PARAMCHECK_NOTNULL(sd);
  758. __MPC_PARAMCHECK_POINTER_AND_SET(retVal,VARIANT_FALSE);
  759. __MPC_PARAMCHECK_END();
  760. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertSDFromCOM( sd ));
  761. __MPC_EXIT_IF_METHOD_FAILS(hr, CheckAccess( vDesiredAccess, sdd, *retVal ));
  762. hr = S_OK;
  763. __HCP_FUNC_CLEANUP;
  764. __HCP_FUNC_EXIT(hr);
  765. }
  766. STDMETHODIMP CPCHSecurity::CheckAccessToFile( /*[in]*/ VARIANT vDesiredAccess ,
  767. /*[in]*/ BSTR bstrFilename ,
  768. /*[out, retval]*/ VARIANT_BOOL *retVal )
  769. {
  770. __HCP_FUNC_ENTRY( "CPCHSecurity::CheckAccessToFile" );
  771. HRESULT hr;
  772. CPCHSecurityDescriptorDirect sdd;
  773. __MPC_PARAMCHECK_BEGIN(hr)
  774. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrFilename);
  775. __MPC_PARAMCHECK_POINTER_AND_SET(retVal,VARIANT_FALSE);
  776. __MPC_PARAMCHECK_END();
  777. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.GetForFile( bstrFilename, sdd.s_SecInfo_MOST ));
  778. __MPC_EXIT_IF_METHOD_FAILS(hr, CheckAccess( vDesiredAccess, sdd, *retVal ));
  779. hr = S_OK;
  780. __HCP_FUNC_CLEANUP;
  781. __HCP_FUNC_EXIT(hr);
  782. }
  783. STDMETHODIMP CPCHSecurity::CheckAccessToRegistry( /*[in]*/ VARIANT vDesiredAccess ,
  784. /*[in]*/ BSTR bstrKey ,
  785. /*[out, retval]*/ VARIANT_BOOL *retVal )
  786. {
  787. __HCP_FUNC_ENTRY( "CPCHSecurity::CheckAccessToRegistry" );
  788. HRESULT hr;
  789. CPCHSecurityDescriptorDirect sdd;
  790. __MPC_PARAMCHECK_BEGIN(hr)
  791. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrKey);
  792. __MPC_PARAMCHECK_POINTER_AND_SET(retVal,VARIANT_FALSE);
  793. __MPC_PARAMCHECK_END();
  794. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.GetForRegistry( bstrKey, sdd.s_SecInfo_MOST ));
  795. __MPC_EXIT_IF_METHOD_FAILS(hr, CheckAccess( vDesiredAccess, sdd, *retVal ));
  796. hr = S_OK;
  797. __HCP_FUNC_CLEANUP;
  798. __HCP_FUNC_EXIT(hr);
  799. }
  800. ////////////////////
  801. STDMETHODIMP CPCHSecurity::GetFileSD( /*[in ]*/ BSTR bstrFilename ,
  802. /*[out, retval]*/ IPCHSecurityDescriptor* *psd )
  803. {
  804. __HCP_FUNC_ENTRY( "CPCHSecurity::GetFileSD" );
  805. HRESULT hr;
  806. MPC::Impersonation imp;
  807. __MPC_PARAMCHECK_BEGIN(hr)
  808. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrFilename);
  809. __MPC_PARAMCHECK_POINTER_AND_SET(psd,NULL);
  810. __MPC_PARAMCHECK_END();
  811. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Initialize ());
  812. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Impersonate());
  813. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptor::GetForFile( bstrFilename, psd ));
  814. hr = S_OK;
  815. __HCP_FUNC_CLEANUP;
  816. __HCP_FUNC_EXIT(hr);
  817. }
  818. STDMETHODIMP CPCHSecurity::SetFileSD( /*[in]*/ BSTR bstrFilename ,
  819. /*[in]*/ IPCHSecurityDescriptor* sd )
  820. {
  821. __HCP_FUNC_ENTRY( "CPCHSecurity::SetFileSD" );
  822. HRESULT hr;
  823. MPC::Impersonation imp;
  824. __MPC_PARAMCHECK_BEGIN(hr)
  825. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrFilename);
  826. __MPC_PARAMCHECK_NOTNULL(sd);
  827. __MPC_PARAMCHECK_END();
  828. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Initialize ());
  829. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Impersonate());
  830. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptor::SetForFile( bstrFilename, sd ));
  831. hr = S_OK;
  832. __HCP_FUNC_CLEANUP;
  833. __HCP_FUNC_EXIT(hr);
  834. }
  835. STDMETHODIMP CPCHSecurity::GetRegistrySD( /*[in ]*/ BSTR bstrKey ,
  836. /*[out, retval]*/ IPCHSecurityDescriptor* *psd )
  837. {
  838. __HCP_FUNC_ENTRY( "CPCHSecurity::GetRegistrySD" );
  839. HRESULT hr;
  840. MPC::Impersonation imp;
  841. __MPC_PARAMCHECK_BEGIN(hr)
  842. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrKey);
  843. __MPC_PARAMCHECK_POINTER_AND_SET(psd,NULL);
  844. __MPC_PARAMCHECK_END();
  845. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Initialize ());
  846. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Impersonate());
  847. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptor::GetForRegistry( bstrKey, psd ));
  848. hr = S_OK;
  849. __HCP_FUNC_CLEANUP;
  850. __HCP_FUNC_EXIT(hr);
  851. }
  852. STDMETHODIMP CPCHSecurity::SetRegistrySD( /*[in]*/ BSTR bstrKey ,
  853. /*[in]*/ IPCHSecurityDescriptor* sd )
  854. {
  855. __HCP_FUNC_ENTRY( "CPCHSecurity::SetRegistrySD" );
  856. HRESULT hr;
  857. MPC::Impersonation imp;
  858. __MPC_PARAMCHECK_BEGIN(hr)
  859. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrKey);
  860. __MPC_PARAMCHECK_NOTNULL(sd);
  861. __MPC_PARAMCHECK_END();
  862. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Initialize ());
  863. __MPC_EXIT_IF_METHOD_FAILS(hr, imp.Impersonate());
  864. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurityDescriptor::SetForRegistry( bstrKey, sd ));
  865. hr = S_OK;
  866. __HCP_FUNC_CLEANUP;
  867. __HCP_FUNC_EXIT(hr);
  868. }