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.

984 lines
21 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. adminacl.cpp
  5. Abstract:
  6. Contains implementation of CAdminACL
  7. Author:
  8. ???
  9. Revision History:
  10. Mohit Srivastava 18-Dec-00
  11. --*/
  12. #define REF
  13. #define BUFFER_SIZE 512
  14. #include "iisprov.h"
  15. #include "adminacl.h"
  16. #include <adserr.h>
  17. CAdminACL::CAdminACL()
  18. {
  19. m_pADs = NULL;
  20. m_pSD = NULL;
  21. m_pDACL = NULL;
  22. bIsInherit = FALSE;
  23. }
  24. CAdminACL::~CAdminACL()
  25. {
  26. CloseSD();
  27. }
  28. void CAdminACL::CloseSD()
  29. {
  30. if(m_pDACL)
  31. {
  32. m_pDACL->Release();
  33. m_pDACL = NULL;
  34. }
  35. if(m_pSD)
  36. {
  37. m_pSD->Release();
  38. m_pSD = NULL;
  39. }
  40. if(m_pADs)
  41. {
  42. m_pADs->Release();
  43. m_pADs = NULL;
  44. }
  45. }
  46. HRESULT CAdminACL::GetObjectAsync(
  47. IWbemClassObject* pObj,
  48. ParsedObjectPath* pParsedObject,
  49. WMI_CLASS* pWMIClass)
  50. {
  51. DBG_ASSERT(m_pSD);
  52. DBG_ASSERT(m_pDACL);
  53. HRESULT hr = S_OK;
  54. if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL )
  55. {
  56. hr = PopulateWmiAdminACL(pObj);
  57. }
  58. else if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE )
  59. {
  60. _bstr_t bstrTrustee;
  61. GetTrustee(pObj, pParsedObject, bstrTrustee);
  62. CACEEnumOperation_FindAndReturn op(this, pObj, bstrTrustee, bIsInherit);
  63. hr = EnumACEsAndOp(REF op);
  64. }
  65. else
  66. {
  67. DBG_ASSERT(false && "Only valid on AdminACL and AdminACE classes");
  68. hr = E_INVALIDARG;
  69. }
  70. return hr;
  71. }
  72. HRESULT CAdminACL::EnumerateACEsAndIndicate(
  73. BSTR i_bstrNameValue,
  74. CWbemServices& i_refNamespace,
  75. IWbemObjectSink& i_refWbemObjectSink)
  76. {
  77. DBG_ASSERT(m_pSD);
  78. DBG_ASSERT(m_pDACL);
  79. CACEEnumOperation_IndicateAll op(
  80. i_bstrNameValue,
  81. REF i_refNamespace,
  82. REF i_refWbemObjectSink,
  83. bIsInherit);
  84. return EnumACEsAndOp(REF op);
  85. }
  86. HRESULT CAdminACL::DeleteObjectAsync(
  87. ParsedObjectPath* pParsedObject)
  88. {
  89. HRESULT hr = S_OK;
  90. _bstr_t bstrTrustee;
  91. //
  92. // get the trustee from key
  93. //
  94. GetTrustee(NULL, pParsedObject, bstrTrustee);
  95. //
  96. // remove the ACE
  97. //
  98. DBG_ASSERT(m_pDACL);
  99. CACEEnumOperation_FindAndRemove op(this, bstrTrustee);
  100. hr = EnumACEsAndOp(REF op);
  101. //
  102. // set the modified AdminACL back into the metabase
  103. //
  104. if(SUCCEEDED(hr))
  105. hr = SetSD();
  106. return hr;
  107. }
  108. HRESULT CAdminACL::PutObjectAsync(
  109. IWbemClassObject* pObj,
  110. ParsedObjectPath* pParsedObject,
  111. WMI_CLASS* pWMIClass)
  112. {
  113. DBG_ASSERT(m_pSD);
  114. DBG_ASSERT(m_pDACL);
  115. HRESULT hr = S_OK;
  116. if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL )
  117. {
  118. hr = SetADSIAdminACL(pObj);
  119. }
  120. else if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE )
  121. {
  122. _bstr_t bstrTrustee;
  123. GetTrustee(NULL, pParsedObject, bstrTrustee);
  124. CACEEnumOperation_FindAndUpdate op(this, pObj, bstrTrustee);
  125. hr = EnumACEsAndOp(REF op);
  126. if(hr == WBEM_E_NOT_FOUND)
  127. {
  128. hr = AddACE(pObj, bstrTrustee);
  129. }
  130. }
  131. else
  132. {
  133. DBG_ASSERT(false && "Only valid on AdminACL and AdminACE");
  134. hr = E_INVALIDARG;
  135. }
  136. // set the modified AdminACL back into the metabase
  137. if(SUCCEEDED(hr))
  138. hr = SetSD();
  139. return hr;
  140. }
  141. HRESULT CAdminACL::PopulateWmiAdminACL(
  142. IWbemClassObject* pObj
  143. )
  144. {
  145. VARIANT vt;
  146. HRESULT hr = S_OK;
  147. VARIANT vtTrue;
  148. vtTrue.boolVal = VARIANT_TRUE;
  149. vtTrue.vt = VT_BOOL;
  150. // Owner
  151. vt.vt = VT_BSTR;
  152. hr = m_pSD->get_Owner(&vt.bstrVal);
  153. if(SUCCEEDED(hr))
  154. {
  155. hr = pObj->Put(L"Owner", 0, &vt, 0);
  156. VariantClear(&vt);
  157. }
  158. if(bIsInherit && SUCCEEDED(hr))
  159. {
  160. hr = CUtils::SetPropertyQualifiers(
  161. pObj, L"Owner", &g_wszIsInherit, &vtTrue, 1);
  162. }
  163. // Group
  164. vt.vt = VT_BSTR;
  165. if(SUCCEEDED(hr))
  166. hr = m_pSD->get_Group(&vt.bstrVal);
  167. if(SUCCEEDED(hr))
  168. {
  169. hr = pObj->Put(L"Group", 0, &vt, 0);
  170. VariantClear(&vt);
  171. }
  172. if(bIsInherit && SUCCEEDED(hr))
  173. {
  174. hr = CUtils::SetPropertyQualifiers(
  175. pObj, L"Group", &g_wszIsInherit, &vtTrue, 1);
  176. }
  177. // ControlFlags
  178. vt.vt = VT_I4;
  179. if(SUCCEEDED(hr))
  180. hr = m_pSD->get_Control(&vt.lVal);
  181. if(SUCCEEDED(hr))
  182. {
  183. hr = pObj->Put(L"ControlFlags", 0, &vt, 0);
  184. VariantClear(&vt);
  185. }
  186. if(bIsInherit && SUCCEEDED(hr))
  187. {
  188. hr = CUtils::SetPropertyQualifiers(
  189. pObj, L"ControlFlags", &g_wszIsInherit, &vtTrue, 1);
  190. }
  191. return hr;
  192. }
  193. HRESULT CAdminACL::SetADSIAdminACL(
  194. IWbemClassObject* pObj
  195. )
  196. {
  197. VARIANT vt;
  198. HRESULT hr;
  199. // Owner
  200. hr = pObj->Get(L"Owner", 0, &vt, NULL, NULL);
  201. if(SUCCEEDED(hr) && vt.vt == VT_BSTR)
  202. hr = m_pSD->put_Owner(vt.bstrVal);
  203. VariantClear(&vt);
  204. // Owner
  205. if(SUCCEEDED(hr))
  206. hr = pObj->Get(L"Group", 0, &vt, NULL, NULL);
  207. if(SUCCEEDED(hr) && vt.vt == VT_BSTR)
  208. hr = m_pSD->put_Group(vt.bstrVal);
  209. VariantClear(&vt);
  210. // ControlFlags
  211. if(SUCCEEDED(hr))
  212. hr = pObj->Get(L"ControlFlags", 0, &vt, NULL, NULL);
  213. if(SUCCEEDED(hr) && vt.vt == VT_I4)
  214. hr = m_pSD->put_Control(vt.lVal);
  215. VariantClear(&vt);
  216. if(FAILED(hr))
  217. {
  218. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  219. }
  220. return hr;
  221. }
  222. HRESULT CAdminACL::OpenSD(
  223. LPCWSTR wszMbPath,
  224. IMSAdminBase2* pAdminBase)
  225. {
  226. DBG_ASSERT(wszMbPath);
  227. CComVariant svar;
  228. METADATA_HANDLE hObjHandle = NULL;
  229. HRESULT hr = S_OK;
  230. DWORD dwBufferSize = 0;
  231. METADATA_RECORD mdrMDData;
  232. BYTE pBuffer[BUFFER_SIZE];
  233. // close SD interface first
  234. CloseSD();
  235. CComBSTR sbstrAdsPath;
  236. hr = GetAdsPath(wszMbPath, &sbstrAdsPath);
  237. if(FAILED(hr))
  238. {
  239. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  240. return hr;
  241. }
  242. // get m_pADs
  243. hr = ADsGetObject(
  244. sbstrAdsPath,
  245. IID_IADs,
  246. (void**)&m_pADs
  247. );
  248. if(FAILED(hr))
  249. {
  250. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  251. return hr;
  252. }
  253. // get m_pSD
  254. hr = m_pADs->Get(L"AdminACL",&svar);
  255. if(FAILED(hr))
  256. {
  257. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  258. if(hr == E_ADS_PROPERTY_NOT_SUPPORTED)
  259. {
  260. //
  261. // Do this, so WMI does not fail query operations.
  262. //
  263. hr = WBEM_E_NOT_FOUND;
  264. }
  265. return hr;
  266. }
  267. hr = V_DISPATCH(&svar)->QueryInterface(
  268. IID_IADsSecurityDescriptor,
  269. (void**)&m_pSD
  270. );
  271. if(FAILED(hr))
  272. {
  273. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  274. return hr;
  275. }
  276. // get m_pDACL
  277. CComPtr<IDispatch> spDisp;
  278. hr = m_pSD->get_DiscretionaryAcl(&spDisp);
  279. if(FAILED(hr))
  280. {
  281. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  282. return hr;
  283. }
  284. hr = spDisp->QueryInterface(
  285. IID_IADsAccessControlList,
  286. (void**)&m_pDACL
  287. );
  288. if(FAILED(hr))
  289. {
  290. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  291. return hr;
  292. }
  293. // set bIsInherit
  294. hr = pAdminBase->OpenKey(
  295. METADATA_MASTER_ROOT_HANDLE,
  296. wszMbPath,
  297. METADATA_PERMISSION_READ,
  298. DEFAULT_TIMEOUT_VALUE,
  299. &hObjHandle
  300. );
  301. if(FAILED(hr))
  302. return hr;
  303. MD_SET_DATA_RECORD(&mdrMDData,
  304. MD_ADMIN_ACL, // ID for "AdminAcl"
  305. METADATA_INHERIT | METADATA_ISINHERITED,
  306. ALL_METADATA,
  307. ALL_METADATA,
  308. BUFFER_SIZE,
  309. pBuffer);
  310. hr = pAdminBase->GetData(
  311. hObjHandle,
  312. L"",
  313. &mdrMDData,
  314. &dwBufferSize
  315. );
  316. hr = S_OK;
  317. bIsInherit = mdrMDData.dwMDAttributes & METADATA_ISINHERITED;
  318. if (hObjHandle && pAdminBase) {
  319. pAdminBase->CloseKey(hObjHandle);
  320. }
  321. return hr;
  322. }
  323. HRESULT CAdminACL::SetSD()
  324. {
  325. VARIANT var;
  326. HRESULT hr = S_OK;
  327. IDispatch* pDisp = NULL;
  328. // put m_pDACL
  329. hr = m_pDACL->QueryInterface(
  330. IID_IDispatch,
  331. (void**)&pDisp
  332. );
  333. if(FAILED(hr))
  334. return hr;
  335. hr = m_pSD->put_DiscretionaryAcl(pDisp);
  336. pDisp->Release();
  337. if(FAILED(hr))
  338. return hr;
  339. //
  340. // put AdminACL
  341. //
  342. hr = m_pSD->QueryInterface(
  343. IID_IDispatch,
  344. (void**)&pDisp
  345. );
  346. if(FAILED(hr))
  347. return hr;
  348. VariantInit(&var);
  349. var.vt = VT_DISPATCH;
  350. var.pdispVal = pDisp;
  351. hr = m_pADs->Put(L"AdminACL",var); // pDisp will be released by this call Put().
  352. if(FAILED(hr))
  353. return hr;
  354. //
  355. // Commit the change to the active directory
  356. //
  357. hr = m_pADs->SetInfo();
  358. return hr;
  359. }
  360. HRESULT CAdminACL::GetAdsPath(
  361. LPCWSTR i_wszMbPath,
  362. BSTR* o_pbstrAdsPath)
  363. {
  364. DBG_ASSERT(i_wszMbPath);
  365. DBG_ASSERT(o_pbstrAdsPath);
  366. DBG_ASSERT(*o_pbstrAdsPath == NULL);
  367. CComBSTR sbstr(L"IIS://LocalHost");
  368. if(sbstr.m_str == NULL)
  369. {
  370. return WBEM_E_OUT_OF_MEMORY;
  371. }
  372. //
  373. // trim the first three characters "/LM"
  374. //
  375. sbstr += (i_wszMbPath+3);
  376. if(sbstr.m_str == NULL)
  377. {
  378. return WBEM_E_OUT_OF_MEMORY;
  379. }
  380. //
  381. // Set out params if everything succeeds
  382. //
  383. *o_pbstrAdsPath = sbstr.Detach();
  384. return S_OK;
  385. }
  386. HRESULT CAdminACL::EnumACEsAndOp(
  387. CACEEnumOperation_Base& refOp)
  388. /*++
  389. Synopsis:
  390. This enumerates all the aces for the current acl.
  391. Arguments: [refOp] - Implements Do, and Done. It is okay if Do throws exceptions.
  392. This function will cleanup correctly.
  393. Return Value:
  394. --*/
  395. {
  396. HRESULT hr = S_OK;
  397. CComVariant var;
  398. CComPtr<IEnumVARIANT> spEnum;
  399. ULONG lFetch;
  400. CComPtr<IADsAccessControlEntry> spACE;
  401. hr = GetACEEnum(&spEnum);
  402. if ( FAILED(hr) )
  403. return hr;
  404. //
  405. // Enumerate ACEs
  406. //
  407. hr = spEnum->Next( 1, &var, &lFetch );
  408. while( hr == S_OK )
  409. {
  410. if (lFetch == 1)
  411. {
  412. if (VT_DISPATCH != V_VT(&var))
  413. {
  414. hr = E_UNEXPECTED;
  415. break;
  416. }
  417. //
  418. // Get the individual ACE
  419. //
  420. hr = V_DISPATCH(&var)->QueryInterface(
  421. IID_IADsAccessControlEntry,
  422. (void**)&spACE);
  423. if ( SUCCEEDED(hr) )
  424. {
  425. hr = refOp.Do(spACE);
  426. if(FAILED(hr))
  427. {
  428. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  429. return hr;
  430. }
  431. if(refOp.Done() == CACEEnumOperation_Base::eDONE_YES)
  432. {
  433. break;
  434. }
  435. spACE = NULL;
  436. }
  437. }
  438. var.Clear();
  439. hr = spEnum->Next( 1, &var, &lFetch );
  440. if(hr == S_FALSE && refOp.Done() == CACEEnumOperation_Base::eDONE_NO)
  441. {
  442. hr = WBEM_E_NOT_FOUND;
  443. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  444. return hr;
  445. }
  446. }
  447. return hr;
  448. }
  449. void CAdminACL::GetTrustee(
  450. IWbemClassObject* pObj,
  451. ParsedObjectPath* pPath,
  452. _bstr_t& bstrTrustee
  453. )
  454. /*++
  455. Synopsis:
  456. parse ParsedObjectPath to get the Trustee key
  457. Arguments: [pObj] -
  458. [pPath] -
  459. [bstrTrustee] -
  460. --*/
  461. {
  462. KeyRef* pkr;
  463. WCHAR* pszKey = L"Trustee";
  464. VARIANT vtTrue;
  465. vtTrue.boolVal = VARIANT_TRUE;
  466. vtTrue.vt = VT_BOOL;
  467. pkr = CUtils::GetKey(pPath, pszKey);
  468. if(pkr->m_vValue.vt == VT_BSTR && pkr->m_vValue.bstrVal != NULL)
  469. {
  470. bstrTrustee = pkr->m_vValue;
  471. }
  472. else
  473. {
  474. THROW_ON_ERROR(WBEM_E_INVALID_OBJECT);
  475. }
  476. if (pObj)
  477. {
  478. _bstr_t bstr = pkr->m_pName;
  479. HRESULT hr = pObj->Put(bstr, 0, &pkr->m_vValue, 0);
  480. THROW_ON_ERROR(hr);
  481. if(bIsInherit && SUCCEEDED(hr))
  482. {
  483. hr = CUtils::SetPropertyQualifiers(
  484. pObj, L"Trustee", &g_wszIsInherit, &vtTrue, 1);
  485. THROW_ON_ERROR(hr);
  486. }
  487. }
  488. }
  489. HRESULT CAdminACL::GetACEEnum(
  490. IEnumVARIANT** pEnum)
  491. {
  492. HRESULT hr = S_OK;
  493. LPUNKNOWN pUnk = NULL;
  494. DBG_ASSERT(pEnum);
  495. if(*pEnum)
  496. {
  497. (*pEnum)->Release();
  498. }
  499. hr = m_pDACL->get__NewEnum( &pUnk );
  500. if ( SUCCEEDED(hr) )
  501. {
  502. hr = pUnk->QueryInterface( IID_IEnumVARIANT, (void**) pEnum );
  503. }
  504. return hr;
  505. }
  506. HRESULT CAdminACL::AddACE(
  507. IWbemClassObject* pObj,
  508. _bstr_t& bstrTrustee
  509. )
  510. /*++
  511. Synopsis:
  512. Add an ACE.
  513. Arguments: [pObj] -
  514. [bstrTrustee] -
  515. Return Value:
  516. --*/
  517. {
  518. HRESULT hr = m_pDACL->put_AclRevision(ADS_SD_REVISION_DS);
  519. if(FAILED(hr))
  520. {
  521. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  522. return hr;
  523. }
  524. // create a ACE
  525. IADsAccessControlEntry* pACE = NULL;
  526. hr = NewACE(
  527. pObj,
  528. bstrTrustee,
  529. &pACE);
  530. if(FAILED(hr))
  531. {
  532. DBGPRINTF((DBG_CONTEXT, "Failed, hr: 0x%x\n", hr));
  533. return hr;
  534. }
  535. // add the ACE
  536. IDispatch* pDisp = NULL;
  537. hr = pACE->QueryInterface(IID_IDispatch,(void**)&pDisp);
  538. if(SUCCEEDED(hr))
  539. {
  540. hr = m_pDACL->AddAce(pDisp);
  541. pDisp->Release();
  542. }
  543. pACE->Release();
  544. return hr;
  545. }
  546. HRESULT CAdminACL::NewACE(
  547. IWbemClassObject* pObj,
  548. _bstr_t& bstrTrustee,
  549. IADsAccessControlEntry** ppACE
  550. )
  551. /*++
  552. Synopsis:
  553. function to create an ACE
  554. Arguments: [pObj] -
  555. [bstrTrustee] -
  556. [ppACE] -
  557. Return Value:
  558. --*/
  559. {
  560. DBG_ASSERT(ppACE);
  561. HRESULT hr = CoCreateInstance(
  562. CLSID_AccessControlEntry,
  563. NULL,
  564. CLSCTX_INPROC_SERVER,
  565. IID_IADsAccessControlEntry,
  566. (void**)ppACE);
  567. //
  568. // Trustee
  569. //
  570. if(SUCCEEDED(hr))
  571. hr = (*ppACE)->put_Trustee(bstrTrustee);
  572. if(SUCCEEDED(hr))
  573. hr = SetDataOfACE(pObj, *ppACE);
  574. return hr;
  575. }
  576. HRESULT CAdminACL::SetDataOfACE(
  577. IWbemClassObject* pObj,
  578. IADsAccessControlEntry* pACE
  579. )
  580. {
  581. HRESULT hr;
  582. CComVariant vt;
  583. //
  584. // AccessMask
  585. //
  586. hr = pObj->Get(L"AccessMask", 0, &vt, NULL, NULL);
  587. if(SUCCEEDED(hr) && vt.vt == VT_I4)
  588. hr = pACE->put_AccessMask(vt.lVal);
  589. vt.Clear();
  590. //
  591. // AceType
  592. //
  593. if(SUCCEEDED(hr))
  594. hr = pObj->Get(L"AceType", 0, &vt, NULL, NULL);
  595. if(SUCCEEDED(hr) && vt.vt == VT_I4)
  596. hr = pACE->put_AceType(vt.lVal);
  597. vt.Clear();
  598. //
  599. // AceFlags
  600. //
  601. if(SUCCEEDED(hr))
  602. hr = pObj->Get(L"AceFlags", 0, &vt, NULL, NULL);
  603. if(SUCCEEDED(hr) && vt.vt == VT_I4)
  604. hr = pACE->put_AceFlags(vt.lVal);
  605. vt.Clear();
  606. //
  607. // Flags
  608. //
  609. if(SUCCEEDED(hr))
  610. hr = pObj->Get(L"Flags", 0, &vt, NULL, NULL);
  611. if(SUCCEEDED(hr) && vt.vt == VT_I4)
  612. hr = pACE->put_Flags(vt.lVal);
  613. vt.Clear();
  614. //
  615. // ObjectType
  616. //
  617. if(SUCCEEDED(hr))
  618. hr = pObj->Get(L"ObjectType", 0, &vt, NULL, NULL);
  619. if(SUCCEEDED(hr) && vt.vt == VT_BSTR)
  620. hr = pACE->put_ObjectType(vt.bstrVal);
  621. vt.Clear();
  622. //
  623. // InheritedObjectType
  624. //
  625. if(SUCCEEDED(hr))
  626. hr = pObj->Get(L"InheritedObjectType", 0, &vt, NULL, NULL);
  627. if(SUCCEEDED(hr) && vt.vt == VT_BSTR)
  628. hr = pACE->put_InheritedObjectType(vt.bstrVal);
  629. vt.Clear();
  630. return hr;
  631. }
  632. //
  633. // CACEEnumOperation_Base
  634. //
  635. HRESULT CACEEnumOperation_Base::PopulateWmiACE(
  636. IWbemClassObject* pObj,
  637. IADsAccessControlEntry* pACE,
  638. BOOL bIsInherit
  639. )
  640. {
  641. _variant_t vt;
  642. BSTR bstr;
  643. long lVal;
  644. HRESULT hr;
  645. VARIANT vtTrue;
  646. vtTrue.boolVal = VARIANT_TRUE;
  647. vtTrue.vt = VT_BOOL;
  648. // AccessMask
  649. hr = pACE->get_AccessMask(&lVal);
  650. if(SUCCEEDED(hr))
  651. {
  652. vt.vt = VT_I4;
  653. vt.lVal = lVal;
  654. hr = pObj->Put(L"AccessMask", 0, &vt, 0);
  655. if(bIsInherit && SUCCEEDED(hr))
  656. {
  657. hr = CUtils::SetPropertyQualifiers(
  658. pObj, L"AccessMask", &g_wszIsInherit, &vtTrue, 1);
  659. }
  660. }
  661. // AceType
  662. if(SUCCEEDED(hr))
  663. hr = pACE->get_AceType(&lVal);
  664. if(SUCCEEDED(hr))
  665. {
  666. vt.vt = VT_I4;
  667. vt.lVal = lVal;
  668. hr = pObj->Put(L"AceType", 0, &vt, 0);
  669. if(bIsInherit && SUCCEEDED(hr))
  670. {
  671. hr = CUtils::SetPropertyQualifiers(
  672. pObj, L"AceType", &g_wszIsInherit, &vtTrue, 1);
  673. }
  674. }
  675. // AceFlags
  676. if(SUCCEEDED(hr))
  677. hr = pACE->get_AceFlags(&lVal);
  678. if(SUCCEEDED(hr))
  679. {
  680. vt.vt = VT_I4;
  681. vt.lVal = lVal;
  682. hr = pObj->Put(L"AceFlags", 0, &vt, 0);
  683. if(bIsInherit && SUCCEEDED(hr))
  684. {
  685. hr = CUtils::SetPropertyQualifiers(
  686. pObj, L"AceFlags", &g_wszIsInherit, &vtTrue, 1);
  687. }
  688. }
  689. // Flags
  690. if(SUCCEEDED(hr))
  691. hr = pACE->get_Flags(&lVal);
  692. if(SUCCEEDED(hr))
  693. {
  694. vt.vt = VT_I4;
  695. vt.lVal = lVal;
  696. hr = pObj->Put(L"Flags", 0, &vt, 0);
  697. if(bIsInherit && SUCCEEDED(hr))
  698. {
  699. hr = CUtils::SetPropertyQualifiers(
  700. pObj, L"Flags", &g_wszIsInherit, &vtTrue, 1);
  701. }
  702. }
  703. // ObjectType
  704. if(SUCCEEDED(hr))
  705. hr = pACE->get_ObjectType(&bstr);
  706. if(SUCCEEDED(hr))
  707. {
  708. vt = bstr;
  709. hr = pObj->Put(L"ObjectType", 0, &vt, 0);
  710. if(bIsInherit && SUCCEEDED(hr))
  711. {
  712. hr = CUtils::SetPropertyQualifiers(
  713. pObj, L"ObjectType", &g_wszIsInherit, &vtTrue, 1);
  714. }
  715. SysFreeString(bstr);
  716. }
  717. // InheritedObjectType
  718. if(SUCCEEDED(hr))
  719. hr = pACE->get_InheritedObjectType(&bstr);
  720. if(SUCCEEDED(hr))
  721. {
  722. vt = bstr;
  723. hr = pObj->Put(L"InheritedObjectType", 0, &vt, 0);
  724. if(bIsInherit && SUCCEEDED(hr))
  725. {
  726. hr = CUtils::SetPropertyQualifiers(
  727. pObj, L"InheritedObjectType", &g_wszIsInherit, &vtTrue, 1);
  728. }
  729. SysFreeString(bstr);
  730. }
  731. return hr;
  732. }
  733. //
  734. // CACEEnumOperation_IndicateAll
  735. //
  736. HRESULT CAdminACL::CACEEnumOperation_IndicateAll::Do(
  737. IADsAccessControlEntry* pACE)
  738. {
  739. DBG_ASSERT(pACE);
  740. if(FAILED(m_hr))
  741. {
  742. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", m_hr));
  743. return m_hr;
  744. }
  745. CComPtr<IWbemClassObject> spInstance;
  746. HRESULT hr = m_spClass->SpawnInstance(0, &spInstance);
  747. if(FAILED(hr))
  748. {
  749. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  750. return hr;
  751. }
  752. hr = spInstance->Put(
  753. WMI_CLASS_DATA::s_ACE.pszKeyName,
  754. 0,
  755. &m_vNameValue,
  756. 0);
  757. if(FAILED(hr))
  758. {
  759. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  760. return hr;
  761. }
  762. CComBSTR sbstrTrustee;
  763. hr = pACE->get_Trustee(&sbstrTrustee);
  764. if(FAILED(hr))
  765. {
  766. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  767. return hr;
  768. }
  769. VARIANT vTrustee;
  770. vTrustee.bstrVal = sbstrTrustee;
  771. vTrustee.vt = VT_BSTR;
  772. hr = spInstance->Put(L"Trustee", 0, &vTrustee, 0);
  773. if(FAILED(hr))
  774. {
  775. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  776. return hr;
  777. }
  778. hr = PopulateWmiACE(spInstance, pACE, bLocalIsInherit);
  779. if(FAILED(hr))
  780. {
  781. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  782. return hr;
  783. }
  784. hr = m_pWbemObjectSink->Indicate(1, &spInstance);
  785. if(FAILED(hr))
  786. {
  787. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  788. return hr;
  789. }
  790. return hr;
  791. }
  792. //
  793. // CACEEnumOperation_Find
  794. //
  795. HRESULT CAdminACL::CACEEnumOperation_Find::Do(
  796. IADsAccessControlEntry* pACE)
  797. {
  798. DBG_ASSERT(pACE);
  799. DBG_ASSERT(m_eDone == eDONE_NO);
  800. CComBSTR sbstr;
  801. HRESULT hr = pACE->get_Trustee(&sbstr);
  802. if(FAILED(hr))
  803. {
  804. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  805. return hr;
  806. }
  807. if(_wcsicmp(sbstr, m_bstrTrustee) == 0)
  808. {
  809. m_eDone = eDONE_YES;
  810. hr = DoOnMatch(pACE);
  811. if(FAILED(hr))
  812. {
  813. DBGPRINTF((DBG_CONTEXT, "Failure, hr=0x%x\n", hr));
  814. return hr;
  815. }
  816. }
  817. return hr;
  818. }