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.

600 lines
15 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: Basecont.cpp
  7. //
  8. // Contents:
  9. //
  10. // History: 07-26-2001 Hiteshr Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.h"
  14. /******************************************************************************
  15. Class: CBaseLeafNode
  16. Purpose: BaseNode class for all the non container object. A node is a node in
  17. snapins tree listview.
  18. ******************************************************************************/
  19. CBaseLeafNode::
  20. CBaseLeafNode(CRoleComponentDataObject * pComponentDataObject,
  21. CAdminManagerNode* pAdminManagerNode,
  22. CBaseAz* pBaseAz)
  23. :CBaseNode(pComponentDataObject,
  24. pAdminManagerNode,
  25. pBaseAz)
  26. {
  27. SetDisplayName(GetBaseAzObject()->GetName());
  28. }
  29. CBaseLeafNode::
  30. ~CBaseLeafNode()
  31. {
  32. }
  33. LPCWSTR
  34. CBaseLeafNode::
  35. GetString(int nCol)
  36. {
  37. CBaseAz * pBaseAz = GetBaseAzObject();
  38. ASSERT(pBaseAz);
  39. //Name
  40. if(nCol == 0)
  41. return pBaseAz->GetName();
  42. //Type
  43. if( nCol == 1)
  44. return pBaseAz->GetType();
  45. if( nCol == 2)
  46. return pBaseAz->GetDescription();
  47. ASSERT(FALSE);
  48. return NULL;
  49. }
  50. int
  51. CBaseLeafNode::
  52. GetImageIndex(BOOL /*bOpenImage*/)
  53. {
  54. return GetBaseAzObject()->GetImageIndex();
  55. }
  56. BOOL
  57. CBaseLeafNode::
  58. OnSetDeleteVerbState(DATA_OBJECT_TYPES ,
  59. BOOL* pbHide,
  60. CNodeList* pNodeList)
  61. {
  62. if(!pbHide || !pNodeList)
  63. {
  64. ASSERT(pbHide);
  65. ASSERT(pNodeList);
  66. return FALSE;
  67. }
  68. CBaseAz* pBaseAz = GetBaseAzObject();
  69. ASSERT(pBaseAz);
  70. BOOL bWrite = FALSE;
  71. HRESULT hr = pBaseAz->IsWritable(bWrite);
  72. if(FAILED(hr) || !bWrite || pNodeList->GetCount() > 1)
  73. {
  74. *pbHide = TRUE;
  75. return FALSE;
  76. }
  77. else
  78. {
  79. *pbHide = FALSE;
  80. return TRUE;
  81. }
  82. }
  83. BOOL
  84. CBaseLeafNode::
  85. CanCloseSheets()
  86. {
  87. //This function is called when there are open property sheets,
  88. //and operation cannot be done without closing them.
  89. ::DisplayInformation(NULL,
  90. IDS_CLOSE_CONTAINER_PROPERTY_SHEETS,
  91. GetDisplayName());
  92. return FALSE;
  93. }
  94. void
  95. CBaseLeafNode::
  96. OnDelete(CComponentDataObject* pComponentData,
  97. CNodeList* pNodeList)
  98. {
  99. GenericDeleteRoutine(this,pComponentData,pNodeList,TRUE);
  100. }
  101. BOOL
  102. CBaseLeafNode::
  103. HasPropertyPages(DATA_OBJECT_TYPES /*type*/,
  104. BOOL* pbHideVerb,
  105. CNodeList* pNodeList)
  106. {
  107. if (!pNodeList || !pbHideVerb)
  108. {
  109. ASSERT(pNodeList);
  110. ASSERT(pbHideVerb);
  111. return FALSE;
  112. }
  113. if (pNodeList->GetCount() == 1) // single selection
  114. {
  115. *pbHideVerb = FALSE; // always show the verb
  116. return TRUE;
  117. }
  118. // Multiple selection
  119. *pbHideVerb = TRUE;
  120. return FALSE;
  121. }
  122. HRESULT
  123. CBaseLeafNode::
  124. CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  125. LONG_PTR handle,
  126. CNodeList* pNodeList)
  127. {
  128. if(!lpProvider || !pNodeList)
  129. {
  130. ASSERT(lpProvider);
  131. ASSERT(pNodeList);
  132. return E_POINTER;
  133. }
  134. if(!CanReadOneProperty(GetDisplayName(),
  135. GetBaseAzObject()))
  136. return E_FAIL;
  137. HRESULT hr = S_OK;
  138. if (pNodeList->GetCount() > 1)
  139. {
  140. return hr;
  141. }
  142. CRolePropertyPageHolder* pHolder = NULL;
  143. UINT nCountOfPages = 0;
  144. do
  145. {
  146. CComponentDataObject* pComponentDataObject = GetComponentDataObject();
  147. ASSERT(pComponentDataObject);
  148. pHolder = new CRolePropertyPageHolder(GetContainer(),
  149. this,
  150. pComponentDataObject);
  151. if(!pHolder)
  152. {
  153. hr = E_OUTOFMEMORY;
  154. break;
  155. }
  156. //Add Property Pages
  157. while(1)
  158. {
  159. hr = AddOnePageToList(pHolder, nCountOfPages);
  160. if(hr == HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS))
  161. {
  162. hr = S_OK;
  163. break;
  164. }
  165. if(FAILED(hr))
  166. {
  167. break;
  168. }
  169. nCountOfPages++;
  170. }
  171. BREAK_ON_FAIL_HRESULT(hr);
  172. if(nCountOfPages)
  173. {
  174. return pHolder->CreateModelessSheet(lpProvider, handle);
  175. }
  176. }while(0);
  177. if(FAILED(hr) || !nCountOfPages)
  178. {
  179. if(pHolder)
  180. delete pHolder;
  181. }
  182. return hr;
  183. }
  184. void
  185. CBaseLeafNode
  186. ::OnPropertyChange(CComponentDataObject* pComponentData,
  187. BOOL bScopePane,
  188. long changeMask)
  189. {
  190. if(!pComponentData)
  191. {
  192. ASSERT(pComponentData);
  193. return;
  194. }
  195. SetDisplayName(GetBaseAzObject()->GetName());
  196. CTreeNode::OnPropertyChange(pComponentData,
  197. bScopePane,
  198. changeMask);
  199. }
  200. /******************************************************************************
  201. Class: CGroupNode
  202. Purpose: Snapin Node for Application Group Object
  203. ******************************************************************************/
  204. DEBUG_DECLARE_INSTANCE_COUNTER(CGroupNode)
  205. CGroupNode::
  206. CGroupNode(CRoleComponentDataObject * pComponentDataObject,
  207. CAdminManagerNode* pAdminManagerNode,
  208. CBaseAz* pBaseAz,
  209. CRoleAz* pRoleAz)
  210. :CBaseLeafNode(pComponentDataObject,pAdminManagerNode,
  211. pBaseAz),
  212. m_pRoleAz(pRoleAz)
  213. {
  214. DEBUG_INCREMENT_INSTANCE_COUNTER(CGroupNode);
  215. }
  216. CGroupNode
  217. ::~CGroupNode()
  218. {
  219. DEBUG_DECREMENT_INSTANCE_COUNTER(CGroupNode)
  220. }
  221. HRESULT
  222. CGroupNode::
  223. AddOnePageToList(CRolePropertyPageHolder *pHolder, UINT nPageNumber)
  224. {
  225. HRESULT hr = S_OK;
  226. if(!pHolder)
  227. {
  228. ASSERT(pHolder);
  229. return E_POINTER;
  230. }
  231. if(nPageNumber == 0)
  232. {
  233. //Add General Property Page
  234. CGroupGeneralPropertyPage * pGenPropPage =
  235. new CGroupGeneralPropertyPage(GetBaseAzObject(),this);
  236. if(!pGenPropPage)
  237. {
  238. return E_OUTOFMEMORY;
  239. }
  240. pHolder->AddPageToList(pGenPropPage);
  241. return hr;
  242. }
  243. //Get the type of grou[
  244. CGroupAz* pGroupAz = static_cast<CGroupAz*>(GetBaseAzObject());
  245. LONG lGroupType;
  246. hr = pGroupAz->GetGroupType(&lGroupType);
  247. if(FAILED(hr))
  248. {
  249. return hr;
  250. }
  251. if((lGroupType == AZ_GROUPTYPE_BASIC) && (nPageNumber == 1 || nPageNumber == 2))
  252. {
  253. //Add member/non-member page
  254. CGroupMemberPropertyPage * pGroupMemberPropertyPage =
  255. new CGroupMemberPropertyPage(GetBaseAzObject(),this,
  256. (nPageNumber == 1) ? IDD_GROUP_MEMBER : IDD_GROUP_NON_MEMBER,
  257. (nPageNumber == 1) ? TRUE : FALSE);
  258. if(!pGroupMemberPropertyPage)
  259. {
  260. return E_OUTOFMEMORY;
  261. }
  262. pHolder->AddPageToList(pGroupMemberPropertyPage);
  263. return hr;
  264. }
  265. if((lGroupType == AZ_GROUPTYPE_LDAP_QUERY) && (nPageNumber == 1))
  266. {
  267. //Add LDAP Query Property Page
  268. CGroupQueryPropertyPage * pQueryPropPage =
  269. new CGroupQueryPropertyPage(GetBaseAzObject(),this);
  270. if(!pQueryPropPage)
  271. {
  272. hr = E_OUTOFMEMORY;
  273. return hr;
  274. }
  275. pHolder->AddPageToList(pQueryPropPage);
  276. return hr;
  277. }
  278. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  279. }
  280. HRESULT
  281. CGroupNode::
  282. DeleteAssociatedBaseAzObject()
  283. {
  284. TRACE_METHOD_EX(DEB_SNAPIN,CGroupNode,DeleteAssociatedBaseAzObject)
  285. HRESULT hr = S_OK;
  286. //If m_pRoleAz is present, this group node is used to
  287. //represent a member of Role. On delete delete it from
  288. //Role Membership. Else delete this object which is done
  289. //by base class delete
  290. CBaseAz* pBaseAz = GetBaseAzObject();
  291. if(!m_pRoleAz)
  292. {
  293. CContainerAz* pContainerAzParent = GetBaseAzObject()->GetParentAz();
  294. if(!pContainerAzParent)
  295. {
  296. ASSERT(pContainerAzParent);
  297. return E_UNEXPECTED;
  298. }
  299. hr = pContainerAzParent->DeleteAzObject(pBaseAz->GetObjectType(),
  300. pBaseAz->GetName());
  301. }
  302. else
  303. {
  304. //Remove this group from Role Membership
  305. hr = m_pRoleAz->RemoveMember(AZ_PROP_ROLE_APP_MEMBERS,
  306. pBaseAz);
  307. if(SUCCEEDED(hr))
  308. {
  309. hr = m_pRoleAz->Submit();
  310. }
  311. }
  312. return hr;
  313. }
  314. void
  315. CGroupNode::
  316. OnDelete(CComponentDataObject* pComponentData,
  317. CNodeList* pNodeList)
  318. {
  319. GenericDeleteRoutine(this,
  320. pComponentData,
  321. pNodeList,
  322. !m_pRoleAz); //Don't ask for confirmation when removing group from a role
  323. }
  324. /******************************************************************************
  325. Class: CTaskNode
  326. Purpose: Snapin Node for Task Object
  327. ******************************************************************************/
  328. DEBUG_DECLARE_INSTANCE_COUNTER(CTaskNode)
  329. CTaskNode::
  330. CTaskNode(CRoleComponentDataObject * pComponentDataObject,
  331. CAdminManagerNode* pAdminManagerNode,
  332. CBaseAz* pBaseAz)
  333. :CBaseLeafNode(pComponentDataObject,
  334. pAdminManagerNode,
  335. pBaseAz)
  336. {
  337. DEBUG_INCREMENT_INSTANCE_COUNTER(CTaskNode);
  338. }
  339. CTaskNode
  340. ::~CTaskNode()
  341. {
  342. DEBUG_DECREMENT_INSTANCE_COUNTER(CTaskNode)
  343. }
  344. HRESULT
  345. CTaskNode::
  346. AddOnePageToList(CRolePropertyPageHolder *pHolder, UINT nPageNumber)
  347. {
  348. HRESULT hr = S_OK;
  349. if(!pHolder)
  350. {
  351. ASSERT(pHolder);
  352. return E_POINTER;
  353. }
  354. CTaskAz* pTaskAz = dynamic_cast<CTaskAz*>(GetBaseAzObject());
  355. ASSERT(pTaskAz);
  356. if(nPageNumber == 0)
  357. {
  358. //Set the Title to "Node_Name Definition Properties"
  359. pHolder->SetSheetTitle(IDS_FMT_PROP_SHEET_TITILE_FOR_ROLE_DEFINITION,
  360. this);
  361. //Add General Property Page
  362. CTaskGeneralPropertyPage * pGenPropPage =
  363. new CTaskGeneralPropertyPage(GetBaseAzObject(),
  364. this,
  365. pTaskAz->IsRoleDefinition());
  366. if(!pGenPropPage)
  367. {
  368. hr = E_OUTOFMEMORY;
  369. return hr;
  370. }
  371. pHolder->AddPageToList(pGenPropPage);
  372. return hr;
  373. }
  374. else if(nPageNumber == 1)
  375. {
  376. //Add Definition Property Page
  377. CTaskDefinitionPropertyPage * pDefinitionPropPage =
  378. new CTaskDefinitionPropertyPage(pTaskAz,
  379. this,
  380. pTaskAz->IsRoleDefinition());
  381. if(!pDefinitionPropPage)
  382. {
  383. hr = E_OUTOFMEMORY;
  384. return hr;
  385. }
  386. pHolder->AddPageToList(pDefinitionPropPage);
  387. return hr;
  388. }
  389. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  390. }
  391. /******************************************************************************
  392. Class: COperationNode
  393. Purpose: Snapin Node for Operation Object
  394. ******************************************************************************/
  395. DEBUG_DECLARE_INSTANCE_COUNTER(COperationNode)
  396. COperationNode::
  397. COperationNode(CRoleComponentDataObject * pComponentDataObject,
  398. CAdminManagerNode* pAdminManagerNode,
  399. CBaseAz* pBaseAz)
  400. :CBaseLeafNode(pComponentDataObject,
  401. pAdminManagerNode,
  402. pBaseAz)
  403. {
  404. DEBUG_INCREMENT_INSTANCE_COUNTER(COperationNode)
  405. }
  406. COperationNode
  407. ::~COperationNode()
  408. {
  409. DEBUG_DECREMENT_INSTANCE_COUNTER(COperationNode)
  410. }
  411. HRESULT
  412. COperationNode::
  413. AddOnePageToList(CRolePropertyPageHolder *pHolder, UINT nPageNumber)
  414. {
  415. HRESULT hr = S_OK;
  416. if(!pHolder)
  417. {
  418. ASSERT(pHolder);
  419. return E_POINTER;
  420. }
  421. if(nPageNumber == 0)
  422. {
  423. //Set the Title to "Node_Name Definition Properties"
  424. pHolder->SetSheetTitle(IDS_FMT_PROP_SHEET_TITILE_FOR_ROLE_DEFINITION,
  425. this);
  426. //
  427. //Add General Property Page
  428. //
  429. COperationGeneralPropertyPage * pGenPropPage =
  430. new COperationGeneralPropertyPage(GetBaseAzObject(),this);
  431. if(!pGenPropPage)
  432. {
  433. hr = E_OUTOFMEMORY;
  434. return hr;
  435. }
  436. pHolder->AddPageToList(pGenPropPage);
  437. return hr;
  438. }
  439. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  440. }
  441. /******************************************************************************
  442. Class: CSidCacheNode
  443. Purpose: Snapin Node for Windows Users/Groups which are represented by SID
  444. ******************************************************************************/
  445. DEBUG_DECLARE_INSTANCE_COUNTER(CSidCacheNode)
  446. CSidCacheNode::
  447. CSidCacheNode(CRoleComponentDataObject * pComponentDataObject,
  448. CAdminManagerNode* pAdminManagerNode,
  449. CBaseAz* pBaseAz,
  450. CRoleAz* pRoleAz)
  451. :CBaseLeafNode(pComponentDataObject,
  452. pAdminManagerNode,
  453. pBaseAz),
  454. m_pRoleAz(pRoleAz)
  455. {
  456. DEBUG_INCREMENT_INSTANCE_COUNTER(CSidCacheNode)
  457. ASSERT(m_pRoleAz);
  458. }
  459. CSidCacheNode::~CSidCacheNode()
  460. {
  461. DEBUG_DECREMENT_INSTANCE_COUNTER(CSidCacheNode)
  462. }
  463. HRESULT
  464. CSidCacheNode::
  465. DeleteAssociatedBaseAzObject()
  466. {
  467. TRACE_METHOD_EX(DEB_SNAPIN,CSidCacheNode,DeleteAssociatedBaseAzObject)
  468. CBaseAz* pBaseAz = GetBaseAzObject();
  469. HRESULT hr = m_pRoleAz->RemoveMember(AZ_PROP_ROLE_MEMBERS,
  470. pBaseAz);
  471. if(SUCCEEDED(hr))
  472. {
  473. hr = m_pRoleAz->Submit();
  474. }
  475. return hr;
  476. }
  477. void
  478. CSidCacheNode::
  479. OnDelete(CComponentDataObject* pComponentData,
  480. CNodeList* pNodeList)
  481. {
  482. GenericDeleteRoutine(this,pComponentData,pNodeList,FALSE);
  483. }
  484. BOOL
  485. CSidCacheNode::
  486. OnSetDeleteVerbState(DATA_OBJECT_TYPES ,
  487. BOOL* pbHide,
  488. CNodeList* pNodeList)
  489. {
  490. if(!pbHide || !pNodeList)
  491. {
  492. ASSERT(pbHide);
  493. ASSERT(pNodeList);
  494. return FALSE;
  495. }
  496. BOOL bWrite = FALSE;
  497. HRESULT hr = m_pRoleAz->IsWritable(bWrite);
  498. if(FAILED(hr) || !bWrite || pNodeList->GetCount() > 1)
  499. {
  500. *pbHide = TRUE;
  501. return FALSE;
  502. }
  503. else
  504. {
  505. *pbHide = FALSE;
  506. return TRUE;
  507. }
  508. }
  509. BOOL
  510. CSidCacheNode::
  511. HasPropertyPages(DATA_OBJECT_TYPES /*type*/,
  512. BOOL* pbHideVerb,
  513. CNodeList* /*pNodeList*/)
  514. {
  515. if(!pbHideVerb)
  516. {
  517. ASSERT(pbHideVerb);
  518. return FALSE;
  519. }
  520. *pbHideVerb = TRUE;
  521. return FALSE;
  522. }