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.

1433 lines
37 KiB

  1. #include "headers.h"
  2. /*****************************************************************************
  3. *****************************************************************************/
  4. template<class IAzInterface>
  5. CBaseAzImpl<IAzInterface>
  6. ::CBaseAzImpl(CComPtr<IAzInterface>& spAzInterface,
  7. OBJECT_TYPE_AZ eObjectType,
  8. CContainerAz* pParentContainerAz)
  9. :CBaseAz(eObjectType,pParentContainerAz),
  10. m_spAzInterface(spAzInterface)
  11. {
  12. }
  13. template<class IAzInterface>
  14. CBaseAzImpl<IAzInterface>::~CBaseAzImpl()
  15. {
  16. }
  17. template<class IAzInterface>
  18. HRESULT
  19. CBaseAzImpl<IAzInterface>::SetProperty(LONG lPropId, const CString& strPropValue)
  20. {
  21. CComBSTR bstr = strPropValue;
  22. CComVariant var = bstr;
  23. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  24. var,
  25. CComVariant());
  26. CHECK_HRESULT(hr);
  27. return hr;
  28. }
  29. template<class IAzInterface>
  30. HRESULT
  31. CBaseAzImpl<IAzInterface>::GetProperty(LONG lPropId, CString* pstrPropValue)
  32. {
  33. CComVariant varName;
  34. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  35. CComVariant(),
  36. &varName);
  37. if(SUCCEEDED(hr))
  38. {
  39. ASSERT(varName.vt == VT_BSTR);
  40. *pstrPropValue = varName.bstrVal;
  41. }
  42. CHECK_HRESULT(hr);
  43. return hr;
  44. }
  45. template<class IAzInterface>
  46. HRESULT
  47. CBaseAzImpl<IAzInterface>::SetProperty(LONG lPropId, BOOL bValue)
  48. {
  49. CComVariant varValue = bValue;
  50. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  51. varValue,
  52. CComVariant());
  53. CHECK_HRESULT(hr);
  54. return hr;
  55. }
  56. template<class IAzInterface>
  57. HRESULT
  58. CBaseAzImpl<IAzInterface>::GetProperty(LONG lPropId, BOOL* pbValue)
  59. {
  60. CComVariant varName;
  61. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  62. CComVariant(),
  63. &varName);
  64. if(SUCCEEDED(hr))
  65. {
  66. ASSERT(varName.vt == VT_BOOL);
  67. *pbValue = (varName.boolVal == VARIANT_TRUE);
  68. }
  69. CHECK_HRESULT(hr);
  70. return hr;
  71. }
  72. template<class IAzInterface>
  73. HRESULT
  74. CBaseAzImpl<IAzInterface>::SetProperty(LONG lPropId, LONG lValue)
  75. {
  76. CComVariant varName = lValue;
  77. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  78. varName,
  79. CComVariant());
  80. CHECK_HRESULT(hr);
  81. return hr;
  82. }
  83. template<class IAzInterface>
  84. HRESULT
  85. CBaseAzImpl<IAzInterface>::GetProperty(LONG lPropId, LONG* plValue)
  86. {
  87. CComVariant varName;
  88. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  89. CComVariant(),
  90. &varName);
  91. if(SUCCEEDED(hr))
  92. {
  93. ASSERT(varName.vt == VT_I4);
  94. *plValue = varName.lVal;
  95. }
  96. CHECK_HRESULT(hr);
  97. return hr;
  98. }
  99. template<class IAzInterface>
  100. const CString&
  101. CBaseAzImpl<IAzInterface>::GetName()
  102. {
  103. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAzImpl,GetName)
  104. if(!m_strName.IsEmpty())
  105. return m_strName;
  106. CComVariant varName;
  107. GetProperty(AZ_PROP_NAME, &m_strName);
  108. return m_strName;
  109. }
  110. template<class IAzInterface>
  111. HRESULT
  112. CBaseAzImpl<IAzInterface>::SetName(const CString& strName)
  113. {
  114. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAzImpl,SetName)
  115. ASSERT(!strName.IsEmpty());
  116. HRESULT hr = SetProperty(AZ_PROP_NAME,strName);
  117. if(SUCCEEDED(hr))
  118. m_strName = strName;
  119. return hr;
  120. }
  121. template<class IAzInterface>
  122. const CString&
  123. CBaseAzImpl<IAzInterface>::GetDescription()
  124. {
  125. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAzImpl,GetDescription)
  126. CComVariant varDesc;
  127. if(!m_strDescription.IsEmpty())
  128. return m_strDescription;
  129. HRESULT hr = m_spAzInterface->GetProperty(AZ_PROP_DESCRIPTION,
  130. CComVariant(),
  131. &varDesc);
  132. if(SUCCEEDED(hr))
  133. {
  134. ASSERT(varDesc.vt == VT_BSTR);
  135. m_strDescription = varDesc.bstrVal;
  136. return m_strDescription;
  137. }
  138. else
  139. {
  140. DBG_OUT_HRESULT(hr);
  141. return m_strDescription;
  142. }
  143. }
  144. template<class IAzInterface>
  145. HRESULT
  146. CBaseAzImpl<IAzInterface>::SetDescription(const CString& strDesc)
  147. {
  148. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAzImpl,SetDescription)
  149. ASSERT(!strDesc.IsEmpty());
  150. CComBSTR bstrDesc = strDesc;
  151. CComVariant varDesc = bstrDesc;
  152. VARIANTARG dest;
  153. VariantInit(&dest);
  154. HRESULT hr1 = VariantChangeType(&dest,&varDesc,0,VT_BSTR);
  155. HRESULT hr = m_spAzInterface->SetProperty(AZ_PROP_DESCRIPTION,
  156. varDesc,
  157. CComVariant());
  158. if(SUCCEEDED(hr))
  159. m_strDescription = varDesc.bstrVal;
  160. CHECK_HRESULT(hr);
  161. return hr;
  162. }
  163. template<class IAzInterface>
  164. HRESULT
  165. CBaseAzImpl<IAzInterface>::Submit()
  166. {
  167. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAzImpl,Submit)
  168. HRESULT hr = m_spAzInterface->Submit(0, CComVariant());
  169. CHECK_HRESULT(hr);
  170. return hr;
  171. }
  172. template<class IAzInterface>
  173. HRESULT
  174. CBaseAzImpl<IAzInterface>::Clear()
  175. {
  176. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAzImpl,Submit)
  177. HRESULT hr = m_spAzInterface->Submit(AZ_SUBMIT_FLAG_ABORT, CComVariant());
  178. CHECK_HRESULT(hr);
  179. return hr;
  180. }
  181. /*****************************************************************************
  182. *****************************************************************************/
  183. template<class IAzInterface>
  184. CContainerAzImpl<IAzInterface>
  185. ::CContainerAzImpl(CComPtr<IAzInterface>& spAzInterface,
  186. OBJECT_TYPE_AZ eObjectType,
  187. CContainerAz* pParentContainerAz)
  188. :CContainerAz(eObjectType,pParentContainerAz),
  189. m_spAzInterface(spAzInterface)
  190. {
  191. }
  192. template<class IAzInterface>
  193. CContainerAzImpl<IAzInterface>::~CContainerAzImpl()
  194. {
  195. }
  196. template<class IAzInterface>
  197. HRESULT
  198. CContainerAzImpl<IAzInterface>::SetProperty(LONG lPropId, const CString& strPropValue)
  199. {
  200. CComBSTR bstr = strPropValue;
  201. CComVariant var = bstr;
  202. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  203. var,
  204. CComVariant());
  205. CHECK_HRESULT(hr);
  206. return hr;
  207. }
  208. template<class IAzInterface>
  209. HRESULT
  210. CContainerAzImpl<IAzInterface>::GetProperty(LONG lPropId, CString* pstrPropValue)
  211. {
  212. CComVariant varName;
  213. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  214. CComVariant(),
  215. &varName);
  216. if(SUCCEEDED(hr))
  217. {
  218. ASSERT(varName.vt == VT_BSTR);
  219. *pstrPropValue = varName.bstrVal;
  220. }
  221. CHECK_HRESULT(hr);
  222. return hr;
  223. }
  224. template<class IAzInterface>
  225. HRESULT
  226. CContainerAzImpl<IAzInterface>::SetProperty(LONG lPropId, BOOL bValue)
  227. {
  228. CComVariant varValue = bValue;
  229. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  230. varValue,
  231. CComVariant());
  232. CHECK_HRESULT(hr);
  233. return hr;
  234. }
  235. template<class IAzInterface>
  236. HRESULT
  237. CContainerAzImpl<IAzInterface>::GetProperty(LONG lPropId, BOOL* pbValue)
  238. {
  239. CComVariant varName;
  240. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  241. CComVariant(),
  242. &varName);
  243. if(SUCCEEDED(hr))
  244. {
  245. ASSERT(varName.vt == VT_BOOL);
  246. *pbValue = (varName.boolVal == VARIANT_TRUE);
  247. }
  248. CHECK_HRESULT(hr);
  249. return hr;
  250. }
  251. template<class IAzInterface>
  252. HRESULT
  253. CContainerAzImpl<IAzInterface>::SetProperty(LONG lPropId, LONG lValue)
  254. {
  255. CComVariant varName = lValue;
  256. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  257. varName,
  258. CComVariant());
  259. CHECK_HRESULT(hr);
  260. return hr;
  261. }
  262. template<class IAzInterface>
  263. HRESULT
  264. CContainerAzImpl<IAzInterface>::GetProperty(LONG lPropId, LONG* plValue)
  265. {
  266. CComVariant varName;
  267. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  268. CComVariant(),
  269. &varName);
  270. if(SUCCEEDED(hr))
  271. {
  272. ASSERT(varName.vt == VT_I4);
  273. *plValue = varName.lVal;
  274. }
  275. CHECK_HRESULT(hr);
  276. return hr;
  277. }
  278. template<class IAzInterface>
  279. const CString&
  280. CContainerAzImpl<IAzInterface>::GetName()
  281. {
  282. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,GetName)
  283. if(!m_strName.IsEmpty())
  284. return m_strName;
  285. CComVariant varName;
  286. GetProperty(AZ_PROP_NAME, &m_strName);
  287. return m_strName;
  288. }
  289. template<class IAzInterface>
  290. HRESULT
  291. CContainerAzImpl<IAzInterface>::SetName(const CString& strName)
  292. {
  293. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,SetName)
  294. ASSERT(!strName.IsEmpty());
  295. HRESULT hr = SetProperty(AZ_PROP_NAME,strName);
  296. if(SUCCEEDED(hr))
  297. m_strName = strName;
  298. return hr;
  299. }
  300. template<class IAzInterface>
  301. const CString&
  302. CContainerAzImpl<IAzInterface>::GetDescription()
  303. {
  304. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,GetDescription)
  305. CComVariant varDesc;
  306. if(!m_strDescription.IsEmpty())
  307. return m_strDescription;
  308. HRESULT hr = m_spAzInterface->GetProperty(AZ_PROP_DESCRIPTION,
  309. CComVariant(),
  310. &varDesc);
  311. if(SUCCEEDED(hr))
  312. {
  313. ASSERT(varDesc.vt == VT_BSTR);
  314. m_strDescription = varDesc.bstrVal;
  315. return m_strDescription;
  316. }
  317. else
  318. {
  319. DBG_OUT_HRESULT(hr);
  320. return m_strDescription;
  321. }
  322. }
  323. template<class IAzInterface>
  324. HRESULT
  325. CContainerAzImpl<IAzInterface>::SetDescription(const CString& strDesc)
  326. {
  327. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,SetDescription)
  328. ASSERT(!strDesc.IsEmpty());
  329. CComBSTR bstrDesc = strDesc;
  330. CComVariant varDesc = bstrDesc;
  331. VARIANTARG dest;
  332. VariantInit(&dest);
  333. HRESULT hr1 = VariantChangeType(&dest,&varDesc,0,VT_BSTR);
  334. HRESULT hr = m_spAzInterface->SetProperty(AZ_PROP_DESCRIPTION,
  335. varDesc,
  336. CComVariant());
  337. if(SUCCEEDED(hr))
  338. m_strDescription = varDesc.bstrVal;
  339. CHECK_HRESULT(hr);
  340. return hr;
  341. }
  342. template<class IAzInterface>
  343. HRESULT
  344. CContainerAzImpl<IAzInterface>::Submit()
  345. {
  346. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,Submit)
  347. HRESULT hr = m_spAzInterface->Submit(0, CComVariant());
  348. CHECK_HRESULT(hr);
  349. return hr;
  350. }
  351. template<class IAzInterface>
  352. HRESULT
  353. CContainerAzImpl<IAzInterface>::Clear()
  354. {
  355. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,Submit)
  356. HRESULT hr = m_spAzInterface->Submit(AZ_SUBMIT_FLAG_ABORT, CComVariant());
  357. CHECK_HRESULT(hr);
  358. return hr;
  359. }
  360. template<class IAzInterface>
  361. HRESULT
  362. CContainerAzImpl<IAzInterface>::
  363. CreateGroup(const CString& strGroupName, CGroupAz** ppGroupAz)
  364. {
  365. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,CreateGroup)
  366. if(strGroupName.IsEmpty() || !ppGroupAz)
  367. {
  368. ASSERT(!strGroupName.IsEmpty());
  369. ASSERT(ppGroupAz);
  370. return E_INVALIDARG;
  371. }
  372. CComBSTR bstrName = strGroupName;
  373. HRESULT hr = S_OK;
  374. CComPtr<IAzApplicationGroup> spGroup;
  375. hr = m_spAzInterface->CreateApplicationGroup(bstrName,
  376. CComVariant(), //Reserved
  377. &spGroup);
  378. if(FAILED(hr))
  379. {
  380. DBG_OUT_HRESULT(hr);
  381. return hr;
  382. }
  383. *ppGroupAz = new CGroupAz(spGroup,this);
  384. if(!*ppGroupAz)
  385. {
  386. hr = E_OUTOFMEMORY;
  387. return hr;
  388. }
  389. return S_OK;
  390. }
  391. template<class IAzInterface>
  392. HRESULT
  393. CContainerAzImpl<IAzInterface>::
  394. OpenGroup(const CString& strGroupName, CGroupAz** ppGroupAz)
  395. {
  396. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,OpenGroup);
  397. if(strGroupName.IsEmpty() || !ppGroupAz)
  398. {
  399. ASSERT(!strGroupName.IsEmpty());
  400. ASSERT(ppGroupAz);
  401. return E_INVALIDARG;
  402. }
  403. CComBSTR bstrName = strGroupName;
  404. HRESULT hr = S_OK;
  405. CComPtr<IAzApplicationGroup> spGroup;
  406. hr = m_spAzInterface->OpenApplicationGroup(bstrName,
  407. CComVariant(), //Reserved
  408. &spGroup);
  409. if(FAILED(hr))
  410. {
  411. DBG_OUT_HRESULT(hr);
  412. return hr;
  413. }
  414. *ppGroupAz = new CGroupAz(spGroup,this);
  415. if(!*ppGroupAz)
  416. {
  417. hr = E_OUTOFMEMORY;
  418. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  419. return hr;
  420. }
  421. return S_OK;
  422. }
  423. template<class IAzInterface>
  424. HRESULT
  425. CContainerAzImpl<IAzInterface>::
  426. DeleteGroup(const CString& strGroupName)
  427. {
  428. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,DeleteGroup)
  429. if(strGroupName.IsEmpty())
  430. {
  431. ASSERT(!strGroupName.IsEmpty());
  432. return E_INVALIDARG;
  433. }
  434. CComBSTR bstrName = strGroupName;
  435. HRESULT hr = S_OK;
  436. CComPtr<IAzApplicationGroup> spGroup;
  437. hr = m_spAzInterface->DeleteApplicationGroup(bstrName,
  438. CComVariant());
  439. CHECK_HRESULT(hr);
  440. return hr;
  441. }
  442. template<class IAzInterface>
  443. HRESULT
  444. CContainerAzImpl<IAzInterface>::
  445. GetGroupCollection(GROUP_COLLECTION** ppGroupCollection)
  446. {
  447. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,GetGroupCollection);
  448. if(!ppGroupCollection)
  449. {
  450. ASSERT(ppGroupCollection);
  451. return E_INVALIDARG;
  452. }
  453. CComPtr<IAzApplicationGroups> spAzGroups;
  454. HRESULT hr = m_spAzInterface->get_ApplicationGroups(&spAzGroups);
  455. if(FAILED(hr))
  456. {
  457. DBG_OUT_HRESULT(hr);
  458. return hr;
  459. }
  460. *ppGroupCollection = new GROUP_COLLECTION(spAzGroups,
  461. this);
  462. if(!*ppGroupCollection)
  463. {
  464. hr = E_OUTOFMEMORY;
  465. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  466. return hr;
  467. }
  468. return S_OK;
  469. }
  470. template<class IAzInterface>
  471. HRESULT
  472. CContainerAzImpl<IAzInterface>::
  473. GetPolicyUsers(IN LONG lPropId,
  474. OUT CList<CBaseAz*,CBaseAz*>& pListAdmins)
  475. {
  476. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,GetPolicyUsers)
  477. HRESULT hr = S_OK;
  478. CList<PSID,PSID> listSids;
  479. do
  480. {
  481. CComVariant varUserList;
  482. hr = m_spAzInterface->GetProperty(lPropId,
  483. CComVariant(),
  484. &varUserList);
  485. BREAK_ON_FAIL_HRESULT(hr);
  486. hr = SafeArrayToSidList(varUserList,
  487. listSids);
  488. BREAK_ON_FAIL_HRESULT(hr);
  489. CSidHandler * pSidHandler = GetSidHandler();
  490. if(!pSidHandler)
  491. {
  492. ASSERT(pSidHandler);
  493. return E_UNEXPECTED;
  494. }
  495. hr = pSidHandler->LookupSids(this,listSids,pListAdmins);
  496. BREAK_ON_FAIL_HRESULT(hr);
  497. }while(0);
  498. RemoveItemsFromList(listSids,TRUE);
  499. return hr;
  500. }
  501. template<class IAzInterface>
  502. HRESULT
  503. CContainerAzImpl<IAzInterface>::
  504. AddPolicyUser(LONG lPropId,
  505. IN CBaseAz* pBaseAz)
  506. {
  507. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,AddPolicyUser)
  508. if(!pBaseAz)
  509. {
  510. ASSERT(pBaseAz);
  511. return E_POINTER;
  512. }
  513. HRESULT hr = S_OK;
  514. CString strSid;
  515. if(GetStringSidFromSidCachecAz(pBaseAz,&strSid))
  516. {
  517. CComVariant varSid = strSid;
  518. m_spAzInterface->AddPropertyItem(lPropId,
  519. varSid,
  520. CComVariant());
  521. }
  522. else
  523. {
  524. hr = E_FAIL;
  525. }
  526. CHECK_HRESULT(hr);
  527. return hr;
  528. }
  529. template<class IAzInterface>
  530. HRESULT
  531. CContainerAzImpl<IAzInterface>::
  532. RemovePolicyUser(IN LONG lPropId,
  533. IN CBaseAz* pBaseAz)
  534. {
  535. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,RemovePolicyUser)
  536. if(!pBaseAz)
  537. {
  538. ASSERT(pBaseAz);
  539. return E_POINTER;
  540. }
  541. HRESULT hr = S_OK;
  542. CString strSid;
  543. if(GetStringSidFromSidCachecAz(pBaseAz,&strSid))
  544. {
  545. CComVariant var = strSid;
  546. hr = m_spAzInterface->DeletePropertyItem(lPropId,
  547. var,
  548. CComVariant());
  549. }
  550. else
  551. {
  552. hr = E_FAIL;
  553. }
  554. CHECK_HRESULT(hr);
  555. return hr;
  556. }
  557. template<class IAzInterface>
  558. BOOL
  559. CContainerAzImpl<IAzInterface>::
  560. IsSecurable()
  561. {
  562. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAzImpl,IsSecurable);
  563. HRESULT hr = S_OK;
  564. CComVariant varUserList;
  565. hr = m_spAzInterface->get_PolicyAdministrators(&varUserList);
  566. CHECK_HRESULT(hr);
  567. if(SUCCEEDED(hr))
  568. return TRUE;
  569. else
  570. return FALSE;
  571. }
  572. /*****************************************************************************
  573. Class: CRoleTaskContainerAzImpl
  574. *****************************************************************************/
  575. template<class IAzInterface>
  576. CRoleTaskContainerAzImpl<IAzInterface>
  577. ::CRoleTaskContainerAzImpl(CComPtr<IAzInterface>& spAzInterface,
  578. OBJECT_TYPE_AZ eObjectType,
  579. CContainerAz* pParentContainerAz)
  580. :CRoleTaskContainerAz(eObjectType,pParentContainerAz),
  581. m_spAzInterface(spAzInterface)
  582. {
  583. }
  584. template<class IAzInterface>
  585. CRoleTaskContainerAzImpl<IAzInterface>::~CRoleTaskContainerAzImpl()
  586. {
  587. }
  588. template<class IAzInterface>
  589. HRESULT
  590. CRoleTaskContainerAzImpl<IAzInterface>::SetProperty(LONG lPropId, const CString& strPropValue)
  591. {
  592. CComBSTR bstr = strPropValue;
  593. CComVariant var = bstr;
  594. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  595. var,
  596. CComVariant());
  597. CHECK_HRESULT(hr);
  598. return hr;
  599. }
  600. template<class IAzInterface>
  601. HRESULT
  602. CRoleTaskContainerAzImpl<IAzInterface>::GetProperty(LONG lPropId, CString* pstrPropValue)
  603. {
  604. CComVariant varName;
  605. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  606. CComVariant(),
  607. &varName);
  608. if(SUCCEEDED(hr))
  609. {
  610. ASSERT(varName.vt == VT_BSTR);
  611. *pstrPropValue = varName.bstrVal;
  612. }
  613. CHECK_HRESULT(hr);
  614. return hr;
  615. }
  616. template<class IAzInterface>
  617. HRESULT
  618. CRoleTaskContainerAzImpl<IAzInterface>::SetProperty(LONG lPropId, BOOL bValue)
  619. {
  620. CComVariant varValue = bValue;
  621. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  622. varValue,
  623. CComVariant());
  624. CHECK_HRESULT(hr);
  625. return hr;
  626. }
  627. template<class IAzInterface>
  628. HRESULT
  629. CRoleTaskContainerAzImpl<IAzInterface>::GetProperty(LONG lPropId, BOOL* pbValue)
  630. {
  631. CComVariant varName;
  632. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  633. CComVariant(),
  634. &varName);
  635. if(SUCCEEDED(hr))
  636. {
  637. ASSERT(varName.vt == VT_BOOL);
  638. *pbValue = (varName.boolVal == VARIANT_TRUE);
  639. }
  640. CHECK_HRESULT(hr);
  641. return hr;
  642. }
  643. template<class IAzInterface>
  644. HRESULT
  645. CRoleTaskContainerAzImpl<IAzInterface>::SetProperty(LONG lPropId, LONG lValue)
  646. {
  647. CComVariant varName = lValue;
  648. HRESULT hr = m_spAzInterface->SetProperty(lPropId,
  649. varName,
  650. CComVariant());
  651. CHECK_HRESULT(hr);
  652. return hr;
  653. }
  654. template<class IAzInterface>
  655. HRESULT
  656. CRoleTaskContainerAzImpl<IAzInterface>::GetProperty(LONG lPropId, LONG* plValue)
  657. {
  658. CComVariant varName;
  659. HRESULT hr = m_spAzInterface->GetProperty(lPropId,
  660. CComVariant(),
  661. &varName);
  662. if(SUCCEEDED(hr))
  663. {
  664. ASSERT(varName.vt == VT_I4);
  665. *plValue = varName.lVal;
  666. }
  667. CHECK_HRESULT(hr);
  668. return hr;
  669. }
  670. template<class IAzInterface>
  671. const CString&
  672. CRoleTaskContainerAzImpl<IAzInterface>::GetName()
  673. {
  674. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,GetName)
  675. if(!m_strName.IsEmpty())
  676. return m_strName;
  677. CComVariant varName;
  678. GetProperty(AZ_PROP_NAME, &m_strName);
  679. return m_strName;
  680. }
  681. template<class IAzInterface>
  682. HRESULT
  683. CRoleTaskContainerAzImpl<IAzInterface>::SetName(const CString& strName)
  684. {
  685. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,SetName)
  686. ASSERT(!strName.IsEmpty());
  687. HRESULT hr = SetProperty(AZ_PROP_NAME,strName);
  688. if(SUCCEEDED(hr))
  689. m_strName = strName;
  690. return hr;
  691. }
  692. template<class IAzInterface>
  693. const CString&
  694. CRoleTaskContainerAzImpl<IAzInterface>::GetDescription()
  695. {
  696. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,GetDescription)
  697. CComVariant varDesc;
  698. if(!m_strDescription.IsEmpty())
  699. return m_strDescription;
  700. HRESULT hr = m_spAzInterface->GetProperty(AZ_PROP_DESCRIPTION,
  701. CComVariant(),
  702. &varDesc);
  703. if(SUCCEEDED(hr))
  704. {
  705. ASSERT(varDesc.vt == VT_BSTR);
  706. m_strDescription = varDesc.bstrVal;
  707. return m_strDescription;
  708. }
  709. else
  710. {
  711. DBG_OUT_HRESULT(hr);
  712. return m_strDescription;
  713. }
  714. }
  715. template<class IAzInterface>
  716. HRESULT
  717. CRoleTaskContainerAzImpl<IAzInterface>::SetDescription(const CString& strDesc)
  718. {
  719. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,SetDescription)
  720. ASSERT(!strDesc.IsEmpty());
  721. CComBSTR bstrDesc = strDesc;
  722. CComVariant varDesc = bstrDesc;
  723. VARIANTARG dest;
  724. VariantInit(&dest);
  725. HRESULT hr1 = VariantChangeType(&dest,&varDesc,0,VT_BSTR);
  726. HRESULT hr = m_spAzInterface->SetProperty(AZ_PROP_DESCRIPTION,
  727. varDesc,
  728. CComVariant());
  729. if(SUCCEEDED(hr))
  730. m_strDescription = varDesc.bstrVal;
  731. CHECK_HRESULT(hr);
  732. return hr;
  733. }
  734. template<class IAzInterface>
  735. HRESULT
  736. CRoleTaskContainerAzImpl<IAzInterface>::Submit()
  737. {
  738. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,Submit)
  739. HRESULT hr = m_spAzInterface->Submit(0, CComVariant());
  740. CHECK_HRESULT(hr);
  741. return hr;
  742. }
  743. template<class IAzInterface>
  744. HRESULT
  745. CRoleTaskContainerAzImpl<IAzInterface>::Clear()
  746. {
  747. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,Submit)
  748. HRESULT hr = m_spAzInterface->Submit(AZ_SUBMIT_FLAG_ABORT, CComVariant());
  749. CHECK_HRESULT(hr);
  750. return hr;
  751. }
  752. template<class IAzInterface>
  753. HRESULT
  754. CRoleTaskContainerAzImpl<IAzInterface>::
  755. CreateGroup(const CString& strGroupName, CGroupAz** ppGroupAz)
  756. {
  757. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,CreateGroup)
  758. if(strGroupName.IsEmpty() || !ppGroupAz)
  759. {
  760. ASSERT(!strGroupName.IsEmpty());
  761. ASSERT(ppGroupAz);
  762. return E_INVALIDARG;
  763. }
  764. CComBSTR bstrName = strGroupName;
  765. HRESULT hr = S_OK;
  766. CComPtr<IAzApplicationGroup> spGroup;
  767. hr = m_spAzInterface->CreateApplicationGroup(bstrName,
  768. CComVariant(), //Reserved
  769. &spGroup);
  770. if(FAILED(hr))
  771. {
  772. DBG_OUT_HRESULT(hr);
  773. return hr;
  774. }
  775. *ppGroupAz = new CGroupAz(spGroup,this);
  776. if(!*ppGroupAz)
  777. {
  778. hr = E_OUTOFMEMORY;
  779. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  780. return hr;
  781. }
  782. return S_OK;
  783. }
  784. template<class IAzInterface>
  785. HRESULT
  786. CRoleTaskContainerAzImpl<IAzInterface>::
  787. OpenGroup(const CString& strGroupName, CGroupAz** ppGroupAz)
  788. {
  789. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,OpenGroup);
  790. if(strGroupName.IsEmpty() || !ppGroupAz)
  791. {
  792. ASSERT(!strGroupName.IsEmpty());
  793. ASSERT(ppGroupAz);
  794. return E_INVALIDARG;
  795. }
  796. CComBSTR bstrName = strGroupName;
  797. HRESULT hr = S_OK;
  798. CComPtr<IAzApplicationGroup> spGroup;
  799. hr = m_spAzInterface->OpenApplicationGroup(bstrName,
  800. CComVariant(), //Reserved
  801. &spGroup);
  802. if(FAILED(hr))
  803. {
  804. DBG_OUT_HRESULT(hr);
  805. return hr;
  806. }
  807. *ppGroupAz = new CGroupAz(spGroup,this);
  808. if(!*ppGroupAz)
  809. {
  810. hr = E_OUTOFMEMORY;
  811. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  812. return hr;
  813. }
  814. return S_OK;
  815. }
  816. template<class IAzInterface>
  817. HRESULT
  818. CRoleTaskContainerAzImpl<IAzInterface>::
  819. DeleteGroup(const CString& strGroupName)
  820. {
  821. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,DeleteGroup)
  822. if(strGroupName.IsEmpty())
  823. {
  824. ASSERT(!strGroupName.IsEmpty());
  825. return E_INVALIDARG;
  826. }
  827. CComBSTR bstrName = strGroupName;
  828. HRESULT hr = S_OK;
  829. CComPtr<IAzApplicationGroup> spGroup;
  830. hr = m_spAzInterface->DeleteApplicationGroup(bstrName,
  831. CComVariant());
  832. CHECK_HRESULT(hr);
  833. return hr;
  834. }
  835. template<class IAzInterface>
  836. HRESULT
  837. CRoleTaskContainerAzImpl<IAzInterface>::
  838. GetGroupCollection(GROUP_COLLECTION** ppGroupCollection)
  839. {
  840. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,GetGroupCollection);
  841. if(!ppGroupCollection)
  842. {
  843. ASSERT(ppGroupCollection);
  844. return E_INVALIDARG;
  845. }
  846. CComPtr<IAzApplicationGroups> spAzGroups;
  847. HRESULT hr = m_spAzInterface->get_ApplicationGroups(&spAzGroups);
  848. if(FAILED(hr))
  849. {
  850. DBG_OUT_HRESULT(hr);
  851. return hr;
  852. }
  853. *ppGroupCollection = new GROUP_COLLECTION(spAzGroups,
  854. this);
  855. if(!*ppGroupCollection)
  856. {
  857. hr = E_OUTOFMEMORY;
  858. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  859. return hr;
  860. }
  861. return S_OK;
  862. }
  863. template<class IAzInterface>
  864. HRESULT
  865. CRoleTaskContainerAzImpl<IAzInterface>::
  866. GetPolicyUsers(IN LONG lPropId,
  867. OUT CList<CBaseAz*,CBaseAz*>& pListAdmins)
  868. {
  869. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,GetPolicyUsers)
  870. HRESULT hr = S_OK;
  871. CList<PSID,PSID> listSids;
  872. do
  873. {
  874. CComVariant varUserList;
  875. hr = m_spAzInterface->GetProperty(lPropId,
  876. CComVariant(),
  877. &varUserList);
  878. BREAK_ON_FAIL_HRESULT(hr);
  879. hr = SafeArrayToSidList(varUserList,
  880. listSids);
  881. BREAK_ON_FAIL_HRESULT(hr);
  882. CSidHandler * pSidHandler = GetSidHandler();
  883. if(!pSidHandler)
  884. {
  885. ASSERT(pSidHandler);
  886. return E_UNEXPECTED;
  887. }
  888. hr = pSidHandler->LookupSids(this,listSids,pListAdmins);
  889. BREAK_ON_FAIL_HRESULT(hr);
  890. }while(0);
  891. RemoveItemsFromList(listSids,TRUE);
  892. return hr;
  893. }
  894. template<class IAzInterface>
  895. HRESULT
  896. CRoleTaskContainerAzImpl<IAzInterface>::
  897. AddPolicyUser(LONG lPropId,
  898. IN CBaseAz* pBaseAz)
  899. {
  900. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,AddPolicyUser)
  901. if(!pBaseAz)
  902. {
  903. ASSERT(pBaseAz);
  904. return E_POINTER;
  905. }
  906. HRESULT hr = S_OK;
  907. CString strSid;
  908. if(GetStringSidFromSidCachecAz(pBaseAz,&strSid))
  909. {
  910. CComVariant varSid = strSid;
  911. hr = m_spAzInterface->AddPropertyItem(lPropId,
  912. varSid,
  913. CComVariant());
  914. }
  915. else
  916. {
  917. hr = E_FAIL;
  918. }
  919. CHECK_HRESULT(hr);
  920. return hr;
  921. }
  922. template<class IAzInterface>
  923. HRESULT
  924. CRoleTaskContainerAzImpl<IAzInterface>::
  925. RemovePolicyUser(IN LONG lPropId,
  926. IN CBaseAz* pBaseAz)
  927. {
  928. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,RemovePolicyUser)
  929. if(!pBaseAz)
  930. {
  931. ASSERT(pBaseAz);
  932. return E_POINTER;
  933. }
  934. HRESULT hr = S_OK;
  935. CString strSid;
  936. if(GetStringSidFromSidCachecAz(pBaseAz,&strSid))
  937. {
  938. CComVariant var = strSid;
  939. hr = m_spAzInterface->DeletePropertyItem(lPropId,
  940. var,
  941. CComVariant());
  942. }
  943. else
  944. {
  945. hr = E_FAIL;
  946. }
  947. CHECK_HRESULT(hr);
  948. return hr;
  949. }
  950. template<class IAzInterface>
  951. BOOL
  952. CRoleTaskContainerAzImpl<IAzInterface>::
  953. IsSecurable()
  954. {
  955. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,IsSecurable);
  956. HRESULT hr = S_OK;
  957. CComVariant varUserList;
  958. hr = m_spAzInterface->get_PolicyAdministrators(&varUserList);
  959. if(SUCCEEDED(hr))
  960. return TRUE;
  961. else
  962. return FALSE;
  963. }
  964. template<class IAzInterface>
  965. HRESULT CRoleTaskContainerAzImpl<IAzInterface>::CreateTask(const CString& strTaskName, CTaskAz** ppTaskAz)
  966. {
  967. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,CreateTask)
  968. if(strTaskName.IsEmpty() || !ppTaskAz)
  969. {
  970. ASSERT(!strTaskName.IsEmpty());
  971. ASSERT(ppTaskAz);
  972. return E_INVALIDARG;
  973. }
  974. CComBSTR bstrName = strTaskName;
  975. HRESULT hr = S_OK;
  976. CComPtr<IAzTask> spTask;
  977. hr = m_spAzInterface->CreateTask(bstrName,
  978. CComVariant(), //Reserved
  979. &spTask);
  980. if(FAILED(hr))
  981. {
  982. DBG_OUT_HRESULT(hr);
  983. return hr;
  984. }
  985. hr = Submit();
  986. if(FAILED(hr))
  987. {
  988. DBG_OUT_HRESULT(hr);
  989. return hr;
  990. }
  991. *ppTaskAz = new CTaskAz(spTask,this);
  992. if(!*ppTaskAz)
  993. {
  994. hr = E_OUTOFMEMORY;
  995. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  996. return hr;
  997. }
  998. return S_OK;
  999. }
  1000. template<class IAzInterface>
  1001. HRESULT
  1002. CRoleTaskContainerAzImpl<IAzInterface>
  1003. ::OpenTask(const CString& strTaskName, CTaskAz** ppTaskAz)
  1004. {
  1005. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,OpenTask)
  1006. if(strTaskName.IsEmpty() || !ppTaskAz)
  1007. {
  1008. ASSERT(!strTaskName.IsEmpty());
  1009. ASSERT(ppTaskAz);
  1010. return E_INVALIDARG;
  1011. }
  1012. CComBSTR bstrName = strTaskName;
  1013. HRESULT hr = S_OK;
  1014. CComPtr<IAzTask> spTask;
  1015. hr = m_spAzInterface->OpenTask(bstrName,
  1016. CComVariant(), //Reserved
  1017. &spTask);
  1018. if(FAILED(hr))
  1019. {
  1020. DBG_OUT_HRESULT(hr);
  1021. return hr;
  1022. }
  1023. *ppTaskAz = new CTaskAz(spTask,this);
  1024. if(!*ppTaskAz)
  1025. {
  1026. hr = E_OUTOFMEMORY;
  1027. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  1028. return hr;
  1029. }
  1030. return S_OK;
  1031. }
  1032. template<class IAzInterface>
  1033. HRESULT
  1034. CRoleTaskContainerAzImpl<IAzInterface>
  1035. ::DeleteTask(const CString& strTaskName)
  1036. {
  1037. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,DeleteTask)
  1038. if(strTaskName.IsEmpty())
  1039. {
  1040. ASSERT(!strTaskName.IsEmpty());
  1041. return E_INVALIDARG;
  1042. }
  1043. CComBSTR bstrName = strTaskName;
  1044. HRESULT hr = S_OK;
  1045. CComPtr<IAzTask> spTask;
  1046. hr = m_spAzInterface->DeleteTask(bstrName,
  1047. CComVariant());
  1048. CHECK_HRESULT(hr);
  1049. return hr;
  1050. }
  1051. template<class IAzInterface> HRESULT
  1052. CRoleTaskContainerAzImpl<IAzInterface>
  1053. ::GetTaskCollection(TASK_COLLECTION** ppTaskCollection)
  1054. {
  1055. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,GetTaskCollection)
  1056. if(!ppTaskCollection)
  1057. {
  1058. ASSERT(ppTaskCollection);
  1059. return E_INVALIDARG;
  1060. }
  1061. CComPtr<IAzTasks> spAzTasks;
  1062. HRESULT hr = m_spAzInterface->get_Tasks(&spAzTasks);
  1063. if(FAILED(hr))
  1064. {
  1065. DBG_OUT_HRESULT(hr);
  1066. return hr;
  1067. }
  1068. *ppTaskCollection = new TASK_COLLECTION(spAzTasks,
  1069. this);
  1070. if(!*ppTaskCollection)
  1071. {
  1072. hr = E_OUTOFMEMORY;
  1073. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  1074. return hr;
  1075. }
  1076. return S_OK;
  1077. }
  1078. //
  1079. //Methods for Role
  1080. //
  1081. template<class IAzInterface>
  1082. HRESULT
  1083. CRoleTaskContainerAzImpl<IAzInterface>
  1084. ::CreateRole(const CString& strRoleName, CRoleAz** ppRoleAz)
  1085. {
  1086. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,CreateRole)
  1087. if(strRoleName.IsEmpty() || !ppRoleAz)
  1088. {
  1089. ASSERT(!strRoleName.IsEmpty());
  1090. ASSERT(ppRoleAz);
  1091. return E_INVALIDARG;
  1092. }
  1093. CComBSTR bstrName = strRoleName;
  1094. HRESULT hr = S_OK;
  1095. CComPtr<IAzRole> spRole;
  1096. hr = m_spAzInterface->CreateRole(bstrName,
  1097. CComVariant(), //Reserved
  1098. &spRole);
  1099. if(FAILED(hr))
  1100. {
  1101. DBG_OUT_HRESULT(hr);
  1102. return hr;
  1103. }
  1104. *ppRoleAz = new CRoleAz(spRole,this);
  1105. if(!*ppRoleAz)
  1106. {
  1107. hr = E_OUTOFMEMORY;
  1108. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  1109. return hr;
  1110. }
  1111. return S_OK;
  1112. }
  1113. template<class IAzInterface>
  1114. HRESULT
  1115. CRoleTaskContainerAzImpl<IAzInterface>
  1116. ::OpenRole(const CString& strRoleName, CRoleAz** ppRoleAz)
  1117. {
  1118. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,OpenRole)
  1119. if(strRoleName.IsEmpty() || !ppRoleAz)
  1120. {
  1121. ASSERT(!strRoleName.IsEmpty());
  1122. ASSERT(ppRoleAz);
  1123. return E_INVALIDARG;
  1124. }
  1125. CComBSTR bstrName = strRoleName;
  1126. HRESULT hr = S_OK;
  1127. CComPtr<IAzRole> spRole;
  1128. hr = m_spAzInterface->OpenRole(bstrName,
  1129. CComVariant(), //Reserved
  1130. &spRole);
  1131. if(FAILED(hr))
  1132. {
  1133. DBG_OUT_HRESULT(hr);
  1134. return hr;
  1135. }
  1136. *ppRoleAz = new CRoleAz(spRole,this);
  1137. if(!*ppRoleAz)
  1138. {
  1139. hr = E_OUTOFMEMORY;
  1140. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  1141. return hr;
  1142. }
  1143. return S_OK;
  1144. }
  1145. template<class IAzInterface>
  1146. HRESULT
  1147. CRoleTaskContainerAzImpl<IAzInterface>
  1148. ::DeleteRole(const CString& strRoleName)
  1149. {
  1150. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,DeleteRole)
  1151. if(strRoleName.IsEmpty())
  1152. {
  1153. ASSERT(!strRoleName.IsEmpty());
  1154. return E_INVALIDARG;
  1155. }
  1156. CComBSTR bstrName = strRoleName;
  1157. HRESULT hr = S_OK;
  1158. CComPtr<IAzRole> spRole;
  1159. hr = m_spAzInterface->DeleteRole(bstrName,
  1160. CComVariant()); //Reserved
  1161. CHECK_HRESULT(hr);
  1162. return hr;
  1163. }
  1164. template<class IAzInterface>
  1165. HRESULT
  1166. CRoleTaskContainerAzImpl<IAzInterface>
  1167. ::GetRoleCollection(ROLE_COLLECTION** ppRoleCollection)
  1168. {
  1169. TRACE_METHOD_EX(DEB_SNAPIN,CRoleTaskContainerAzImpl,GetRoleCollection)
  1170. if(!ppRoleCollection)
  1171. {
  1172. ASSERT(ppRoleCollection);
  1173. return E_INVALIDARG;
  1174. }
  1175. CComPtr<IAzRoles> spAzRoles;
  1176. HRESULT hr = m_spAzInterface->get_Roles(&spAzRoles);
  1177. if(FAILED(hr))
  1178. {
  1179. DBG_OUT_HRESULT(hr);
  1180. return hr;
  1181. }
  1182. *ppRoleCollection = new ROLE_COLLECTION(spAzRoles,
  1183. this);
  1184. if(!*ppRoleCollection)
  1185. {
  1186. hr = E_OUTOFMEMORY;
  1187. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  1188. return hr;
  1189. }
  1190. return S_OK;
  1191. }