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.

2145 lines
59 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: baseaz.cpp
  7. //
  8. // Contents: Implementation of Base Classes for AzObjects
  9. //
  10. // History: 09-01
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.h"
  14. /******************************************************************************
  15. Class: CBaseAz
  16. Purpose: This is the base class for all AzObject classes.
  17. ******************************************************************************/
  18. CString
  19. CBaseAz::
  20. GetParentType()
  21. {
  22. if(m_pParentContainerAz)
  23. {
  24. return m_pParentContainerAz->GetType();
  25. }
  26. //m_pParentContainerAz will be null for AdminManagerAz in which
  27. //case return the Type of the store
  28. return GetType();
  29. }
  30. CSidHandler*
  31. CBaseAz::
  32. GetSidHandler()
  33. {
  34. //m_pParentContainerAz == NULL only for CAdminManagerAz which
  35. //overrides this method.
  36. ASSERT(m_pParentContainerAz);
  37. return m_pParentContainerAz->GetSidHandler();
  38. }
  39. CAdminManagerAz*
  40. CBaseAz::
  41. GetAdminManager()
  42. {
  43. //m_pParentContainerAz == NULL only for CAdminManagerAz which
  44. //overrides this method.
  45. ASSERT(m_pParentContainerAz);
  46. return m_pParentContainerAz->GetAdminManager();
  47. }
  48. HRESULT
  49. CBaseAz::IsWritable(BOOL& bRefWrite)
  50. {
  51. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAz,IsWritable)
  52. return GetProperty(AZ_PROP_WRITABLE, &bRefWrite);
  53. }
  54. /******************************************************************************
  55. Class: CContainerAz
  56. Purpose: AdminManagerAz, ApplicationAz and ScopeAz can contain child objects.
  57. All of them can contain group objects. CContainerAz is base class
  58. for all AzObjects which are container
  59. ******************************************************************************/
  60. HRESULT
  61. CContainerAz::
  62. CanCreateChildObject(BOOL& bCahCreateChild)
  63. {
  64. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAz,CanCreateChildObject)
  65. return GetProperty(AZ_PROP_CHILD_CREATE, &bCahCreateChild);
  66. }
  67. BOOL
  68. CContainerAz::
  69. IsAuditingSupported()
  70. {
  71. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAz,IsAuditingSupported)
  72. BOOL bVal = 0;
  73. HRESULT hr = GetProperty(AZ_PROP_GENERATE_AUDITS,&bVal);
  74. CHECK_HRESULT(hr);
  75. HRESULT hr1 = GetProperty(AZ_PROP_APPLY_STORE_SACL,&bVal);
  76. CHECK_HRESULT(hr1);
  77. return (SUCCEEDED(hr) || SUCCEEDED(hr1));
  78. }
  79. //+----------------------------------------------------------------------------
  80. // Function:IsDelegatorSupported
  81. // Synopsis:Checks if Container Supports delegator property
  82. //-----------------------------------------------------------------------------
  83. BOOL
  84. CContainerAz::
  85. IsDelegatorSupported()
  86. {
  87. TRACE_METHOD_EX(DEB_SNAPIN,CContainerAz,IsDelegatorSupported)
  88. //Delegator Property is supported For AD Application,
  89. //AdminManager objects
  90. if(GetAdminManager()->GetStoreType() == AZ_ADMIN_STORE_AD)
  91. {
  92. if(GetObjectType() == ADMIN_MANAGER_AZ ||
  93. GetObjectType() == APPLICATION_AZ)
  94. return TRUE;
  95. }
  96. return FALSE;
  97. }
  98. /******************************************************************************
  99. Class: CAdminManagerAz
  100. Purpose: class for IAzAdminManager interface
  101. ******************************************************************************/
  102. DEBUG_DECLARE_INSTANCE_COUNTER(CAdminManagerAz);
  103. CAdminManagerAz::
  104. CAdminManagerAz(CComPtr<IAzAuthorizationStore>& spAzInterface)
  105. :CContainerAzImpl<IAzAuthorizationStore>(spAzInterface,
  106. ADMIN_MANAGER_AZ,
  107. NULL),
  108. m_pSidHandler(NULL)
  109. {
  110. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CAdminManagerAz);
  111. DEBUG_INCREMENT_INSTANCE_COUNTER(CAdminManagerAz);
  112. SetType(IDS_TYPE_ADMIN_MANAGER);
  113. }
  114. CAdminManagerAz::~CAdminManagerAz()
  115. {
  116. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CAdminManagerAz);
  117. DEBUG_DECREMENT_INSTANCE_COUNTER(CAdminManagerAz);
  118. if(m_pSidHandler)
  119. delete m_pSidHandler;
  120. }
  121. HRESULT
  122. CAdminManagerAz::
  123. UpdateCache()
  124. {
  125. HRESULT hr = m_spAzInterface->UpdateCache(CComVariant());
  126. CHECK_HRESULT(hr);
  127. return hr;
  128. }
  129. HRESULT
  130. CAdminManagerAz::
  131. DeleteSelf()
  132. {
  133. HRESULT hr = m_spAzInterface->Delete(CComVariant());
  134. CHECK_HRESULT(hr);
  135. return hr;
  136. }
  137. HRESULT
  138. CAdminManagerAz::
  139. CreateSidHandler(const CString& strTargetComputerName)
  140. {
  141. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,CreateSidHandler)
  142. CMachineInfo * pMachineInfo = new CMachineInfo();
  143. if(!pMachineInfo)
  144. return E_OUTOFMEMORY;
  145. pMachineInfo->InitializeMacineConfiguration(strTargetComputerName);
  146. m_pSidHandler = new CSidHandler(pMachineInfo);
  147. if(!m_pSidHandler)
  148. {
  149. delete pMachineInfo;
  150. return E_OUTOFMEMORY;
  151. }
  152. return S_OK;
  153. }
  154. //+----------------------------------------------------------------------------
  155. //
  156. // Function: Initialize
  157. // Synopsis: Associates IAzAuthorizationStore to a policy store
  158. // Arguments: IN lStoreType
  159. // IN lFlags
  160. // IN strPolicyURL
  161. // See IAzAuthorizationStore for desc of Parameters
  162. // Returns: hr
  163. //-----------------------------------------------------------------------------
  164. HRESULT CAdminManagerAz::Initialize(IN ULONG lStoreType,
  165. IN ULONG lFlags,
  166. IN const CString& strPolicyURL)
  167. {
  168. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,Initialize)
  169. if(strPolicyURL.IsEmpty())
  170. {
  171. ASSERT(FALSE);
  172. return E_INVALIDARG;
  173. }
  174. HRESULT hr = S_OK;
  175. do
  176. {
  177. CString strFormalStoreName;
  178. //Get the formal Store Name
  179. NameToStoreName(lStoreType,
  180. strPolicyURL,
  181. FALSE,
  182. strFormalStoreName);
  183. Dbg(DEB_SNAPIN, "lStoreType = %u, storeName = %ws, formalStoreName = %ws\n",lStoreType,(LPCWSTR)strPolicyURL,(LPCWSTR)strFormalStoreName );
  184. //Snapin always calls initailize in Manage Store mode
  185. lFlags |= AZ_AZSTORE_FLAG_MANAGE_STORE_ONLY;
  186. CComBSTR bstr = strFormalStoreName;
  187. hr = m_spAzInterface->Initialize(lFlags,
  188. bstr,
  189. CComVariant());
  190. BREAK_ON_FAIL_HRESULT(hr);
  191. //Submit if creating new store
  192. if(lFlags & AZ_AZSTORE_FLAG_CREATE)
  193. {
  194. hr = Submit();
  195. BREAK_ON_FAIL_HRESULT(hr);
  196. }
  197. m_strPolicyURL = strPolicyURL;
  198. GetDisplayNameFromStoreURL(strFormalStoreName,m_strAdminManagerName);
  199. m_ulStoreType = lStoreType;
  200. //
  201. //Create the Sid Handler for the store
  202. //
  203. CComBSTR bstrTargetMachineName;
  204. HRESULT hr1 = m_spAzInterface->get_TargetMachine(&bstrTargetMachineName);
  205. CString strMachineName;
  206. if(SUCCEEDED(hr1) && (bstrTargetMachineName.Length() != 0))
  207. {
  208. strMachineName = bstrTargetMachineName;
  209. }
  210. hr = CreateSidHandler(strMachineName);
  211. BREAK_ON_FAIL_HRESULT(hr);
  212. }while(0);
  213. return hr;
  214. }
  215. //+----------------------------------------------------------------------------
  216. //
  217. // Function: OpenPolicyStore
  218. // Synopsis: Open an existing policy store
  219. //-----------------------------------------------------------------------------
  220. HRESULT
  221. CAdminManagerAz::OpenPolicyStore(IN ULONG lStoreType,
  222. IN const CString& strPolicyURL)
  223. {
  224. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,OpenPolicyStore)
  225. return Initialize(lStoreType, 0, strPolicyURL);
  226. }
  227. //+----------------------------------------------------------------------------
  228. // Function: CreatePolicyStore
  229. // Synopsis: Creates a new policy store
  230. //-----------------------------------------------------------------------------
  231. HRESULT
  232. CAdminManagerAz::CreatePolicyStore(IN ULONG lStoreType,
  233. IN const CString& strPolicyURL)
  234. {
  235. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,OpenPolicyStore)
  236. return Initialize(lStoreType, AZ_AZSTORE_FLAG_CREATE, strPolicyURL);
  237. }
  238. //+----------------------------------------------------------------------------
  239. // Function:CreateApplication
  240. // Synopsis:Create a new application
  241. // Arguments:IN strApplicationName: Name of new application
  242. // OUT ppApplicationAz : receives pointer to CApplicatioAz for new
  243. // app
  244. //-----------------------------------------------------------------------------
  245. HRESULT
  246. CAdminManagerAz::CreateApplication(IN const CString& strApplicationName,
  247. OUT CApplicationAz ** ppApplicationAz)
  248. {
  249. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz, CreateApplication);
  250. if(!ppApplicationAz)
  251. {
  252. ASSERT(ppApplicationAz);
  253. return E_POINTER;
  254. }
  255. HRESULT hr = S_OK;
  256. CComPtr<IAzApplication> spAzApplication;
  257. CComBSTR bstr = strApplicationName;
  258. hr = m_spAzInterface->CreateApplication(bstr,
  259. CComVariant(),
  260. &spAzApplication);
  261. if(FAILED(hr))
  262. {
  263. DBG_OUT_HRESULT(hr);
  264. return hr;
  265. }
  266. *ppApplicationAz = new CApplicationAz(spAzApplication,
  267. this);
  268. if(!*ppApplicationAz)
  269. {
  270. return E_OUTOFMEMORY;
  271. }
  272. return hr;
  273. }
  274. HRESULT
  275. CAdminManagerAz::DeleteApplication(const CString& strApplicationName)
  276. {
  277. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz, DeleteApplication);
  278. HRESULT hr = S_OK;
  279. CComBSTR bstr = strApplicationName;
  280. hr = m_spAzInterface->DeleteApplication(bstr, CComVariant());
  281. CHECK_HRESULT(hr);
  282. return hr;
  283. }
  284. HRESULT
  285. CAdminManagerAz::
  286. GetApplicationCollection(APPLICATION_COLLECTION** ppApplicationCollection)
  287. {
  288. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,GetApplicationCollection)
  289. if(!ppApplicationCollection)
  290. {
  291. ASSERT(ppApplicationCollection);
  292. return E_POINTER;
  293. }
  294. HRESULT hr = S_OK;
  295. CComPtr<IAzApplications> spAzApplications;
  296. hr = m_spAzInterface->get_Applications(&spAzApplications);
  297. if(FAILED(hr))
  298. {
  299. DBG_OUT_HRESULT(hr);
  300. return hr;
  301. }
  302. //Create AppCollection
  303. *ppApplicationCollection =
  304. new APPLICATION_COLLECTION(spAzApplications,
  305. this);
  306. if(!*ppApplicationCollection)
  307. {
  308. hr = E_OUTOFMEMORY;
  309. DBG_OUT_HRESULT(hr);
  310. return hr;
  311. }
  312. return hr;
  313. }
  314. HRESULT
  315. CAdminManagerAz::
  316. CreateAzObject(IN OBJECT_TYPE_AZ eObjectType,
  317. IN const CString& strName,
  318. OUT CBaseAz** ppBaseAz)
  319. {
  320. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,CreateAzObject)
  321. if(!ppBaseAz)
  322. {
  323. ASSERT(ppBaseAz);
  324. return E_POINTER;
  325. }
  326. switch (eObjectType)
  327. {
  328. case APPLICATION_AZ:
  329. {
  330. return CreateApplication(strName, reinterpret_cast<CApplicationAz**>(ppBaseAz));
  331. }
  332. case GROUP_AZ:
  333. {
  334. return CreateGroup(strName, reinterpret_cast<CGroupAz**>(ppBaseAz));
  335. }
  336. default:
  337. {
  338. ASSERT(FALSE);
  339. return E_UNEXPECTED;
  340. }
  341. }
  342. }
  343. HRESULT
  344. CAdminManagerAz::
  345. OpenObject(IN OBJECT_TYPE_AZ eObjectType,
  346. IN const CString& strName,
  347. OUT CBaseAz** ppBaseAz)
  348. {
  349. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,OpenObject)
  350. if(!ppBaseAz)
  351. {
  352. ASSERT(ppBaseAz);
  353. return E_POINTER;
  354. }
  355. switch (eObjectType)
  356. {
  357. case GROUP_AZ:
  358. {
  359. return OpenGroup(strName, reinterpret_cast<CGroupAz**>(ppBaseAz));
  360. }
  361. default:
  362. {
  363. ASSERT(FALSE);
  364. return E_UNEXPECTED;
  365. }
  366. }
  367. }
  368. HRESULT
  369. CAdminManagerAz::
  370. DeleteAzObject(IN OBJECT_TYPE_AZ eObjectType,
  371. IN const CString& strName)
  372. {
  373. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAz,DeleteAzObject)
  374. switch (eObjectType)
  375. {
  376. case APPLICATION_AZ:
  377. {
  378. return DeleteApplication(strName);
  379. }
  380. case GROUP_AZ:
  381. {
  382. return DeleteGroup(strName);
  383. }
  384. default:
  385. {
  386. ASSERT(FALSE);
  387. return E_UNEXPECTED;
  388. }
  389. }
  390. }
  391. HRESULT
  392. CAdminManagerAz::
  393. GetAzObjectCollection(IN OBJECT_TYPE_AZ eObjectType,
  394. OUT CBaseAzCollection **ppBaseAzCollection)
  395. {
  396. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,GetAzObjectCollection)
  397. if(!ppBaseAzCollection)
  398. {
  399. ASSERT(ppBaseAzCollection);
  400. return E_POINTER;
  401. }
  402. switch (eObjectType)
  403. {
  404. case APPLICATION_AZ:
  405. {
  406. return GetApplicationCollection(reinterpret_cast<APPLICATION_COLLECTION**>(ppBaseAzCollection));
  407. }
  408. case GROUP_AZ:
  409. {
  410. return GetGroupCollection(reinterpret_cast<GROUP_COLLECTION**>(ppBaseAzCollection));
  411. }
  412. default:
  413. {
  414. ASSERT(FALSE);
  415. return E_UNEXPECTED;
  416. }
  417. }
  418. }
  419. /******************************************************************************
  420. Class: CApplicationAz
  421. Purpose: class for IAzApplication interface
  422. ******************************************************************************/
  423. DEBUG_DECLARE_INSTANCE_COUNTER(CApplicationAz)
  424. CApplicationAz::
  425. CApplicationAz(IN CComPtr<IAzApplication>& spAzInterface,
  426. IN CContainerAz* pParentContainerAz)
  427. :CRoleTaskContainerAzImpl<IAzApplication>(spAzInterface,
  428. APPLICATION_AZ,
  429. pParentContainerAz)
  430. {
  431. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CApplicationAz)
  432. DEBUG_INCREMENT_INSTANCE_COUNTER(CApplicationAz);
  433. SetType(IDS_TYPE_APPLICATION);
  434. }
  435. //+----------------------------------------------------------------------------
  436. // Function: Destructor
  437. //-----------------------------------------------------------------------------
  438. CApplicationAz::~CApplicationAz()
  439. {
  440. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CApplicationAz)
  441. DEBUG_DECREMENT_INSTANCE_COUNTER(CApplicationAz)
  442. }
  443. HRESULT
  444. CApplicationAz::
  445. CreateOperation(IN const CString& strOperationName,
  446. OUT COperationAz** ppOperationAz)
  447. {
  448. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,CreateOperation)
  449. if(!ppOperationAz)
  450. {
  451. ASSERT(ppOperationAz);
  452. return E_POINTER;
  453. }
  454. CComBSTR bstrName = strOperationName;
  455. HRESULT hr = S_OK;
  456. CComPtr<IAzOperation> spOperation;
  457. hr = m_spAzInterface->CreateOperation(bstrName,
  458. CComVariant(), //Reserved
  459. &spOperation);
  460. if(FAILED(hr))
  461. {
  462. DBG_OUT_HRESULT(hr);
  463. return hr;
  464. }
  465. *ppOperationAz = new COperationAz(spOperation,this);
  466. if(!*ppOperationAz)
  467. return E_OUTOFMEMORY;
  468. return S_OK;
  469. }
  470. HRESULT
  471. CApplicationAz
  472. ::DeleteOperation(IN const CString& strOperationName)
  473. {
  474. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,DeleteOperation)
  475. CComBSTR bstrName = strOperationName;
  476. HRESULT hr = S_OK;
  477. hr = m_spAzInterface->DeleteOperation(bstrName,
  478. CComVariant());
  479. CHECK_HRESULT(hr);
  480. return hr;
  481. }
  482. HRESULT
  483. CApplicationAz
  484. ::OpenOperation(IN const CString& strOperationName,
  485. IN COperationAz** ppOperationAz)
  486. {
  487. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,OpenOperation)
  488. if(!ppOperationAz)
  489. {
  490. ASSERT(ppOperationAz);
  491. return E_POINTER;
  492. }
  493. HRESULT hr = S_OK;
  494. CComBSTR bstrName = strOperationName;
  495. CComPtr<IAzOperation> spOperation;
  496. hr = m_spAzInterface->OpenOperation(bstrName,
  497. CComVariant(), //Reserved
  498. &spOperation);
  499. if(FAILED(hr))
  500. {
  501. DBG_OUT_HRESULT(hr);
  502. return hr;
  503. }
  504. *ppOperationAz = new COperationAz(spOperation,this);
  505. if(!*ppOperationAz)
  506. {
  507. return E_OUTOFMEMORY;
  508. }
  509. return S_OK;
  510. }
  511. HRESULT
  512. CApplicationAz
  513. ::GetOperationCollection(OUT OPERATION_COLLECTION** ppOperationCollection)
  514. {
  515. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,GetOperationCollection)
  516. if(!ppOperationCollection)
  517. {
  518. ASSERT(ppOperationCollection);
  519. return E_POINTER;
  520. }
  521. CComPtr<IAzOperations> spAzOperations;
  522. HRESULT hr = m_spAzInterface->get_Operations(&spAzOperations);
  523. if(FAILED(hr))
  524. {
  525. DBG_OUT_HRESULT(hr);
  526. return hr;
  527. }
  528. *ppOperationCollection = new OPERATION_COLLECTION(spAzOperations,
  529. this);
  530. if(!*ppOperationCollection)
  531. {
  532. return E_OUTOFMEMORY;
  533. }
  534. return S_OK;
  535. }
  536. HRESULT
  537. CApplicationAz::
  538. CreateScope(IN const CString& strScopeName,
  539. OUT CScopeAz** ppScopeAz)
  540. {
  541. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,CreateScope)
  542. if(!ppScopeAz)
  543. {
  544. ASSERT(ppScopeAz);
  545. return E_POINTER;
  546. }
  547. CComBSTR bstrName = strScopeName;
  548. HRESULT hr = S_OK;
  549. CComPtr<IAzScope> spScope;
  550. hr = m_spAzInterface->CreateScope(bstrName,
  551. CComVariant(), //Reserved
  552. &spScope);
  553. if(FAILED(hr))
  554. {
  555. DBG_OUT_HRESULT(hr);
  556. return hr;
  557. }
  558. *ppScopeAz = new CScopeAz(spScope,this);
  559. if(!*ppScopeAz)
  560. {
  561. return E_OUTOFMEMORY;
  562. }
  563. return S_OK;
  564. }
  565. HRESULT
  566. CApplicationAz
  567. ::DeleteScope(IN const CString& strScopeName)
  568. {
  569. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,DeleteScope)
  570. CComBSTR bstrName = strScopeName;
  571. HRESULT hr = S_OK;
  572. hr = m_spAzInterface->DeleteScope(bstrName,
  573. CComVariant());
  574. CHECK_HRESULT(hr);
  575. return hr;
  576. }
  577. HRESULT
  578. CApplicationAz
  579. ::GetScopeCollection(OUT SCOPE_COLLECTION** ppScopeCollection)
  580. {
  581. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,GetScopeCollection)
  582. if(!ppScopeCollection)
  583. {
  584. ASSERT(ppScopeCollection);
  585. return E_POINTER;
  586. }
  587. CComPtr<IAzScopes> spAzScopes;
  588. HRESULT hr = m_spAzInterface->get_Scopes(&spAzScopes);
  589. if(FAILED(hr))
  590. {
  591. DBG_OUT_HRESULT(hr);
  592. return hr;
  593. }
  594. *ppScopeCollection = new SCOPE_COLLECTION(spAzScopes,
  595. this);
  596. if(!*ppScopeCollection)
  597. {
  598. hr = E_OUTOFMEMORY;
  599. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  600. return hr;
  601. }
  602. return S_OK;
  603. }
  604. //CContainerAz Override
  605. HRESULT
  606. CApplicationAz::
  607. CreateAzObject(IN OBJECT_TYPE_AZ eObjectType,
  608. IN const CString& strName,
  609. OUT CBaseAz** ppBaseAz)
  610. {
  611. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,CreateAzObject)
  612. if(!ppBaseAz)
  613. {
  614. ASSERT(ppBaseAz);
  615. return E_POINTER;
  616. }
  617. switch (eObjectType)
  618. {
  619. case SCOPE_AZ:
  620. {
  621. return CreateScope(strName, reinterpret_cast<CScopeAz**>(ppBaseAz));
  622. }
  623. case GROUP_AZ:
  624. {
  625. return CreateGroup(strName, reinterpret_cast<CGroupAz**>(ppBaseAz));
  626. }
  627. case TASK_AZ:
  628. {
  629. return CreateTask(strName, reinterpret_cast<CTaskAz**>(ppBaseAz));
  630. }
  631. case ROLE_AZ:
  632. {
  633. return CreateRole(strName, reinterpret_cast<CRoleAz**>(ppBaseAz));
  634. }
  635. case OPERATION_AZ:
  636. {
  637. return CreateOperation(strName, reinterpret_cast<COperationAz**>(ppBaseAz));
  638. }
  639. default:
  640. {
  641. ASSERT(FALSE);
  642. return E_UNEXPECTED;
  643. }
  644. }
  645. }
  646. HRESULT
  647. CApplicationAz::
  648. OpenObject(IN OBJECT_TYPE_AZ eObjectType,
  649. IN const CString& strName,
  650. OUT CBaseAz** ppBaseAz)
  651. {
  652. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,OpenObject)
  653. if(!ppBaseAz)
  654. {
  655. ASSERT(ppBaseAz);
  656. return E_POINTER;
  657. }
  658. switch (eObjectType)
  659. {
  660. case GROUP_AZ:
  661. {
  662. return OpenGroup(strName, reinterpret_cast<CGroupAz**>(ppBaseAz));
  663. }
  664. case TASK_AZ:
  665. {
  666. return OpenTask(strName, reinterpret_cast<CTaskAz**>(ppBaseAz));
  667. }
  668. case ROLE_AZ:
  669. {
  670. return OpenRole(strName, reinterpret_cast<CRoleAz**>(ppBaseAz));
  671. }
  672. case OPERATION_AZ:
  673. {
  674. return OpenOperation(strName, reinterpret_cast<COperationAz**>(ppBaseAz));
  675. }
  676. default:
  677. {
  678. return E_UNEXPECTED;
  679. }
  680. }
  681. }
  682. HRESULT
  683. CApplicationAz::
  684. DeleteAzObject(IN OBJECT_TYPE_AZ eObjectType,
  685. IN const CString& strName)
  686. {
  687. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,DeleteAzObject)
  688. switch (eObjectType)
  689. {
  690. case SCOPE_AZ:
  691. return DeleteScope(strName);
  692. case GROUP_AZ:
  693. return DeleteGroup(strName);
  694. case TASK_AZ:
  695. return DeleteTask(strName);
  696. case ROLE_AZ:
  697. return DeleteRole(strName);
  698. case OPERATION_AZ:
  699. return DeleteOperation(strName);
  700. default:
  701. {
  702. ASSERT(FALSE);
  703. return E_UNEXPECTED;
  704. }
  705. }
  706. }
  707. HRESULT
  708. CApplicationAz::
  709. GetAzObjectCollection(IN OBJECT_TYPE_AZ eObjectType,
  710. OUT CBaseAzCollection **ppBaseAzCollection)
  711. {
  712. TRACE_METHOD_EX(DEB_SNAPIN,CApplicationAz,GetAzObjectCollection)
  713. if(!ppBaseAzCollection)
  714. {
  715. ASSERT(ppBaseAzCollection);
  716. return E_POINTER;
  717. }
  718. switch (eObjectType)
  719. {
  720. case SCOPE_AZ:
  721. return GetScopeCollection(reinterpret_cast<SCOPE_COLLECTION**>(ppBaseAzCollection));
  722. case GROUP_AZ:
  723. return GetGroupCollection(reinterpret_cast<GROUP_COLLECTION**>(ppBaseAzCollection));
  724. case TASK_AZ:
  725. return GetTaskCollection(reinterpret_cast<TASK_COLLECTION**>(ppBaseAzCollection));
  726. case ROLE_AZ:
  727. return GetRoleCollection(reinterpret_cast<ROLE_COLLECTION**>(ppBaseAzCollection));
  728. case OPERATION_AZ:
  729. return GetOperationCollection(reinterpret_cast<OPERATION_COLLECTION**>(ppBaseAzCollection));
  730. default:
  731. {
  732. ASSERT(FALSE);
  733. return E_UNEXPECTED;
  734. }
  735. }
  736. }
  737. /******************************************************************************
  738. Class: CScopeAz
  739. Purpose: Thin wrapper class around IAzApplication interface.
  740. ******************************************************************************/
  741. DEBUG_DECLARE_INSTANCE_COUNTER(CScopeAz)
  742. CScopeAz::CScopeAz(CComPtr<IAzScope>& spAzInterface,
  743. CContainerAz* pParentContainerAz)
  744. :CRoleTaskContainerAzImpl<IAzScope>(spAzInterface,
  745. SCOPE_AZ,
  746. pParentContainerAz)
  747. {
  748. DEBUG_INCREMENT_INSTANCE_COUNTER(CScopeAz)
  749. SetType(IDS_TYPE_SCOPE);
  750. }
  751. CScopeAz::~CScopeAz()
  752. {
  753. DEBUG_DECREMENT_INSTANCE_COUNTER(CScopeAz)
  754. }
  755. HRESULT
  756. CScopeAz::
  757. CreateAzObject(IN OBJECT_TYPE_AZ eObjectType,
  758. IN const CString& strName,
  759. OUT CBaseAz** ppBaseAz)
  760. {
  761. TRACE_METHOD_EX(DEB_SNAPIN,CScopeAz,CreateAzObject)
  762. if(!ppBaseAz)
  763. {
  764. ASSERT(ppBaseAz);
  765. return E_POINTER;
  766. }
  767. switch (eObjectType)
  768. {
  769. case GROUP_AZ:
  770. return CreateGroup(strName, reinterpret_cast<CGroupAz**>(ppBaseAz));
  771. case TASK_AZ:
  772. return CreateTask(strName, reinterpret_cast<CTaskAz**>(ppBaseAz));
  773. case ROLE_AZ:
  774. return CreateRole(strName, reinterpret_cast<CRoleAz**>(ppBaseAz));
  775. default:
  776. {
  777. ASSERT(FALSE);
  778. return E_UNEXPECTED;
  779. }
  780. }
  781. }
  782. HRESULT
  783. CScopeAz::
  784. OpenObject(IN OBJECT_TYPE_AZ eObjectType,
  785. IN const CString& strName,
  786. OUT CBaseAz** ppBaseAz)
  787. {
  788. TRACE_METHOD_EX(DEB_SNAPIN,CScopeAz,OpenObject)
  789. if(!ppBaseAz)
  790. {
  791. ASSERT(ppBaseAz);
  792. return E_POINTER;
  793. }
  794. switch (eObjectType)
  795. {
  796. case GROUP_AZ:
  797. return OpenGroup(strName, reinterpret_cast<CGroupAz**>(ppBaseAz));
  798. case TASK_AZ:
  799. return OpenTask(strName, reinterpret_cast<CTaskAz**>(ppBaseAz));
  800. case ROLE_AZ:
  801. return OpenRole(strName, reinterpret_cast<CRoleAz**>(ppBaseAz));
  802. default:
  803. {
  804. ASSERT(FALSE);
  805. return E_UNEXPECTED;
  806. }
  807. }
  808. }
  809. HRESULT
  810. CScopeAz::
  811. DeleteAzObject(IN OBJECT_TYPE_AZ eObjectType,
  812. IN const CString& strName)
  813. {
  814. TRACE_METHOD_EX(DEB_SNAPIN,CScopeAz,DeleteAzObject)
  815. switch (eObjectType)
  816. {
  817. case GROUP_AZ:
  818. return DeleteGroup(strName);
  819. case TASK_AZ:
  820. return DeleteTask(strName);
  821. case ROLE_AZ:
  822. return DeleteRole(strName);
  823. default:
  824. {
  825. ASSERT(FALSE);
  826. return E_UNEXPECTED;
  827. }
  828. }
  829. }
  830. HRESULT
  831. CScopeAz::
  832. GetAzObjectCollection(IN OBJECT_TYPE_AZ eObjectType,
  833. OUT CBaseAzCollection **ppBaseAzCollection)
  834. {
  835. TRACE_METHOD_EX(DEB_SNAPIN,CScopeAz,GetAzObjectCollection)
  836. if(!ppBaseAzCollection)
  837. {
  838. ASSERT(ppBaseAzCollection);
  839. return E_POINTER;
  840. }
  841. switch (eObjectType)
  842. {
  843. case GROUP_AZ:
  844. return GetGroupCollection(reinterpret_cast<GROUP_COLLECTION**>(ppBaseAzCollection));
  845. case TASK_AZ:
  846. return GetTaskCollection(reinterpret_cast<TASK_COLLECTION**>(ppBaseAzCollection));
  847. case ROLE_AZ:
  848. return GetRoleCollection(reinterpret_cast<ROLE_COLLECTION**>(ppBaseAzCollection));
  849. default:
  850. {
  851. ASSERT(FALSE);
  852. return E_UNEXPECTED;
  853. }
  854. }
  855. }
  856. HRESULT
  857. CScopeAz::
  858. CanScopeBeDelegated(BOOL & bDelegatable)
  859. {
  860. TRACE_METHOD_EX(DEB_SNAPIN,CScopeAz,CanScopeBeDelegated)
  861. return GetProperty(AZ_PROP_SCOPE_CAN_BE_DELEGATED,&bDelegatable);
  862. }
  863. HRESULT
  864. CScopeAz::
  865. BizRulesWritable(BOOL &brefBizRuleWritable)
  866. {
  867. TRACE_METHOD_EX(DEB_SNAPIN,CScopeAz,BizRulesWritable)
  868. return GetProperty(AZ_PROP_SCOPE_BIZRULES_WRITABLE,&brefBizRuleWritable);
  869. }
  870. /******************************************************************************
  871. Class: CTaskAz
  872. Purpose: class for IAzTask interface
  873. ******************************************************************************/
  874. DEBUG_DECLARE_INSTANCE_COUNTER(CTaskAz)
  875. CTaskAz::
  876. CTaskAz(CComPtr<IAzTask>& spAzInterface,
  877. CContainerAz* pParentContainerAz)
  878. :CBaseAzImpl<IAzTask>(spAzInterface,
  879. TASK_AZ,
  880. pParentContainerAz)
  881. {
  882. DEBUG_INCREMENT_INSTANCE_COUNTER(CTaskAz)
  883. CComVariant var;
  884. if(SUCCEEDED(m_spAzInterface->GetProperty(AZ_PROP_TASK_IS_ROLE_DEFINITION,
  885. CComVariant(),
  886. &var)))
  887. {
  888. ASSERT(var.vt == VT_BOOL);
  889. if(var.boolVal == VARIANT_TRUE)
  890. SetType(IDS_TYPE_ROLE_DEFINITION);
  891. else
  892. SetType(IDS_TYPE_TASK);
  893. }
  894. else
  895. SetType(IDS_TYPE_TASK);
  896. }
  897. CTaskAz::~CTaskAz()
  898. {
  899. DEBUG_DECREMENT_INSTANCE_COUNTER(CTaskAz)
  900. }
  901. int
  902. CTaskAz::
  903. GetImageIndex()
  904. {
  905. if(IsRoleDefinition())
  906. return iIconRoleDefinition;
  907. else
  908. return iIconTask;
  909. }
  910. HRESULT
  911. CTaskAz::
  912. GetMembers(IN LONG lPropId,
  913. OUT CList<CBaseAz*,CBaseAz*>& listMembers)
  914. {
  915. switch (lPropId)
  916. {
  917. case AZ_PROP_TASK_OPERATIONS:
  918. return GetOperations(listMembers);
  919. case AZ_PROP_TASK_TASKS:
  920. return GetTasks(listMembers);
  921. }
  922. ASSERT(FALSE);
  923. return E_UNEXPECTED;
  924. }
  925. HRESULT
  926. CTaskAz::
  927. AddMember(IN LONG lPropId,
  928. IN CBaseAz* pBaseAz)
  929. {
  930. if(!pBaseAz)
  931. {
  932. ASSERT(FALSE);
  933. return E_POINTER;
  934. }
  935. switch (lPropId)
  936. {
  937. case AZ_PROP_TASK_OPERATIONS:
  938. case AZ_PROP_TASK_TASKS:
  939. {
  940. CComVariant varTaskName = pBaseAz->GetName();
  941. HRESULT hr = m_spAzInterface->AddPropertyItem(lPropId,
  942. varTaskName,
  943. CComVariant());
  944. CHECK_HRESULT(hr);
  945. return hr;
  946. }
  947. }
  948. ASSERT(FALSE);
  949. return E_UNEXPECTED;
  950. }
  951. HRESULT
  952. CTaskAz::
  953. RemoveMember(IN LONG lPropId,
  954. IN CBaseAz* pBaseAz)
  955. {
  956. CComVariant var = pBaseAz->GetName();
  957. switch (lPropId)
  958. {
  959. case AZ_PROP_TASK_OPERATIONS:
  960. case AZ_PROP_TASK_TASKS:
  961. {
  962. return m_spAzInterface->DeletePropertyItem(lPropId,
  963. var,
  964. CComVariant());
  965. break;
  966. }
  967. }
  968. ASSERT(FALSE);
  969. return E_UNEXPECTED;
  970. }
  971. HRESULT
  972. CTaskAz::
  973. GetOperations(OUT CList<CBaseAz*,CBaseAz*>& listOperationAz)
  974. {
  975. TRACE_METHOD_EX(DEB_SNAPIN,CTaskAz,GetOperations)
  976. HRESULT hr = S_OK;
  977. do
  978. {
  979. CComVariant varOperationList;
  980. hr = m_spAzInterface->GetProperty(AZ_PROP_TASK_OPERATIONS,
  981. CComVariant(),
  982. &varOperationList);
  983. BREAK_ON_FAIL_HRESULT(hr);
  984. //
  985. //Operations are contained by applications,
  986. //and they can only be opened at application
  987. //
  988. CContainerAz* pParetnContainerAz = GetParentAz();
  989. if(pParetnContainerAz->GetObjectType() == SCOPE_AZ)
  990. pParetnContainerAz = pParetnContainerAz->GetParentAz();
  991. ASSERT(pParetnContainerAz->GetObjectType() == APPLICATION_AZ);
  992. hr = SafeArrayToAzObjectList(varOperationList,
  993. pParetnContainerAz,
  994. OPERATION_AZ,
  995. listOperationAz);
  996. BREAK_ON_FAIL_HRESULT(hr);
  997. }while(0);
  998. return hr;
  999. }
  1000. HRESULT
  1001. CTaskAz::
  1002. GetTasks(OUT CList<CBaseAz*,CBaseAz*>& listTaskAz)
  1003. {
  1004. TRACE_METHOD_EX(DEB_SNAPIN,CTaskAz,GetTasks)
  1005. HRESULT hr = S_OK;
  1006. do
  1007. {
  1008. CComVariant varTaskList;
  1009. hr = m_spAzInterface->GetProperty(AZ_PROP_TASK_TASKS,
  1010. CComVariant(),
  1011. &varTaskList);
  1012. BREAK_ON_FAIL_HRESULT(hr);
  1013. hr = SafeArrayToAzObjectList(varTaskList,
  1014. GetParentAz(),
  1015. TASK_AZ,
  1016. listTaskAz);
  1017. BREAK_ON_FAIL_HRESULT(hr);
  1018. }while(0);
  1019. return hr;
  1020. }
  1021. BOOL
  1022. CTaskAz::
  1023. IsRoleDefinition()
  1024. {
  1025. CComVariant var;
  1026. if(SUCCEEDED(m_spAzInterface->GetProperty(AZ_PROP_TASK_IS_ROLE_DEFINITION,
  1027. CComVariant(),
  1028. &var)));
  1029. {
  1030. ASSERT(var.vt == VT_BOOL);
  1031. return (var.boolVal == VARIANT_TRUE);
  1032. }
  1033. }
  1034. HRESULT
  1035. CTaskAz::
  1036. MakeRoleDefinition()
  1037. {
  1038. CComVariant var = TRUE;
  1039. SetType(IDS_TYPE_ROLE_DEFINITION);
  1040. HRESULT hr = m_spAzInterface->SetProperty(AZ_PROP_TASK_IS_ROLE_DEFINITION,
  1041. var,
  1042. CComVariant());
  1043. CHECK_HRESULT(hr);
  1044. return hr;
  1045. }
  1046. DEBUG_DECLARE_INSTANCE_COUNTER(COperationAz)
  1047. COperationAz::
  1048. COperationAz(CComPtr<IAzOperation>& spAzInterface,
  1049. CContainerAz* pParentContainerAz)
  1050. :CBaseAzImpl<IAzOperation>(spAzInterface,
  1051. OPERATION_AZ,
  1052. pParentContainerAz)
  1053. {
  1054. DEBUG_INCREMENT_INSTANCE_COUNTER(COperationAz)
  1055. SetType(IDS_TYPE_OPERATION);
  1056. }
  1057. COperationAz::~COperationAz()
  1058. {
  1059. DEBUG_DECREMENT_INSTANCE_COUNTER(COperationAz)
  1060. }
  1061. DEBUG_DECLARE_INSTANCE_COUNTER(CRoleAz)
  1062. CRoleAz::
  1063. CRoleAz(CComPtr<IAzRole>& spAzInterface,
  1064. CContainerAz* pParentContainerAz)
  1065. :CBaseAzImpl<IAzRole>(spAzInterface,
  1066. ROLE_AZ,
  1067. pParentContainerAz)
  1068. {
  1069. DEBUG_INCREMENT_INSTANCE_COUNTER(CRoleAz);
  1070. SetType(IDS_TYPE_ROLE);
  1071. }
  1072. CRoleAz::~CRoleAz()
  1073. {
  1074. DEBUG_DECREMENT_INSTANCE_COUNTER(CRoleAz)
  1075. }
  1076. HRESULT
  1077. CRoleAz::
  1078. GetMembers(IN LONG lPropId,
  1079. OUT CList<CBaseAz*,CBaseAz*>& listMembers)
  1080. {
  1081. switch (lPropId)
  1082. {
  1083. case AZ_PROP_ROLE_APP_MEMBERS:
  1084. return GetApplicationGroups(listMembers);
  1085. case AZ_PROP_ROLE_MEMBERS:
  1086. return GetWindowsGroups(listMembers);
  1087. case AZ_PROP_ROLE_OPERATIONS:
  1088. return GetOperations(listMembers);
  1089. case AZ_PROP_ROLE_TASKS:
  1090. return GetTasks(listMembers);
  1091. }
  1092. ASSERT(FALSE);
  1093. return E_UNEXPECTED;
  1094. }
  1095. HRESULT
  1096. CRoleAz::
  1097. GetWindowsGroups(OUT CList<CBaseAz*, CBaseAz*>& listWindowsGroups)
  1098. {
  1099. TRACE_METHOD_EX(DEB_SNAPIN,CGroupAz,GetWindowsGroups)
  1100. HRESULT hr = S_OK;
  1101. CList<PSID,PSID> listSids;
  1102. do
  1103. {
  1104. CComVariant varGroupList;
  1105. hr = m_spAzInterface->GetProperty(AZ_PROP_ROLE_MEMBERS,
  1106. CComVariant(),
  1107. &varGroupList);
  1108. BREAK_ON_FAIL_HRESULT(hr);
  1109. hr = SafeArrayToSidList(varGroupList,
  1110. listSids);
  1111. BREAK_ON_FAIL_HRESULT(hr);
  1112. CSidHandler * pSidHandler = GetSidHandler();
  1113. if(!pSidHandler)
  1114. {
  1115. ASSERT(pSidHandler);
  1116. return E_UNEXPECTED;
  1117. }
  1118. hr = pSidHandler->LookupSids(this,
  1119. listSids,
  1120. listWindowsGroups);
  1121. BREAK_ON_FAIL_HRESULT(hr);
  1122. }while(0);
  1123. RemoveItemsFromList(listSids,TRUE);
  1124. return hr;
  1125. }
  1126. HRESULT
  1127. CRoleAz::
  1128. GetApplicationGroups(CList<CBaseAz*,CBaseAz*>& listGroupAz)
  1129. {
  1130. TRACE_METHOD_EX(DEB_SNAPIN,CGroupAz,GetApplicationGroups)
  1131. HRESULT hr = S_OK;
  1132. do
  1133. {
  1134. CComVariant varGroupList;
  1135. hr = m_spAzInterface->GetProperty(AZ_PROP_ROLE_APP_MEMBERS,
  1136. CComVariant(),
  1137. &varGroupList);
  1138. BREAK_ON_FAIL_HRESULT(hr);
  1139. hr = SafeArrayToAzObjectList(varGroupList,
  1140. GetParentAz(),
  1141. GROUP_AZ,
  1142. listGroupAz);
  1143. BREAK_ON_FAIL_HRESULT(hr);
  1144. }while(0);
  1145. return hr;
  1146. }
  1147. HRESULT
  1148. CRoleAz::
  1149. GetOperations(OUT CList<CBaseAz*,CBaseAz*>& listOperationAz)
  1150. {
  1151. TRACE_METHOD_EX(DEB_SNAPIN,CTaskAz,GetOperations)
  1152. HRESULT hr = S_OK;
  1153. do
  1154. {
  1155. CComVariant varOperationList;
  1156. hr = m_spAzInterface->GetProperty(AZ_PROP_ROLE_OPERATIONS,
  1157. CComVariant(),
  1158. &varOperationList);
  1159. BREAK_ON_FAIL_HRESULT(hr);
  1160. //
  1161. //Operations are contained by applications,
  1162. //and they can only be opened at application
  1163. //
  1164. CContainerAz* pParetnContainerAz = GetParentAz();
  1165. if(pParetnContainerAz->GetObjectType() == SCOPE_AZ)
  1166. pParetnContainerAz = pParetnContainerAz->GetParentAz();
  1167. ASSERT(pParetnContainerAz->GetObjectType() == APPLICATION_AZ);
  1168. hr = SafeArrayToAzObjectList(varOperationList,
  1169. pParetnContainerAz,
  1170. OPERATION_AZ,
  1171. listOperationAz);
  1172. BREAK_ON_FAIL_HRESULT(hr);
  1173. }while(0);
  1174. return hr;
  1175. }
  1176. HRESULT
  1177. CRoleAz::
  1178. GetTasks(OUT CList<CBaseAz*,CBaseAz*>& listTaskAz)
  1179. {
  1180. TRACE_METHOD_EX(DEB_SNAPIN,CTaskAz,GetTasks)
  1181. HRESULT hr = S_OK;
  1182. do
  1183. {
  1184. CComVariant varTaskList;
  1185. hr = m_spAzInterface->GetProperty(AZ_PROP_ROLE_TASKS,
  1186. CComVariant(),
  1187. &varTaskList);
  1188. BREAK_ON_FAIL_HRESULT(hr);
  1189. hr = SafeArrayToAzObjectList(varTaskList,
  1190. GetParentAz(),
  1191. TASK_AZ,
  1192. listTaskAz);
  1193. }while(0);
  1194. return hr;
  1195. }
  1196. HRESULT
  1197. CRoleAz::
  1198. AddMember(IN LONG lPropId,
  1199. IN CBaseAz* pBaseAz)
  1200. {
  1201. if(!pBaseAz)
  1202. {
  1203. ASSERT(FALSE);
  1204. return E_POINTER;
  1205. }
  1206. switch (lPropId)
  1207. {
  1208. case AZ_PROP_ROLE_OPERATIONS:
  1209. case AZ_PROP_ROLE_TASKS:
  1210. case AZ_PROP_ROLE_APP_MEMBERS:
  1211. {
  1212. CComVariant varName = pBaseAz->GetName();
  1213. return m_spAzInterface->AddPropertyItem(lPropId,
  1214. varName,
  1215. CComVariant());
  1216. }
  1217. case AZ_PROP_ROLE_MEMBERS:
  1218. {
  1219. CString strSid;
  1220. if(GetStringSidFromSidCachecAz(pBaseAz, &strSid))
  1221. {
  1222. CComVariant var = strSid;
  1223. return m_spAzInterface->AddPropertyItem(lPropId,
  1224. var,
  1225. CComVariant());
  1226. }
  1227. else
  1228. {
  1229. return E_FAIL;
  1230. }
  1231. }
  1232. }
  1233. ASSERT(FALSE);
  1234. return E_UNEXPECTED;
  1235. }
  1236. HRESULT
  1237. CRoleAz::
  1238. RemoveMember(IN LONG lPropId,
  1239. IN CBaseAz* pBaseAz)
  1240. {
  1241. switch (lPropId)
  1242. {
  1243. case AZ_PROP_ROLE_OPERATIONS:
  1244. case AZ_PROP_ROLE_TASKS:
  1245. case AZ_PROP_ROLE_APP_MEMBERS:
  1246. {
  1247. CComVariant var = pBaseAz->GetName();
  1248. return m_spAzInterface->DeletePropertyItem(lPropId,
  1249. var,
  1250. CComVariant());
  1251. break;
  1252. }
  1253. case AZ_PROP_ROLE_MEMBERS:
  1254. {
  1255. CString strSid;
  1256. if(GetStringSidFromSidCachecAz(pBaseAz, &strSid))
  1257. {
  1258. CComVariant var = strSid;
  1259. return m_spAzInterface->DeletePropertyItem(lPropId,
  1260. var,
  1261. CComVariant());
  1262. }
  1263. else
  1264. {
  1265. return E_FAIL;
  1266. }
  1267. }
  1268. }
  1269. ASSERT(FALSE);
  1270. return E_UNEXPECTED;
  1271. }
  1272. DEBUG_DECLARE_INSTANCE_COUNTER(CGroupAz)
  1273. CGroupAz::
  1274. CGroupAz(CComPtr<IAzApplicationGroup>& spAzInterface,
  1275. CContainerAz* pParentContainerAz)
  1276. :CBaseAzImpl<IAzApplicationGroup>(spAzInterface,
  1277. GROUP_AZ,
  1278. pParentContainerAz)
  1279. {
  1280. DEBUG_INCREMENT_INSTANCE_COUNTER(CGroupAz)
  1281. CComVariant varType;
  1282. LONG lGroupType = AZ_GROUPTYPE_BASIC;
  1283. HRESULT hr = m_spAzInterface->GetProperty(AZ_PROP_GROUP_TYPE,
  1284. CComVariant(),
  1285. &varType);
  1286. if(SUCCEEDED(hr))
  1287. {
  1288. ASSERT(varType.vt == VT_I4);
  1289. lGroupType = varType.lVal;
  1290. }
  1291. SetType((lGroupType == AZ_GROUPTYPE_LDAP_QUERY) ? IDS_TYPE_LDAP_GROUP:IDS_TYPE_BASIC_GROUP);
  1292. }
  1293. CGroupAz::~CGroupAz()
  1294. {
  1295. DEBUG_DECREMENT_INSTANCE_COUNTER(CGroupAz)
  1296. }
  1297. HRESULT
  1298. CGroupAz
  1299. ::GetGroupType(LONG* plGroupType)
  1300. {
  1301. TRACE_METHOD_EX(DEB_SNAPIN,CGroupAz,GetGroupType)
  1302. if(!plGroupType)
  1303. {
  1304. ASSERT(plGroupType);
  1305. return E_POINTER;
  1306. }
  1307. CComVariant varType;
  1308. HRESULT hr = m_spAzInterface->GetProperty(AZ_PROP_GROUP_TYPE,
  1309. CComVariant(),
  1310. &varType);
  1311. if(SUCCEEDED(hr))
  1312. {
  1313. ASSERT(varType.vt == VT_I4);
  1314. *plGroupType = varType.lVal;
  1315. }
  1316. return hr;
  1317. }
  1318. HRESULT
  1319. CGroupAz
  1320. ::SetGroupType(LONG lGroupType)
  1321. {
  1322. TRACE_METHOD_EX(DEB_SNAPIN,CGroupAz,SetGroupType)
  1323. SetType((lGroupType == AZ_GROUPTYPE_LDAP_QUERY) ? IDS_TYPE_LDAP_GROUP:IDS_TYPE_BASIC_GROUP);
  1324. CComVariant varType = lGroupType;
  1325. return m_spAzInterface->SetProperty(AZ_PROP_GROUP_TYPE,
  1326. varType,
  1327. CComVariant());
  1328. }
  1329. HRESULT
  1330. CGroupAz::
  1331. GetMembers(IN LONG lPropId,
  1332. OUT CList<CBaseAz*,CBaseAz*>& listMembers)
  1333. {
  1334. switch (lPropId)
  1335. {
  1336. case AZ_PROP_GROUP_APP_MEMBERS:
  1337. return GetApplicationGroups(listMembers, TRUE);
  1338. case AZ_PROP_GROUP_APP_NON_MEMBERS:
  1339. return GetApplicationGroups(listMembers, FALSE);
  1340. case AZ_PROP_GROUP_MEMBERS:
  1341. return GetWindowsGroups(listMembers, TRUE);
  1342. case AZ_PROP_GROUP_NON_MEMBERS:
  1343. return GetWindowsGroups(listMembers, FALSE);
  1344. }
  1345. ASSERT(FALSE);
  1346. return E_UNEXPECTED;
  1347. }
  1348. HRESULT
  1349. CGroupAz::
  1350. AddMember(IN LONG lPropId,
  1351. IN CBaseAz* pBaseAz)
  1352. {
  1353. if(!pBaseAz)
  1354. {
  1355. ASSERT(FALSE);
  1356. return E_POINTER;
  1357. }
  1358. switch (lPropId)
  1359. {
  1360. case AZ_PROP_GROUP_APP_MEMBERS:
  1361. case AZ_PROP_GROUP_APP_NON_MEMBERS:
  1362. {
  1363. CComVariant varName = pBaseAz->GetName();
  1364. return m_spAzInterface->AddPropertyItem(lPropId,
  1365. varName,
  1366. CComVariant());
  1367. }
  1368. case AZ_PROP_GROUP_MEMBERS:
  1369. case AZ_PROP_GROUP_NON_MEMBERS:
  1370. {
  1371. CString strSid;
  1372. if(GetStringSidFromSidCachecAz(pBaseAz, &strSid))
  1373. {
  1374. CComVariant var = strSid;
  1375. return m_spAzInterface->AddPropertyItem(lPropId,
  1376. var,
  1377. CComVariant());
  1378. }
  1379. else
  1380. {
  1381. return E_FAIL;
  1382. }
  1383. }
  1384. }
  1385. ASSERT(FALSE);
  1386. return E_UNEXPECTED;
  1387. }
  1388. HRESULT
  1389. CGroupAz::
  1390. RemoveMember(IN LONG lPropId,
  1391. IN CBaseAz* pBaseAz)
  1392. {
  1393. switch (lPropId)
  1394. {
  1395. case AZ_PROP_GROUP_APP_MEMBERS:
  1396. case AZ_PROP_GROUP_APP_NON_MEMBERS:
  1397. {
  1398. CComVariant var = pBaseAz->GetName();
  1399. return m_spAzInterface->DeletePropertyItem(lPropId,
  1400. var,
  1401. CComVariant());
  1402. break;
  1403. }
  1404. case AZ_PROP_GROUP_MEMBERS:
  1405. case AZ_PROP_GROUP_NON_MEMBERS:
  1406. {
  1407. CString strSid;
  1408. if(GetStringSidFromSidCachecAz(pBaseAz, &strSid))
  1409. {
  1410. CComVariant var = strSid;
  1411. return m_spAzInterface->DeletePropertyItem(lPropId,
  1412. var,
  1413. CComVariant());
  1414. }
  1415. else
  1416. {
  1417. return E_FAIL;
  1418. }
  1419. }
  1420. }
  1421. ASSERT(FALSE);
  1422. return E_UNEXPECTED;
  1423. }
  1424. HRESULT
  1425. CGroupAz::
  1426. GetApplicationGroups(CList<CBaseAz*,CBaseAz*>& listGroupAz,
  1427. BOOL bMember)
  1428. {
  1429. TRACE_METHOD_EX(DEB_SNAPIN,CGroupAz,GetApplicationGroups)
  1430. HRESULT hr = S_OK;
  1431. do
  1432. {
  1433. CComVariant varGroupList;
  1434. hr = m_spAzInterface->GetProperty(bMember ? AZ_PROP_GROUP_APP_MEMBERS : AZ_PROP_GROUP_APP_NON_MEMBERS,
  1435. CComVariant(),
  1436. &varGroupList);
  1437. BREAK_ON_FAIL_HRESULT(hr);
  1438. hr = SafeArrayToAzObjectList(varGroupList,
  1439. GetParentAz(),
  1440. GROUP_AZ,
  1441. listGroupAz);
  1442. BREAK_ON_FAIL_HRESULT(hr);
  1443. }while(0);
  1444. return hr;
  1445. }
  1446. HRESULT
  1447. CGroupAz::
  1448. GetWindowsGroups(OUT CList<CBaseAz*, CBaseAz*>& listWindowsGroups,
  1449. IN BOOL bMember)
  1450. {
  1451. TRACE_METHOD_EX(DEB_SNAPIN,CGroupAz,GetWindowsGroups)
  1452. HRESULT hr = S_OK;
  1453. CList<PSID,PSID> listSids;
  1454. do
  1455. {
  1456. CComVariant varGroupList;
  1457. hr = m_spAzInterface->GetProperty(bMember ? AZ_PROP_GROUP_MEMBERS : AZ_PROP_GROUP_NON_MEMBERS,
  1458. CComVariant(),
  1459. &varGroupList);
  1460. BREAK_ON_FAIL_HRESULT(hr);
  1461. hr = SafeArrayToSidList(varGroupList,
  1462. listSids);
  1463. BREAK_ON_FAIL_HRESULT(hr);
  1464. CSidHandler * pSidHandler = GetSidHandler();
  1465. if(!pSidHandler)
  1466. {
  1467. ASSERT(pSidHandler);
  1468. return E_UNEXPECTED;
  1469. }
  1470. hr = pSidHandler->LookupSids(this,
  1471. listSids,
  1472. listWindowsGroups);
  1473. BREAK_ON_FAIL_HRESULT(hr);
  1474. }while(0);
  1475. RemoveItemsFromList(listSids,TRUE);
  1476. return hr;
  1477. }
  1478. int
  1479. CGroupAz::
  1480. GetImageIndex()
  1481. {
  1482. LONG lGroupType = AZ_GROUPTYPE_LDAP_QUERY;
  1483. if(SUCCEEDED(GetGroupType(&lGroupType)) &&
  1484. lGroupType == AZ_GROUPTYPE_LDAP_QUERY)
  1485. {
  1486. return iIconLdapGroup;
  1487. }
  1488. else
  1489. return iIconBasicGroup;
  1490. }
  1491. CSidCacheAz::
  1492. CSidCacheAz(SID_CACHE_ENTRY *pSidCacheEntry,
  1493. CBaseAz* pOwnerBaseAz)
  1494. :CBaseAz(SIDCACHE_AZ,NULL),
  1495. m_pOwnerBaseAz(pOwnerBaseAz),
  1496. m_pSidCacheEntry(pSidCacheEntry)
  1497. {
  1498. ASSERT(m_pOwnerBaseAz);
  1499. ASSERT(m_pSidCacheEntry);
  1500. }
  1501. CSidCacheAz::~CSidCacheAz()
  1502. {
  1503. }
  1504. int
  1505. CSidCacheAz::GetImageIndex()
  1506. {
  1507. SID_NAME_USE sidType = m_pSidCacheEntry->GetSidNameUse();
  1508. if(sidType == SidTypeDeletedAccount ||
  1509. sidType == SidTypeInvalid ||
  1510. sidType == SidTypeUnknown)
  1511. {
  1512. return iIconUnknownSid;
  1513. }
  1514. else if(sidType == SidTypeUser)
  1515. {
  1516. return iIconUser;
  1517. }
  1518. else if(sidType == SidTypeComputer)
  1519. {
  1520. return iIconComputerSid;
  1521. }
  1522. else //Assume everything else is group
  1523. {
  1524. return iIconGroup;
  1525. }
  1526. }
  1527. HRESULT
  1528. CContainerAz::GetAzChildObjects(IN OBJECT_TYPE_AZ eObjectType,
  1529. OUT CList<CBaseAz*,CBaseAz*>& ListChildObjects)
  1530. {
  1531. HRESULT hr = S_OK;
  1532. CBaseAzCollection *pBaseAzCollection = NULL;
  1533. do
  1534. {
  1535. //Get the Collection Object
  1536. hr = GetAzObjectCollection(eObjectType,
  1537. &pBaseAzCollection);
  1538. BREAK_ON_FAIL_HRESULT(hr);
  1539. //Get Count of child objects
  1540. LONG lCount = 0;
  1541. hr = pBaseAzCollection->Count(&lCount);
  1542. BREAK_ON_FAIL_HRESULT(hr);
  1543. //Add Items to list
  1544. CBaseAz* pBaseAz = NULL;
  1545. for(LONG i = 1; i <= lCount; ++i)
  1546. {
  1547. pBaseAz = pBaseAzCollection->GetItem(i);
  1548. if(pBaseAz)
  1549. {
  1550. ListChildObjects.AddTail(pBaseAz);
  1551. }
  1552. }
  1553. }while(0);
  1554. if(FAILED(hr))
  1555. {
  1556. RemoveItemsFromList(ListChildObjects);
  1557. }
  1558. if(pBaseAzCollection)
  1559. delete pBaseAzCollection;
  1560. return hr;
  1561. }
  1562. HRESULT
  1563. CContainerAz::
  1564. GetMembers(IN LONG lPropId,
  1565. OUT CList<CBaseAz*,CBaseAz*>& listMembers)
  1566. {
  1567. switch (lPropId)
  1568. {
  1569. case AZ_PROP_POLICY_ADMINS:
  1570. case AZ_PROP_POLICY_READERS:
  1571. case AZ_PROP_DELEGATED_POLICY_USERS:
  1572. return GetPolicyUsers(lPropId,listMembers);
  1573. }
  1574. ASSERT(FALSE);
  1575. return E_UNEXPECTED;
  1576. }
  1577. HRESULT
  1578. CContainerAz::
  1579. AddMember(IN LONG lPropId,
  1580. IN CBaseAz* pBaseAz)
  1581. {
  1582. switch (lPropId)
  1583. {
  1584. case AZ_PROP_POLICY_ADMINS:
  1585. case AZ_PROP_POLICY_READERS:
  1586. case AZ_PROP_DELEGATED_POLICY_USERS:
  1587. return AddPolicyUser(lPropId,pBaseAz);
  1588. }
  1589. ASSERT(FALSE);
  1590. return E_UNEXPECTED;
  1591. }
  1592. HRESULT
  1593. CContainerAz::
  1594. RemoveMember(IN LONG lPropId,
  1595. IN CBaseAz* pBaseAz)
  1596. {
  1597. if(!pBaseAz)
  1598. {
  1599. ASSERT(pBaseAz);
  1600. return E_POINTER;
  1601. }
  1602. switch (lPropId)
  1603. {
  1604. case AZ_PROP_POLICY_ADMINS:
  1605. case AZ_PROP_POLICY_READERS:
  1606. case AZ_PROP_DELEGATED_POLICY_USERS:
  1607. return RemovePolicyUser(lPropId, pBaseAz);
  1608. }
  1609. ASSERT(FALSE);
  1610. return E_UNEXPECTED;
  1611. }
  1612. //+----------------------------------------------------------------------------
  1613. // Function: GetAllAzChildObjects
  1614. // Synopsis: Functions gets the child objects of type eObjectType and appends
  1615. // them to ListChildObjects. It gets the childobjects from
  1616. // pParentContainerAz and from parent/grandparent of
  1617. // pParentContainerAz.
  1618. //-----------------------------------------------------------------------------
  1619. HRESULT GetAllAzChildObjects(IN CContainerAz* pParentContainerAz,
  1620. IN OBJECT_TYPE_AZ eObjectType,
  1621. OUT CList<CBaseAz*,CBaseAz*>& ListChildObjects)
  1622. {
  1623. if(!pParentContainerAz)
  1624. {
  1625. ASSERT(pParentContainerAz);
  1626. return E_POINTER;
  1627. }
  1628. HRESULT hr = S_OK;
  1629. while(pParentContainerAz)
  1630. {
  1631. hr = pParentContainerAz->GetAzChildObjects(eObjectType,
  1632. ListChildObjects);
  1633. BREAK_ON_FAIL_HRESULT(hr);
  1634. if(eObjectType == TASK_AZ)
  1635. {
  1636. if(pParentContainerAz->GetObjectType() == APPLICATION_AZ)
  1637. break;
  1638. }
  1639. else if(eObjectType == GROUP_AZ)
  1640. {
  1641. if(pParentContainerAz->GetObjectType() == ADMIN_MANAGER_AZ)
  1642. break;
  1643. }
  1644. else
  1645. {
  1646. break;
  1647. }
  1648. pParentContainerAz = pParentContainerAz->GetParentAz();
  1649. }
  1650. return hr;
  1651. }
  1652. HRESULT
  1653. GetPolicyUsersFromAllLevel(IN LONG lPropId,
  1654. IN CContainerAz* pContainerAz,
  1655. OUT CList<CBaseAz*,CBaseAz*>& listPolicyUsers)
  1656. {
  1657. if(!pContainerAz)
  1658. {
  1659. ASSERT(pContainerAz);
  1660. return E_POINTER;
  1661. }
  1662. ASSERT((lPropId == AZ_PROP_POLICY_ADMINS) || (lPropId == AZ_PROP_POLICY_READERS) || (lPropId == AZ_PROP_DELEGATED_POLICY_USERS));
  1663. HRESULT hr = S_OK;
  1664. while(pContainerAz && pContainerAz->IsSecurable())
  1665. {
  1666. hr = pContainerAz->GetMembers(lPropId,
  1667. listPolicyUsers);
  1668. BREAK_ON_FAIL_HRESULT(hr);
  1669. pContainerAz = pContainerAz->GetParentAz();
  1670. }
  1671. if(FAILED(hr))
  1672. {
  1673. RemoveItemsFromList(listPolicyUsers);
  1674. }
  1675. return hr;
  1676. }
  1677. //+----------------------------------------------------------------------------
  1678. // Function: OpenObjectFromAllLevels
  1679. // Synopsis: Opens an object of type eObjectType and name strName. If object
  1680. // cannot be opened at pParentContainerAz, function tries at
  1681. // parent/grandparent of pParentContainerAz
  1682. //-----------------------------------------------------------------------------
  1683. HRESULT OpenObjectFromAllLevels(IN CContainerAz* pParentContainerAz,
  1684. IN OBJECT_TYPE_AZ eObjectType,
  1685. IN const CString& strName,
  1686. OUT CBaseAz** ppBaseAz)
  1687. {
  1688. if(!pParentContainerAz || !ppBaseAz)
  1689. {
  1690. ASSERT(pParentContainerAz);
  1691. ASSERT(ppBaseAz);
  1692. return E_POINTER;
  1693. }
  1694. HRESULT hr = S_OK;
  1695. while(pParentContainerAz)
  1696. {
  1697. hr = pParentContainerAz->OpenObject(eObjectType,
  1698. strName,
  1699. ppBaseAz);
  1700. if(SUCCEEDED(hr))
  1701. break;
  1702. if(eObjectType == TASK_AZ)
  1703. {
  1704. if(pParentContainerAz->GetObjectType() == APPLICATION_AZ)
  1705. break;
  1706. }
  1707. else if(eObjectType == GROUP_AZ)
  1708. {
  1709. if(pParentContainerAz->GetObjectType() == ADMIN_MANAGER_AZ)
  1710. break;
  1711. }
  1712. else
  1713. {
  1714. break;
  1715. }
  1716. pParentContainerAz = pParentContainerAz->GetParentAz();
  1717. }
  1718. return hr;
  1719. }
  1720. //+----------------------------------------------------------------------------
  1721. // Function:SafeArrayToAzObjectList
  1722. // Synopsis:Input to function is a safearray of BSTR. Each BSTR in array is
  1723. // name of object of type eObjectType. Function converts this safe
  1724. // array into a list of corresponding CBaseAz objects.
  1725. // Arguments:var: Varaint of type VT_ARRAY|VT_BSTR
  1726. // pParentContainerAz: Pointer of parent which contains objects
  1727. // in safe array.
  1728. // eObjectType: Type of object in safe array
  1729. // listAzObject: Gets list of CBaseAz objects
  1730. // Returns:
  1731. //-----------------------------------------------------------------------------
  1732. HRESULT SafeArrayToAzObjectList(IN CComVariant& var,
  1733. IN CContainerAz* pParentContainerAz,
  1734. IN OBJECT_TYPE_AZ eObjectType,
  1735. OUT CList<CBaseAz*,CBaseAz*>& listAzObject)
  1736. {
  1737. TRACE_FUNCTION_EX(DEB_SNAPIN,SafeArrayToAzObjectList)
  1738. if((var.vt != (VT_ARRAY | VT_VARIANT)) || !pParentContainerAz)
  1739. {
  1740. ASSERT(var.vt == (VT_ARRAY | VT_VARIANT));
  1741. ASSERT(pParentContainerAz);
  1742. return E_INVALIDARG;
  1743. }
  1744. HRESULT hr = S_OK;
  1745. do
  1746. {
  1747. BSTR HUGEP *pbstr = NULL;
  1748. SAFEARRAY *psa = NULL;
  1749. psa = V_ARRAY(&var);
  1750. LONG lStart;
  1751. hr = SafeArrayGetLBound(psa, 1, &lStart);
  1752. BREAK_ON_FAIL_HRESULT(hr);
  1753. LONG lEnd;
  1754. hr = SafeArrayGetUBound(psa, 1, &lEnd);
  1755. BREAK_ON_FAIL_HRESULT(hr);
  1756. for (LONG lCurrent = lStart; lCurrent <= lEnd; lCurrent++)
  1757. {
  1758. CComVariant varElement;
  1759. hr = SafeArrayGetElement( psa, &lCurrent, &varElement);
  1760. BREAK_ON_FAIL_HRESULT(hr);
  1761. ASSERT(varElement.vt == VT_BSTR);
  1762. CString strName = varElement.bstrVal;
  1763. CBaseAz* pBaseAz = NULL;
  1764. //Open the object.
  1765. hr = OpenObjectFromAllLevels(pParentContainerAz,
  1766. eObjectType,
  1767. strName,
  1768. &pBaseAz);
  1769. BREAK_ON_FAIL_HRESULT(hr);
  1770. listAzObject.AddTail(pBaseAz);
  1771. }
  1772. }while(0);
  1773. if(FAILED(hr))
  1774. {
  1775. RemoveItemsFromList(listAzObject);
  1776. }
  1777. return hr;
  1778. }
  1779. HRESULT
  1780. SafeArrayToSidList(IN CComVariant& var,
  1781. OUT CList<PSID,PSID>& listSid)
  1782. {
  1783. TRACE_FUNCTION_EX(DEB_SNAPIN,SafeArrayToSidList)
  1784. if((var.vt != (VT_ARRAY | VT_VARIANT)))
  1785. {
  1786. ASSERT(var.vt == (VT_ARRAY | VT_VARIANT));
  1787. return E_INVALIDARG;
  1788. }
  1789. HRESULT hr = S_OK;
  1790. do
  1791. {
  1792. BSTR HUGEP *pbstr = NULL;
  1793. SAFEARRAY *psa = NULL;
  1794. psa = V_ARRAY(&var);
  1795. LONG lStart;
  1796. hr = SafeArrayGetLBound(psa, 1, &lStart);
  1797. BREAK_ON_FAIL_HRESULT(hr);
  1798. LONG lEnd;
  1799. hr = SafeArrayGetUBound(psa, 1, &lEnd);
  1800. BREAK_ON_FAIL_HRESULT(hr);
  1801. for (LONG lCurrent = lStart; lCurrent <= lEnd; lCurrent++)
  1802. {
  1803. CComVariant varElement;
  1804. hr = SafeArrayGetElement( psa, &lCurrent, &varElement);
  1805. BREAK_ON_FAIL_HRESULT(hr);
  1806. ASSERT(varElement.vt == VT_BSTR);
  1807. CString strSid = varElement.bstrVal;
  1808. PSID pSid = NULL;
  1809. if(!ConvertStringSidToSid(strSid, &pSid))
  1810. {
  1811. hr = E_FAIL;
  1812. BREAK_ON_FAIL_HRESULT(hr);
  1813. }
  1814. listSid.AddTail(pSid);
  1815. }
  1816. }while(0);
  1817. if(FAILED(hr))
  1818. {
  1819. RemoveItemsFromList(listSid, TRUE);
  1820. }
  1821. return hr;
  1822. }