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.

2509 lines
76 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: headers.h
  7. //
  8. // Contents:
  9. //
  10. // History: 07-26-2001 Hiteshr Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.h"
  14. /******************************************************************************
  15. Class: CRolePropertyPageHolder
  16. Purpose: PropertyPageHolder used by this snapin
  17. ******************************************************************************/
  18. CRolePropertyPageHolder::
  19. CRolePropertyPageHolder(CContainerNode* pContNode,
  20. CTreeNode* pNode,
  21. CComponentDataObject* pComponentData)
  22. :CPropertyPageHolderBase(pContNode,
  23. pNode,
  24. pComponentData)
  25. {
  26. CPropertyPageHolderBase::SetSheetTitle(IDS_FMT_PROP_SHEET_TITLE,pNode);
  27. }
  28. /******************************************************************************
  29. Class: CBaseRolePropertyPage
  30. Purpose: Base Class for all property pages
  31. ******************************************************************************/
  32. void
  33. CBaseRolePropertyPage::
  34. OnCancel()
  35. {
  36. if(IsDirty())
  37. {
  38. //Clear the cache of base object
  39. GetBaseAzObject()->Clear();
  40. }
  41. CPropertyPageBase::OnCancel();
  42. }
  43. BOOL
  44. CBaseRolePropertyPage::
  45. OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  46. {
  47. DWORD_PTR pHelpMap = NULL;
  48. if(FindDialogContextTopic(m_nDialogId, &pHelpMap))
  49. {
  50. ASSERT(pHelpMap);
  51. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  52. g_szContextHelpFileName,
  53. HELP_WM_HELP,
  54. pHelpMap);
  55. return TRUE;
  56. }
  57. return FALSE;
  58. }
  59. /******************************************************************************
  60. Class: CGeneralPropertyPage
  61. Purpose: An Attribute Map based property class which can be used by property
  62. pages which are simple. Used by all general property pages
  63. ******************************************************************************/
  64. BOOL
  65. CGeneralPropertyPage::
  66. OnInitDialog()
  67. {
  68. if(GetAttrMap())
  69. {
  70. BOOL bRet = InitDlgFromAttrMap(this,
  71. GetAttrMap(),
  72. GetBaseAzObject(),
  73. IsReadOnly());
  74. if(bRet)
  75. SetInit(TRUE);
  76. return bRet;
  77. }
  78. //Nothing to Init
  79. return TRUE;
  80. }
  81. BOOL
  82. CGeneralPropertyPage::
  83. OnApply()
  84. {
  85. if(!IsDirty())
  86. return TRUE;
  87. HRESULT hr = S_OK;
  88. BOOL bErrorDisplayed = FALSE;
  89. CBaseAz* pBaseAz = GetBaseAzObject();
  90. do
  91. {
  92. hr = SaveAttrMapChanges(this,
  93. GetAttrMap(),
  94. pBaseAz,
  95. FALSE,
  96. &bErrorDisplayed,
  97. NULL);
  98. BREAK_ON_FAIL_HRESULT(hr);
  99. //Submit the changes
  100. hr = pBaseAz->Submit();
  101. BREAK_ON_FAIL_HRESULT(hr);
  102. }while(0);
  103. if(SUCCEEDED(hr))
  104. {
  105. SetDirty(FALSE);
  106. CRolePropertyPageHolder* pHolder = (CRolePropertyPageHolder*)GetHolder();
  107. ASSERT(pHolder);
  108. pHolder->NotifyConsole(this);
  109. return TRUE;
  110. }
  111. else
  112. {
  113. if(!bErrorDisplayed)
  114. {
  115. //Display Generic Error
  116. CString strError;
  117. GetSystemError(strError, hr);
  118. ::DisplayError(m_hWnd,
  119. IDS_GENERIC_PROPERTY_SAVE_ERROR,
  120. (LPCTSTR)strError);
  121. }
  122. return FALSE;
  123. }
  124. }
  125. BEGIN_MESSAGE_MAP(CAdminManagerGeneralProperty, CGeneralPropertyPage)
  126. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnDirty)
  127. END_MESSAGE_MAP()
  128. BEGIN_MESSAGE_MAP(CApplicationGeneralPropertyPage, CGeneralPropertyPage)
  129. ON_EN_CHANGE(IDC_EDIT_NAME, OnDirty)
  130. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnDirty)
  131. ON_EN_CHANGE(IDC_EDIT_VERSION, OnDirty)
  132. END_MESSAGE_MAP()
  133. BOOL
  134. CApplicationGeneralPropertyPage::
  135. OnInitDialog()
  136. {
  137. //Call the base class implementation
  138. CGeneralPropertyPage::OnInitDialog();
  139. //Application name and version info can only be modified in the the
  140. //developer mode
  141. if(!((CRoleRootData*)(GetBaseNode()->GetAdminManagerNode()->GetRootContainer()))->IsDeveloperMode())
  142. {
  143. GetDlgItem(IDC_EDIT_NAME)->EnableWindow(FALSE);
  144. GetDlgItem(IDC_EDIT_VERSION)->EnableWindow(FALSE);
  145. }
  146. return TRUE;
  147. }
  148. BEGIN_MESSAGE_MAP(CScopeGeneralPropertyPage, CGeneralPropertyPage)
  149. ON_EN_CHANGE(IDC_EDIT_NAME, OnDirty)
  150. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnDirty)
  151. END_MESSAGE_MAP()
  152. BEGIN_MESSAGE_MAP(CGroupGeneralPropertyPage, CGeneralPropertyPage)
  153. ON_EN_CHANGE(IDC_EDIT_NAME, OnDirty)
  154. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnDirty)
  155. END_MESSAGE_MAP()
  156. BOOL
  157. CGroupGeneralPropertyPage::
  158. OnInitDialog()
  159. {
  160. TRACE_METHOD_EX(DEB_SNAPIN,CGroupGeneralPropertyPage,OnInitDialog)
  161. LONG lGroupType;
  162. HRESULT hr = ((CGroupAz*)GetBaseAzObject())->GetGroupType(&lGroupType);
  163. if(SUCCEEDED(hr))
  164. {
  165. if(AZ_GROUPTYPE_LDAP_QUERY == lGroupType)
  166. {
  167. GetDlgItem(IDI_ICON_LDAP_GROUP)->ShowWindow(SW_SHOW);
  168. }
  169. else
  170. {
  171. GetDlgItem(IDI_ICON_BASIC_GROUP)->ShowWindow(SW_SHOW);
  172. }
  173. }
  174. //Call the base class Property page
  175. return CGeneralPropertyPage::OnInitDialog();
  176. }
  177. BEGIN_MESSAGE_MAP(CGroupQueryPropertyPage, CGeneralPropertyPage)
  178. ON_EN_CHANGE(IDC_EDIT_LDAP_QUERY, OnDirty)
  179. END_MESSAGE_MAP()
  180. BEGIN_MESSAGE_MAP(CTaskGeneralPropertyPage, CGeneralPropertyPage)
  181. ON_EN_CHANGE(IDC_EDIT_NAME, OnDirty)
  182. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnDirty)
  183. END_MESSAGE_MAP()
  184. BEGIN_MESSAGE_MAP(COperationGeneralPropertyPage, CGeneralPropertyPage)
  185. ON_EN_CHANGE(IDC_EDIT_NAME, OnDirty)
  186. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnDirty)
  187. ON_EN_CHANGE(IDC_EDIT_OPERATION_NUMBER, OnDirty)
  188. END_MESSAGE_MAP()
  189. /******************************************************************************
  190. Class: CAdminManagerAdvancedPropertyPage
  191. Purpose: Limits Property Page for AdminManger
  192. ******************************************************************************/
  193. BEGIN_MESSAGE_MAP(CAdminManagerAdvancedPropertyPage, CGeneralPropertyPage)
  194. ON_EN_CHANGE(IDC_EDIT_DOMAIN_TIMEOUT, OnDirty)
  195. ON_EN_CHANGE(IDC_EDIT_SCRIPT_ENGINE_TIMEOUT, OnDirty)
  196. ON_EN_CHANGE(IDC_EDIT_MAX_SCRIPT_ENGINE, OnDirty)
  197. ON_BN_CLICKED(IDC_BUTTON_DEFAULT, OnButtonDefault)
  198. ON_BN_CLICKED(IDC_RADIO_AUTH_SCRIPT_DISABLED, OnRadioChange)
  199. ON_BN_CLICKED(IDC_RADIO_AUTH_SCRIPT_ENABLED_NO_TIMEOUT,OnRadioChange)
  200. ON_BN_CLICKED(IDC_RADIO_AUTH_SCRIPT_ENABLED_WITH_TIMEOUT,OnRadioChange)
  201. END_MESSAGE_MAP()
  202. BOOL
  203. CAdminManagerAdvancedPropertyPage::
  204. OnInitDialog()
  205. {
  206. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAdvancedPropertyPage,OnInitDialog)
  207. //Call the base class Property page
  208. if(CGeneralPropertyPage::OnInitDialog())
  209. {
  210. if(IsReadOnly())
  211. {
  212. ((CButton*)GetDlgItem(IDC_BUTTON_DEFAULT))->EnableWindow(FALSE);
  213. }
  214. //Get the initial value for m_lAuthScriptTimeoutValue
  215. HRESULT hr = GetBaseAzObject()->GetProperty(AZ_PROP_AZSTORE_SCRIPT_ENGINE_TIMEOUT, &m_lAuthScriptTimeoutValue);
  216. if(FAILED(hr) || m_lAuthScriptTimeoutValue <= 0)
  217. {
  218. m_lAuthScriptTimeoutValue = AZ_AZSTORE_DEFAULT_SCRIPT_ENGINE_TIMEOUT;
  219. }
  220. //Set the limit text for all the three edit buttons
  221. //Get Length of Maximum Long
  222. long lMaxLong = LONG_MAX;
  223. WCHAR szMaxLongBuffer[34];
  224. _ltow(lMaxLong,szMaxLongBuffer,10);
  225. size_t nMaxLen = wcslen(szMaxLongBuffer);
  226. ((CEdit*)GetDlgItem(IDC_EDIT_DOMAIN_TIMEOUT))->SetLimitText((UINT)nMaxLen);
  227. ((CEdit*)GetDlgItem(IDC_EDIT_SCRIPT_ENGINE_TIMEOUT))->SetLimitText((UINT)nMaxLen);
  228. ((CEdit*)GetDlgItem(IDC_EDIT_MAX_SCRIPT_ENGINE))->SetLimitText((UINT)nMaxLen);
  229. return TRUE;
  230. }
  231. return FALSE;
  232. }
  233. void
  234. CAdminManagerAdvancedPropertyPage::
  235. OnButtonDefault()
  236. {
  237. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerAdvancedPropertyPage,OnButtonDefault)
  238. //Authorization script is enabled with no timeout value.
  239. if( ((CButton*)GetDlgItem(IDC_RADIO_AUTH_SCRIPT_ENABLED_NO_TIMEOUT))->GetCheck() == BST_CHECKED)
  240. {
  241. SetLongValue((CEdit*)GetDlgItem(IDC_EDIT_MAX_SCRIPT_ENGINE),AZ_AZSTORE_DEFAULT_MAX_SCRIPT_ENGINES);
  242. }
  243. //Authorization script is enabled with timeout
  244. else if(((CButton*)GetDlgItem(IDC_RADIO_AUTH_SCRIPT_ENABLED_WITH_TIMEOUT))->GetCheck() == BST_CHECKED)
  245. {
  246. SetLongValue((CEdit*)GetDlgItem(IDC_EDIT_SCRIPT_ENGINE_TIMEOUT),AZ_AZSTORE_DEFAULT_SCRIPT_ENGINE_TIMEOUT);
  247. SetLongValue((CEdit*)GetDlgItem(IDC_EDIT_MAX_SCRIPT_ENGINE),AZ_AZSTORE_DEFAULT_MAX_SCRIPT_ENGINES);
  248. }
  249. SetLongValue((CEdit*)GetDlgItem(IDC_EDIT_DOMAIN_TIMEOUT),AZ_AZSTORE_DEFAULT_DOMAIN_TIMEOUT);
  250. SetDirty(TRUE);
  251. }
  252. void
  253. CAdminManagerAdvancedPropertyPage::
  254. OnRadioChange()
  255. {
  256. //
  257. //If the value in "Authorization script timeout" edit control is not IDS_INFINITE,
  258. //convert it to long and save it in m_lAuthScriptTimeoutValue.
  259. //
  260. CString strInfinite;
  261. VERIFY(strInfinite.LoadString(IDS_INFINITE));
  262. CString strTimeoutValue;
  263. CEdit *pEditAuthScriptTimeout = (CEdit*)GetDlgItem(IDC_EDIT_SCRIPT_ENGINE_TIMEOUT);
  264. pEditAuthScriptTimeout->GetWindowText(strTimeoutValue);
  265. if(strInfinite != strTimeoutValue)
  266. {
  267. //Get the value of authorization script timeout textbox
  268. LONG lAuthScriptTimeoutValue = 0;
  269. if(GetLongValue(*pEditAuthScriptTimeout,lAuthScriptTimeoutValue,m_hWnd))
  270. {
  271. if(lAuthScriptTimeoutValue > 0)
  272. m_lAuthScriptTimeoutValue = lAuthScriptTimeoutValue;
  273. }
  274. }
  275. //Authorization script is disabled
  276. if( ((CButton*)GetDlgItem(IDC_RADIO_AUTH_SCRIPT_DISABLED))->GetCheck() == BST_CHECKED)
  277. {
  278. //Disable autorization script timeout textbox and set its value to zero
  279. SetLongValue(pEditAuthScriptTimeout,0);
  280. pEditAuthScriptTimeout->EnableWindow(FALSE);
  281. //Disable max script engine textbox and set its value to actual value in store
  282. LONG lMaxCachedScripts = 0;
  283. HRESULT hr = GetBaseAzObject()->GetProperty(AZ_PROP_AZSTORE_MAX_SCRIPT_ENGINES,&lMaxCachedScripts);
  284. if(SUCCEEDED(hr))
  285. {
  286. SetLongValue((CEdit*)GetDlgItem(IDC_EDIT_MAX_SCRIPT_ENGINE),lMaxCachedScripts);
  287. }
  288. GetDlgItem(IDC_EDIT_MAX_SCRIPT_ENGINE)->EnableWindow(FALSE);
  289. }
  290. //Authorization script is enabled with no timeout value.
  291. else if( ((CButton*)GetDlgItem(IDC_RADIO_AUTH_SCRIPT_ENABLED_NO_TIMEOUT))->GetCheck() == BST_CHECKED)
  292. {
  293. //Enable script engine textbox
  294. GetDlgItem(IDC_EDIT_MAX_SCRIPT_ENGINE)->EnableWindow(TRUE);
  295. //Disable autorization script timeout textbox and sets it value to "no timeout"
  296. pEditAuthScriptTimeout->SetWindowText(strInfinite);
  297. pEditAuthScriptTimeout->EnableWindow(FALSE);
  298. }
  299. //Authorization script is enabled with timeout
  300. else if(((CButton*)GetDlgItem(IDC_RADIO_AUTH_SCRIPT_ENABLED_WITH_TIMEOUT))->GetCheck() == BST_CHECKED)
  301. {
  302. //Enable script engine textbox
  303. GetDlgItem(IDC_EDIT_MAX_SCRIPT_ENGINE)->EnableWindow(TRUE);
  304. //Enable autorization script timeout textbox
  305. pEditAuthScriptTimeout->EnableWindow(TRUE);
  306. SetLongValue(pEditAuthScriptTimeout,m_lAuthScriptTimeoutValue);
  307. }
  308. SetDirty(TRUE);
  309. }
  310. //+----------------------------------------------------------------------------
  311. // Function:MakeBaseAzListToActionItemList
  312. // Synopsis:Takes a list of BaseAz object and creates a list of ActionItems
  313. //-----------------------------------------------------------------------------
  314. HRESULT
  315. MakeBaseAzListToActionItemList(IN CList<CBaseAz*,CBaseAz*>& listBaseAz,
  316. IN OUT CList<ActionItem*,ActionItem*>& listActionItem)
  317. {
  318. while(listBaseAz.GetCount())
  319. {
  320. ActionItem* pActionItem = new ActionItem(listBaseAz.RemoveHead());
  321. if(!pActionItem)
  322. return E_OUTOFMEMORY;
  323. listActionItem.AddTail(pActionItem);
  324. }
  325. return S_OK;
  326. }
  327. //+----------------------------------------------------------------------------
  328. // Function:MakeBaseAzListToActionItemMap
  329. // Synopsis:Takes a list of BaseAz object and creates a map of ActionItems
  330. //-----------------------------------------------------------------------------
  331. HRESULT
  332. MakeBaseAzListToActionItemMap(IN CList<CBaseAz*,CBaseAz*>& listBaseAz,
  333. IN OUT ActionMap& mapActionItems)
  334. {
  335. while(listBaseAz.GetCount())
  336. {
  337. ActionItem* pActionItem = new ActionItem(listBaseAz.RemoveHead());
  338. if(!pActionItem)
  339. return E_OUTOFMEMORY;
  340. mapActionItems.insert(pair<const CString*,ActionItem*>(&(pActionItem->m_pMemberAz->GetName()),pActionItem));
  341. }
  342. return S_OK;
  343. }
  344. /******************************************************************************
  345. Class: CListCtrlPropertyPage
  346. Purpose: Base class for property pages which have list control and primary
  347. action is to add/delete items from it.
  348. ******************************************************************************/
  349. //+----------------------------------------------------------------------------
  350. // Function:AddMember
  351. // Synopsis:Add one member to ActionList
  352. // Returns:HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) if pMemberAz is already
  353. // in the list
  354. //-----------------------------------------------------------------------------
  355. HRESULT
  356. CListCtrlPropertyPage::
  357. AddMember(IN CBaseAz* pMemberAz,
  358. IN OUT ActionMap& mapActionItem,
  359. IN UINT uiFlags)
  360. {
  361. TRACE_METHOD_EX(DEB_SNAPIN,CListCtrlPropertyPage,AddMember)
  362. if(!pMemberAz)
  363. {
  364. ASSERT(pMemberAz);
  365. return E_POINTER;
  366. }
  367. //Check if item is already present in the list
  368. ActionItem* pCurActionItem = NULL;
  369. for (ActionMap::iterator it = mapActionItem.lower_bound(&(pMemberAz->GetName()));
  370. it != mapActionItem.upper_bound(&(pMemberAz->GetName()));
  371. ++it)
  372. {
  373. pCurActionItem = (*it).second;
  374. if(pCurActionItem->action == ACTION_REMOVED)
  375. {
  376. pCurActionItem = NULL;
  377. continue;
  378. }
  379. CBaseAz* pCurBaseAz = pCurActionItem->m_pMemberAz;
  380. if(EqualObjects(pCurBaseAz,pMemberAz))
  381. {
  382. //Item already present
  383. break;
  384. }
  385. pCurActionItem = NULL;
  386. pCurBaseAz = NULL;
  387. }
  388. if(pCurActionItem)
  389. {
  390. if(pCurActionItem->action == ACTION_REMOVE)
  391. {
  392. pCurActionItem->action = ACTION_NONE;
  393. }
  394. else //pCurActionItem->action == ACTION_NONE
  395. //pCurActionItem->action == ACTION_ADD
  396. {
  397. return HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS);
  398. }
  399. }
  400. else
  401. {
  402. //Create a new Action item
  403. pCurActionItem = new ActionItem(pMemberAz);
  404. if(!pCurActionItem)
  405. return E_OUTOFMEMORY;
  406. pCurActionItem->action = ACTION_ADD;
  407. mapActionItem.insert(pair<const CString*,ActionItem*>(&(pCurActionItem->m_pMemberAz->GetName()),pCurActionItem));
  408. }
  409. //Add Current Item to listcontrol
  410. AddActionItemToListCtrl(&m_listCtrl,
  411. 0,
  412. pCurActionItem,
  413. uiFlags);
  414. return S_OK;
  415. }
  416. BOOL
  417. CListCtrlPropertyPage::
  418. EqualObjects(CBaseAz* p1, CBaseAz* p2)
  419. {
  420. if(p1 &&
  421. p2 &&
  422. (p1->GetObjectType() == p2->GetObjectType()) &&
  423. (p1->GetName() == p2->GetName()))
  424. {
  425. return TRUE;
  426. }
  427. return FALSE;
  428. }
  429. //+----------------------------------------------------------------------------
  430. // Function:AddMembers
  431. // Synopsis:Add List of BaseAz items to list of action items.
  432. // Returns: Number of items added.
  433. //-----------------------------------------------------------------------------
  434. int
  435. CListCtrlPropertyPage::
  436. AddMembers(IN CList<CBaseAz*,CBaseAz*>& listMembers,
  437. IN OUT ActionMap& mapActionItem,
  438. IN UINT uiFlags)
  439. {
  440. TRACE_METHOD_EX(DEB_SNAPIN,CListCtrlPropertyPage,AddMembers)
  441. if(listMembers.IsEmpty())
  442. return 0;
  443. int cItemsAdded = 0;
  444. while(listMembers.GetCount())
  445. {
  446. //Add Member
  447. CBaseAz* pMember = listMembers.RemoveHead();
  448. HRESULT hr = AddMember(pMember,
  449. mapActionItem,
  450. uiFlags);
  451. if(FAILED(hr))
  452. {
  453. if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
  454. {
  455. hr = S_OK;
  456. }
  457. else
  458. {
  459. //Display Generic Error.
  460. CString strError;
  461. GetSystemError(strError, hr);
  462. ::DisplayError(m_hWnd,
  463. IDS_ERROR_ADD_MEMBER_OBJECT,
  464. (LPCTSTR)strError,
  465. (LPCTSTR)pMember->GetName());
  466. }
  467. delete pMember;
  468. pMember = NULL;
  469. }
  470. else
  471. {
  472. cItemsAdded++;
  473. //An item has been added to list.
  474. //Enable Apply button
  475. OnDirty();
  476. }
  477. }
  478. m_listCtrl.Sort();
  479. return cItemsAdded;
  480. }
  481. BOOL
  482. CListCtrlPropertyPage::
  483. OnInitDialog()
  484. {
  485. VERIFY(m_listCtrl.SubclassDlgItem(m_nIdListCtrl,this));
  486. m_listCtrl.Initialize();
  487. //Remove button should be disabled in the begining
  488. GetRemoveButton()->EnableWindow(FALSE);
  489. if(IsReadOnly())
  490. MakeControlsReadOnly();
  491. return TRUE;
  492. }
  493. //+----------------------------------------------------------------------------
  494. // Function:RemoveMember
  495. // Synopsis:Set the action for ActionItem to remove
  496. //-----------------------------------------------------------------------------
  497. void
  498. CListCtrlPropertyPage::
  499. RemoveMember(ActionItem* pActionItem)
  500. {
  501. if(!pActionItem)
  502. {
  503. ASSERT(pActionItem);
  504. return;
  505. }
  506. if(pActionItem->action == ACTION_NONE)
  507. pActionItem->action = ACTION_REMOVE;
  508. else
  509. {
  510. //If this item was a newly added item,
  511. //marked it Removed. We won't attepmt to
  512. //remove it from the object
  513. pActionItem->action = ACTION_REMOVED;
  514. }
  515. OnDirty();
  516. }
  517. void
  518. CListCtrlPropertyPage::
  519. OnButtonRemove()
  520. {
  521. //Remember the Position of first selected entry.
  522. int iFirstSelectedItem = m_listCtrl.GetNextItem(-1, LVIS_SELECTED);
  523. int iSelectedItem = -1;
  524. while( (iSelectedItem = m_listCtrl.GetNextItem(iSelectedItem, LVIS_SELECTED)) != -1)
  525. {
  526. RemoveMember((ActionItem*)(m_listCtrl.GetItemData(iSelectedItem)));
  527. m_listCtrl.DeleteItem(iSelectedItem);
  528. iSelectedItem--;
  529. }
  530. if(m_listCtrl.GetItemCount() <= iFirstSelectedItem)
  531. --iFirstSelectedItem;
  532. SelectListCtrlItem(&m_listCtrl, iFirstSelectedItem);
  533. }
  534. void
  535. CListCtrlPropertyPage::
  536. OnListCtrlItemChanged(NMHDR* /*pNotifyStruct*/, LRESULT* pResult)
  537. {
  538. if(!pResult)
  539. return;
  540. *pResult = 0;
  541. if(!IsReadOnly())
  542. {
  543. SetRemoveButton();
  544. }
  545. }
  546. void
  547. CListCtrlPropertyPage::
  548. SetRemoveButton()
  549. {
  550. EnableButtonIfSelectedInListCtrl(&m_listCtrl,
  551. GetRemoveButton());
  552. }
  553. //+----------------------------------------------------------------------------
  554. // Function:DoActionsFromActionList
  555. // Synopsis:For each ActionItem in list, do the action. This function is
  556. // called from the derived class OnApply.
  557. //-----------------------------------------------------------------------------
  558. BOOL
  559. CListCtrlPropertyPage::
  560. DoActionsFromActionMap(IN ActionMap& mapActionItem,
  561. LONG param)
  562. {
  563. TRACE_METHOD_EX(DEB_SNAPIN,CListCtrlPropertyPage,DoActionsFromActionList);
  564. HRESULT hr = S_OK;
  565. CBaseAz* pBaseAz = GetBaseAzObject();
  566. for (ActionMap::iterator it = mapActionItem.begin();
  567. it != mapActionItem.end();
  568. ++it)
  569. {
  570. ActionItem* pActionItem = (*it).second;
  571. //We need to take action only for add or remove
  572. if(pActionItem->action == ACTION_ADD ||
  573. pActionItem->action == ACTION_REMOVE)
  574. {
  575. //Derived class implements this function
  576. //and understands param
  577. hr = DoOneAction(pActionItem,
  578. param);
  579. if(FAILED(hr))
  580. {
  581. CString strError;
  582. GetSystemError(strError, hr);
  583. ::DisplayError(m_hWnd,
  584. (pActionItem->action == ACTION_ADD) ? IDS_ADD_FAILED : IDS_DELETE_FAILED,
  585. (LPCTSTR)strError,
  586. (LPCTSTR)(pActionItem->m_pMemberAz->GetName()));
  587. break;
  588. }
  589. else
  590. {
  591. if(pActionItem->action == ACTION_ADD)
  592. //Item has been added
  593. pActionItem->action = ACTION_NONE;
  594. else
  595. //Item has been removed
  596. pActionItem->action = ACTION_REMOVED;
  597. }
  598. }
  599. }
  600. if(FAILED(hr))
  601. return FALSE;
  602. return TRUE;
  603. }
  604. /******************************************************************************
  605. Class: CTaskDefinitionPropertyPage
  606. Purpose: Property Page for Task Definition
  607. ******************************************************************************/
  608. BEGIN_MESSAGE_MAP(CTaskDefinitionPropertyPage, CListCtrlPropertyPage)
  609. //{{AFX_MSG_MAP(CTaskDefinitionPropertyPage)
  610. ON_BN_CLICKED(IDC_ADD_TASK, OnButtonAdd)
  611. ON_BN_CLICKED(IDC_REMOVE, OnButtonRemove)
  612. ON_BN_CLICKED(IDC_EDIT_SCRIPT,OnButtonEditScript)
  613. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_TASK_OPERATION, OnListCtrlItemChanged)
  614. //}}AFX_MSG_MAP
  615. END_MESSAGE_MAP()
  616. CTaskDefinitionPropertyPage::
  617. ~CTaskDefinitionPropertyPage()
  618. {
  619. RemoveItemsFromActionMap(m_mapActionItem);
  620. }
  621. BOOL
  622. CTaskDefinitionPropertyPage::
  623. OnInitDialog()
  624. {
  625. HRESULT hr = S_OK;
  626. do
  627. {
  628. if(!CListCtrlPropertyPage::OnInitDialog())
  629. {
  630. hr = E_FAIL;
  631. break;
  632. }
  633. CBaseAz* pBaseAz = GetBaseAzObject();
  634. //Add Member Tasks
  635. CList<CBaseAz*,CBaseAz*> listTasks;
  636. hr = pBaseAz->GetMembers(AZ_PROP_TASK_TASKS,
  637. listTasks);
  638. BREAK_ON_FAIL_HRESULT(hr);
  639. hr = MakeBaseAzListToActionItemMap(listTasks,
  640. m_mapActionItem);
  641. BREAK_ON_FAIL_HRESULT(hr);
  642. //Add Member Operations
  643. CList<CBaseAz*,CBaseAz*> listOperations;
  644. hr = pBaseAz->GetMembers(AZ_PROP_TASK_OPERATIONS,
  645. listOperations);
  646. BREAK_ON_FAIL_HRESULT(hr);
  647. hr = MakeBaseAzListToActionItemMap(listOperations,
  648. m_mapActionItem);
  649. BREAK_ON_FAIL_HRESULT(hr);
  650. //And Tasks and Operations to list control
  651. AddActionItemFromMapToListCtrl(m_mapActionItem,
  652. &m_listCtrl,
  653. GetUIFlags(),
  654. FALSE);
  655. //Get Script Data
  656. hr = GetAuthorizationScriptData(*(CTaskAz*)GetBaseAzObject(),
  657. m_strFileName,
  658. m_strScriptLanguage,
  659. m_strScript);
  660. BREAK_ON_FAIL_HRESULT(hr);
  661. }while(0);
  662. if(FAILED(hr))
  663. {
  664. return FALSE;
  665. }
  666. //Sort the list control
  667. m_listCtrl.Sort();
  668. SetInit(TRUE);
  669. return TRUE;
  670. }
  671. void
  672. CTaskDefinitionPropertyPage::
  673. OnButtonAdd()
  674. {
  675. CBaseAz* pBaseAz= GetBaseAzObject();
  676. CContainerAz* pContainerAz = pBaseAz->GetParentAz();
  677. ASSERT(pContainerAz);
  678. CList<CBaseAz*,CBaseAz*> listObjectsSelected;
  679. if(!GetSelectedDefinitions(IsRoleDefinition(),
  680. pContainerAz,
  681. listObjectsSelected))
  682. {
  683. return;
  684. }
  685. //Add selected members to appropriate property and to listctrl
  686. AddMembers(listObjectsSelected,
  687. m_mapActionItem,
  688. GetUIFlags());
  689. return;
  690. }
  691. void
  692. CTaskDefinitionPropertyPage::
  693. OnButtonEditScript()
  694. {
  695. if(IsBizRuleWritable(m_hWnd,*(GetBaseAzObject()->GetParentAz())))
  696. {
  697. if(GetScriptData(IsReadOnly(),
  698. *GetBaseNode()->GetAdminManagerNode(),
  699. m_strFileName,
  700. m_strScriptLanguage,
  701. m_strScript))
  702. {
  703. OnDirty();
  704. m_bScriptDirty = TRUE;
  705. }
  706. }
  707. }
  708. HRESULT
  709. CTaskDefinitionPropertyPage::
  710. DoOneAction(IN ActionItem* pActionItem,
  711. LONG )
  712. {
  713. TRACE_METHOD_EX(DEB_SNAPIN,CTaskDefinitionPropertyPage,DoOneAction)
  714. if(!pActionItem)
  715. {
  716. ASSERT(pActionItem);
  717. return E_POINTER;
  718. }
  719. CBaseAz* pBaseAz = GetBaseAzObject();
  720. //Decide what property to change
  721. LONG lPropId = AZ_PROP_TASK_TASKS;
  722. if(pActionItem->m_pMemberAz->GetObjectType() == OPERATION_AZ)
  723. lPropId = AZ_PROP_TASK_OPERATIONS;
  724. if(pActionItem->action == ACTION_ADD)
  725. return pBaseAz->AddMember(lPropId,
  726. pActionItem->m_pMemberAz);
  727. else
  728. return pBaseAz->RemoveMember(lPropId,
  729. pActionItem->m_pMemberAz);
  730. }
  731. void
  732. CTaskDefinitionPropertyPage::
  733. MakeControlsReadOnly()
  734. {
  735. TRACE_METHOD_EX(DEB_SNAPIN,CTaskDefinitionPropertyPage,MakeControlsReadOnly)
  736. GetDlgItem(IDC_ADD_TASK)->EnableWindow(FALSE);
  737. GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
  738. }
  739. BOOL
  740. CTaskDefinitionPropertyPage::
  741. OnApply()
  742. {
  743. TRACE_METHOD_EX(DEB_SNAPIN,CTaskDefinitionPropertyPage,OnApply)
  744. if(!IsDirty())
  745. return TRUE;
  746. //Save the items from the action list
  747. if(!DoActionsFromActionMap(m_mapActionItem,
  748. 0))
  749. {
  750. return FALSE;
  751. }
  752. HRESULT hr = S_OK;
  753. BOOL bErrorDisplayed = FALSE;
  754. //Save the authorization data
  755. if(m_bScriptDirty)
  756. {
  757. hr = SaveAuthorizationScriptData(m_hWnd,
  758. *(CTaskAz*)GetBaseAzObject(),
  759. m_strFileName,
  760. m_strScriptLanguage,
  761. m_strScript,
  762. bErrorDisplayed);
  763. }
  764. if(SUCCEEDED(hr))
  765. {
  766. m_bScriptDirty = FALSE;
  767. hr = GetBaseAzObject()->Submit();
  768. }
  769. if(FAILED(hr))
  770. {
  771. if(!bErrorDisplayed)
  772. {
  773. //Display Generic Error
  774. CString strError;
  775. GetSystemError(strError, hr);
  776. ::DisplayError(m_hWnd,
  777. IDS_GENERIC_PROPERTY_SAVE_ERROR,
  778. (LPCTSTR)strError);
  779. }
  780. return FALSE;
  781. }
  782. else
  783. {
  784. SetDirty(FALSE);
  785. return TRUE;
  786. }
  787. return FALSE;
  788. }
  789. /******************************************************************************
  790. Class: Group Membership Property Page
  791. Purpose: Property Page Group Definition
  792. ******************************************************************************/
  793. BEGIN_MESSAGE_MAP(CGroupMemberPropertyPage, CListCtrlPropertyPage)
  794. //{{AFX_MSG_MAP(CGroupMemberPropertyPage)
  795. ON_BN_CLICKED(IDC_ADD_APPLICATION_GROUP, OnButtonAddApplicationGroups)
  796. ON_BN_CLICKED(IDC_ADD_WINDOWS_GROUPS, OnButtonAddWindowsGroups)
  797. ON_BN_CLICKED(IDC_REMOVE, OnButtonRemove)
  798. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_MEMBER, OnListCtrlItemChanged)
  799. //}}AFX_MSG_MAP
  800. END_MESSAGE_MAP()
  801. CGroupMemberPropertyPage::
  802. ~CGroupMemberPropertyPage()
  803. {
  804. RemoveItemsFromActionMap(m_mapActionItem);
  805. }
  806. BOOL
  807. CGroupMemberPropertyPage::
  808. OnInitDialog()
  809. {
  810. HRESULT hr = S_OK;
  811. do
  812. {
  813. if(!CListCtrlPropertyPage::OnInitDialog())
  814. {
  815. hr = E_FAIL;
  816. break;
  817. }
  818. CBaseAz* pBaseAz = static_cast<CBaseAz*>(GetBaseAzObject());
  819. //Add Member ApplicationGroups
  820. CList<CBaseAz*,CBaseAz*> listAppGroups;
  821. hr = pBaseAz->GetMembers(m_bMember ? AZ_PROP_GROUP_APP_MEMBERS : AZ_PROP_GROUP_APP_NON_MEMBERS,
  822. listAppGroups);
  823. BREAK_ON_FAIL_HRESULT(hr);
  824. hr = MakeBaseAzListToActionItemMap(listAppGroups,
  825. m_mapActionItem);
  826. BREAK_ON_FAIL_HRESULT(hr);
  827. //Add Member Windows Groups/User
  828. CList<CBaseAz*,CBaseAz*> listWindowsGroups;
  829. hr = pBaseAz->GetMembers(m_bMember ? AZ_PROP_GROUP_MEMBERS : AZ_PROP_GROUP_NON_MEMBERS,
  830. listWindowsGroups);
  831. BREAK_ON_FAIL_HRESULT(hr);
  832. hr = MakeBaseAzListToActionItemMap(listWindowsGroups,
  833. m_mapActionItem);
  834. BREAK_ON_FAIL_HRESULT(hr);
  835. //Add Members to list control
  836. AddActionItemFromMapToListCtrl(m_mapActionItem,
  837. &m_listCtrl,
  838. GetUIFlags(),
  839. FALSE);
  840. }while(0);
  841. if(FAILED(hr))
  842. {
  843. return FALSE;
  844. }
  845. //Sort the list control
  846. m_listCtrl.Sort();
  847. SetInit(TRUE);
  848. return TRUE;
  849. }
  850. void
  851. CGroupMemberPropertyPage::
  852. MakeControlsReadOnly()
  853. {
  854. TRACE_METHOD_EX(DEB_SNAPIN,CTaskDefinitionPropertyPage,MakeControlsReadOnly)
  855. GetDlgItem(IDC_ADD_APPLICATION_GROUP)->EnableWindow(FALSE);
  856. GetDlgItem(IDC_ADD_WINDOWS_GROUPS)->EnableWindow(FALSE);
  857. GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
  858. }
  859. void
  860. CGroupMemberPropertyPage::
  861. OnButtonAddApplicationGroups()
  862. {
  863. CBaseAz* pBaseAz = GetBaseAzObject();
  864. CList<CBaseAz*,CBaseAz*> listObjectsSelected;
  865. if(!GetSelectedAzObjects(m_hWnd,
  866. GROUP_AZ,
  867. pBaseAz->GetParentAz(),
  868. listObjectsSelected))
  869. {
  870. return;
  871. }
  872. AddMembers(listObjectsSelected,
  873. m_mapActionItem,
  874. GetUIFlags());
  875. }
  876. void
  877. CGroupMemberPropertyPage::
  878. OnButtonAddWindowsGroups()
  879. {
  880. CSidHandler* pSidHandler = GetBaseAzObject()->GetSidHandler();
  881. ASSERT(pSidHandler);
  882. //Display Object Picker and get list of Users to add
  883. CList<CBaseAz*,CBaseAz*> listWindowsGroups;
  884. HRESULT hr = pSidHandler->GetUserGroup(m_hWnd,
  885. GetBaseAzObject(),
  886. listWindowsGroups);
  887. if(FAILED(hr))
  888. {
  889. return;
  890. }
  891. TIMER("Time taken to AddMembers");
  892. AddMembers(listWindowsGroups,
  893. m_mapActionItem,
  894. GetUIFlags());
  895. }
  896. HRESULT
  897. CGroupMemberPropertyPage::
  898. DoOneAction(IN ActionItem* pActionItem,
  899. LONG )
  900. {
  901. TRACE_METHOD_EX(DEB_SNAPIN,CGroupMemberPropertyPage,DoOneAction)
  902. if(!pActionItem)
  903. {
  904. ASSERT(pActionItem);
  905. return E_POINTER;
  906. }
  907. CBaseAz* pBaseAz = GetBaseAzObject();
  908. CBaseAz* pMember = pActionItem->m_pMemberAz;
  909. LONG lPropId;
  910. if(pMember->GetObjectType() == GROUP_AZ)
  911. {
  912. lPropId = m_bMember ? AZ_PROP_GROUP_APP_MEMBERS : AZ_PROP_GROUP_APP_NON_MEMBERS;
  913. }
  914. else if(pMember->GetObjectType() == SIDCACHE_AZ)
  915. {
  916. lPropId = m_bMember ? AZ_PROP_GROUP_MEMBERS : AZ_PROP_GROUP_NON_MEMBERS;
  917. }
  918. if(pActionItem->action == ACTION_ADD)
  919. return pBaseAz->AddMember(lPropId,pMember);
  920. else
  921. return pBaseAz->RemoveMember(lPropId,pMember);
  922. }
  923. BOOL
  924. CGroupMemberPropertyPage::
  925. OnApply()
  926. {
  927. TRACE_METHOD_EX(DEB_SNAPIN,CGroupMemberPropertyPage,OnApply)
  928. if(!IsDirty())
  929. return TRUE;
  930. if(DoActionsFromActionMap(m_mapActionItem,0))
  931. {
  932. HRESULT hr = GetBaseAzObject()->Submit();
  933. if(FAILED(hr))
  934. {
  935. //Display Generic Error
  936. CString strError;
  937. GetSystemError(strError, hr);
  938. ::DisplayError(m_hWnd,
  939. IDS_GENERIC_PROPERTY_SAVE_ERROR,
  940. (LPCTSTR)strError);
  941. return FALSE;
  942. }
  943. else
  944. {
  945. SetDirty(FALSE);
  946. return TRUE;
  947. }
  948. }
  949. return FALSE;
  950. }
  951. /******************************************************************************
  952. Class: CSecurityPropertyPage
  953. Purpose: Security Property Page
  954. ******************************************************************************/
  955. BEGIN_MESSAGE_MAP(CSecurityPropertyPage, CListCtrlPropertyPage)
  956. //{{AFX_MSG_MAP(CGroupMemberPropertyPage)
  957. ON_BN_CLICKED(IDC_ADD, OnButtonAddWindowsGroups)
  958. ON_BN_CLICKED(IDC_REMOVE, OnButtonRemove)
  959. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_MEMBER, OnListCtrlItemChanged)
  960. ON_CBN_SELCHANGE(IDC_COMBO_USER_ROLE, OnComboBoxItemChanged)
  961. //}}AFX_MSG_MAP
  962. END_MESSAGE_MAP()
  963. CSecurityPropertyPage::
  964. ~CSecurityPropertyPage()
  965. {
  966. RemoveItemsFromActionMap(m_mapAdminActionItem);
  967. RemoveItemsFromActionMap(m_mapReadersActionItem);
  968. RemoveItemsFromActionMap(m_mapDelegatedUsersActionItem);
  969. }
  970. BOOL
  971. CSecurityPropertyPage::
  972. OnInitDialog()
  973. {
  974. HRESULT hr = S_OK;
  975. do
  976. {
  977. if(!CListCtrlPropertyPage::OnInitDialog())
  978. {
  979. hr = E_FAIL;
  980. break;
  981. }
  982. CContainerAz* pContainerAz = static_cast<CContainerAz*>(GetBaseAzObject());
  983. CComboBox *pComboBox = (CComboBoxEx*)GetDlgItem(IDC_COMBO_USER_ROLE);
  984. //Add Items to combo box
  985. CString strName;
  986. VERIFY(strName.LoadString(IDS_POLICY_ADMIN));
  987. pComboBox->InsertString(0,strName);
  988. pComboBox->SetItemData(0,AZ_PROP_POLICY_ADMINS);
  989. VERIFY(strName.LoadString(IDS_POLICY_READER));
  990. pComboBox->InsertString(1,strName);
  991. pComboBox->SetItemData(1,AZ_PROP_POLICY_READERS);
  992. m_bDelegatorPresent = pContainerAz->IsDelegatorSupported();
  993. if(m_bDelegatorPresent)
  994. {
  995. VERIFY(strName.LoadString(IDS_POLICY_DELEGATOR));
  996. pComboBox->InsertString(2,strName);
  997. pComboBox->SetItemData(2,AZ_PROP_DELEGATED_POLICY_USERS);
  998. }
  999. pComboBox->SetCurSel(0);
  1000. CList<CBaseAz*,CBaseAz*> listAdmins;
  1001. CList<CBaseAz*,CBaseAz*> listReaders;
  1002. CList<CBaseAz*,CBaseAz*> listDelegatedUsers;
  1003. //Get List of Administrators and add it to listbox
  1004. hr = GetPolicyUsersFromAllLevel(AZ_PROP_POLICY_ADMINS,
  1005. pContainerAz,
  1006. listAdmins);
  1007. BREAK_ON_FAIL_HRESULT(hr);
  1008. hr = MakeBaseAzListToActionItemMap(listAdmins,
  1009. m_mapAdminActionItem);
  1010. BREAK_ON_FAIL_HRESULT(hr);
  1011. AddActionItemFromMapToListCtrl(m_mapAdminActionItem,
  1012. &m_listCtrl,
  1013. GetUIFlags(),
  1014. FALSE);
  1015. //Get List of Readers
  1016. hr = GetPolicyUsersFromAllLevel(AZ_PROP_POLICY_READERS,
  1017. pContainerAz,
  1018. listReaders);
  1019. BREAK_ON_FAIL_HRESULT(hr);
  1020. hr = MakeBaseAzListToActionItemMap(listReaders,
  1021. m_mapReadersActionItem);
  1022. BREAK_ON_FAIL_HRESULT(hr);
  1023. if(m_bDelegatorPresent)
  1024. {
  1025. //Get List of Delegated users
  1026. hr = pContainerAz->GetMembers(AZ_PROP_DELEGATED_POLICY_USERS,
  1027. listDelegatedUsers);
  1028. BREAK_ON_FAIL_HRESULT(hr);
  1029. hr = MakeBaseAzListToActionItemMap(listDelegatedUsers,
  1030. m_mapDelegatedUsersActionItem);
  1031. BREAK_ON_FAIL_HRESULT(hr);
  1032. }
  1033. }while(0);
  1034. if(FAILED(hr))
  1035. {
  1036. return FALSE;
  1037. }
  1038. //Sort the list control
  1039. m_listCtrl.Sort();
  1040. SetInit(TRUE);
  1041. return TRUE;
  1042. }
  1043. ActionMap&
  1044. CSecurityPropertyPage::
  1045. GetListForComboSelection(LONG lComboSel)
  1046. {
  1047. if(lComboSel == AZ_PROP_POLICY_ADMINS)
  1048. return m_mapAdminActionItem;
  1049. else if(lComboSel == AZ_PROP_POLICY_READERS)
  1050. return m_mapReadersActionItem;
  1051. else //AZ_PROP_DELEGATED_POLICY_USERS
  1052. return m_mapDelegatedUsersActionItem;
  1053. }
  1054. void
  1055. CSecurityPropertyPage::
  1056. ReloadAdminList()
  1057. {
  1058. HRESULT hr = S_OK;
  1059. do
  1060. {
  1061. //We need to reload the Admin list if all the admins are removed.In that
  1062. //case core will add owner to the admin list and we need to refresh the
  1063. //list
  1064. m_mapAdminActionItem.clear();
  1065. CList<CBaseAz*,CBaseAz*> listAdmins;
  1066. CContainerAz* pContainerAz = static_cast<CContainerAz*>(GetBaseAzObject());
  1067. //Get List of Administrators and add it to listbox
  1068. hr = GetPolicyUsersFromAllLevel(AZ_PROP_POLICY_ADMINS,
  1069. pContainerAz,
  1070. listAdmins);
  1071. BREAK_ON_FAIL_HRESULT(hr);
  1072. hr = MakeBaseAzListToActionItemMap(listAdmins,
  1073. m_mapAdminActionItem);
  1074. BREAK_ON_FAIL_HRESULT(hr);
  1075. if(AZ_PROP_POLICY_ADMINS == m_LastComboSelection)
  1076. {
  1077. //Clear the current items from the list
  1078. m_listCtrl.DeleteAllItems();
  1079. AddActionItemFromMapToListCtrl(m_mapAdminActionItem,
  1080. &m_listCtrl,
  1081. GetUIFlags(),
  1082. FALSE);
  1083. }
  1084. }while(0);
  1085. //ToDO Display Error in case of failure
  1086. }
  1087. void
  1088. CSecurityPropertyPage::
  1089. MakeControlsReadOnly()
  1090. {
  1091. TRACE_METHOD_EX(DEB_SNAPIN,CTaskDefinitionPropertyPage,MakeControlsReadOnly)
  1092. GetDlgItem(IDC_ADD)->EnableWindow(FALSE);
  1093. GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
  1094. }
  1095. BOOL
  1096. CSecurityPropertyPage::
  1097. HandleBizruleScopeInteraction()
  1098. {
  1099. TRACE_METHOD_EX(DEB_SNAPIN,CTaskDefinitionPropertyPage,HandleBizruleScopeInteraction)
  1100. //Delegation is not allowed in ceratin conditions at scope level for AD
  1101. //store.
  1102. //Check if we are at scope level, store type is AD and we are modifying
  1103. //AZ_PROP_POLICY_ADMINS
  1104. CBaseAz* pBaseAz = GetBaseAzObject();
  1105. if(pBaseAz->GetObjectType() != SCOPE_AZ ||
  1106. pBaseAz->GetAdminManager()->GetStoreType() != AZ_ADMIN_STORE_AD ||
  1107. m_LastComboSelection != AZ_PROP_POLICY_ADMINS)
  1108. {
  1109. return TRUE;
  1110. }
  1111. CScopeAz* pScopeAz = dynamic_cast<CScopeAz*>(pBaseAz);
  1112. if(!pScopeAz)
  1113. {
  1114. ASSERT(pScopeAz);
  1115. return FALSE;
  1116. }
  1117. //Condition 1: Scope is not delegatable which is true when There are
  1118. //authorization scripts in objects defined in the scope.
  1119. //If now user assigns someone to the Admin role for the scope
  1120. //(by clicking Add):
  1121. BOOL bDelegatable = FALSE;
  1122. HRESULT hr = pScopeAz->CanScopeBeDelegated(bDelegatable);
  1123. if(FAILED(hr))
  1124. {
  1125. //Lets try to add and we will fail eventually and show the error
  1126. return TRUE;
  1127. }
  1128. if(!bDelegatable)
  1129. {
  1130. DisplayError(m_hWnd,
  1131. IDS_SCOPE_NOT_DELEGATABLE,
  1132. (LPCWSTR)pScopeAz->GetName());
  1133. return FALSE;
  1134. }
  1135. //Condition 2: The scope has not been delegated and there are not
  1136. //authorization scripts in objects defined in the scope, and the user
  1137. //now assigns someone to the Admin role for the scope (by clicking Add
  1138. //and selecting a user).
  1139. BOOL bScriptWritable = FALSE;
  1140. hr = pScopeAz->BizRulesWritable(bScriptWritable);
  1141. if(SUCCEEDED(hr) && bScriptWritable)
  1142. {
  1143. DisplayInformation(m_hWnd,
  1144. IDS_DELEGATING_PREVENTS_SCRIPTS,
  1145. (LPCWSTR)pScopeAz->GetName());
  1146. }
  1147. return TRUE;
  1148. }
  1149. void
  1150. CSecurityPropertyPage::
  1151. OnButtonAddWindowsGroups()
  1152. {
  1153. TRACE_METHOD_EX(DEB_SNAPIN,CTaskDefinitionPropertyPage,OnButtonAddWindowsGroups)
  1154. if(!HandleBizruleScopeInteraction())
  1155. return;
  1156. CSidHandler* pSidHandler = GetBaseAzObject()->GetSidHandler();
  1157. ASSERT(pSidHandler);
  1158. //Display Object Picker and get list of Users to add
  1159. CList<CBaseAz*,CBaseAz*> listWindowsGroups;
  1160. HRESULT hr = pSidHandler->GetUserGroup(m_hWnd,
  1161. GetBaseAzObject(),
  1162. listWindowsGroups);
  1163. if(FAILED(hr))
  1164. {
  1165. return;
  1166. }
  1167. BOOL m_bAdminSelected = TRUE;
  1168. AddMembers(listWindowsGroups,
  1169. GetListForComboSelection(m_LastComboSelection),
  1170. GetUIFlags());
  1171. }
  1172. void
  1173. CSecurityPropertyPage::
  1174. OnButtonRemove()
  1175. {
  1176. TRACE_METHOD_EX(DEB_SNAPIN,CSecurityPropertyPage,OnButtonRemove)
  1177. //
  1178. //Only entries that were defined at this object level can
  1179. //be deleted. Entries which are inherited from parent cannot
  1180. //be deleted here. Check if there is atleast one entry which
  1181. //can be deleted.
  1182. //
  1183. CBaseAz* pBaseAz = GetBaseAzObject();
  1184. BOOL bAtleastOneInherited = FALSE;
  1185. BOOL bAtleastOneExplicit = FALSE;
  1186. int iSelectedItem = -1;
  1187. while( (iSelectedItem = m_listCtrl.GetNextItem(iSelectedItem, LVIS_SELECTED)) != -1)
  1188. {
  1189. ActionItem* pActionItem = (ActionItem*)m_listCtrl.GetItemData(iSelectedItem);
  1190. CSidCacheAz * pSidCacheAz = (CSidCacheAz *)pActionItem->m_pMemberAz;
  1191. if(pBaseAz->GetType() == pSidCacheAz->GetParentType())
  1192. {
  1193. bAtleastOneExplicit = TRUE;
  1194. }
  1195. else
  1196. {
  1197. bAtleastOneInherited = TRUE;
  1198. }
  1199. }
  1200. if(bAtleastOneInherited && !bAtleastOneExplicit)
  1201. {
  1202. ::DisplayInformation(m_hWnd,IDS_ALL_POLICY_USERS_INHERITED);
  1203. return;
  1204. }
  1205. else if(bAtleastOneInherited && bAtleastOneExplicit)
  1206. {
  1207. //Ask user if wants to delete explict entries
  1208. if(IDNO == ::DisplayConfirmation(m_hWnd,IDS_SOME_POLICY_USERS_INHERITED))
  1209. return;
  1210. }
  1211. //Remember the Position of first selected entry.
  1212. int iFirstSelectedItem = m_listCtrl.GetNextItem(-1, LVIS_SELECTED);
  1213. iSelectedItem = -1;
  1214. while( (iSelectedItem = m_listCtrl.GetNextItem(iSelectedItem, LVIS_SELECTED)) != -1)
  1215. {
  1216. ActionItem* pActionItem = (ActionItem*)m_listCtrl.GetItemData(iSelectedItem);
  1217. CSidCacheAz * pSidCacheAz = (CSidCacheAz *)pActionItem->m_pMemberAz;
  1218. if(pBaseAz->GetType() == pSidCacheAz->GetParentType())
  1219. {
  1220. RemoveMember(pActionItem);
  1221. m_listCtrl.DeleteItem(iSelectedItem);
  1222. iSelectedItem--;
  1223. }
  1224. }
  1225. if(m_listCtrl.GetItemCount() <= iFirstSelectedItem)
  1226. --iFirstSelectedItem;
  1227. SelectListCtrlItem(&m_listCtrl, iFirstSelectedItem);
  1228. }
  1229. void
  1230. CSecurityPropertyPage::
  1231. OnComboBoxItemChanged()
  1232. {
  1233. TRACE_METHOD_EX(DEB_SNAPIN,CSecurityPropertyPage,OnComboBoxItemChanged)
  1234. CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_USER_ROLE);
  1235. LONG lComboSelection = (LONG)pComboBox->GetItemData(pComboBox->GetCurSel());
  1236. if(lComboSelection == m_LastComboSelection)
  1237. return;
  1238. m_listCtrl.DeleteAllItems();
  1239. GetRemoveButton()->EnableWindow(FALSE);
  1240. m_LastComboSelection = lComboSelection;
  1241. AddActionItemFromMapToListCtrl(GetListForComboSelection(m_LastComboSelection),
  1242. &m_listCtrl,
  1243. GetUIFlags(),
  1244. FALSE);
  1245. //Resort the items
  1246. m_listCtrl.Sort();
  1247. }
  1248. BOOL
  1249. CSecurityPropertyPage::
  1250. EqualObjects(CBaseAz* p1, CBaseAz* p2)
  1251. {
  1252. /* p1 is the item already in the list and p2 is the new item we are tying
  1253. to add. p1 and p2 are equal if and only if their names, objecttype and
  1254. parent type are equal. In security page, we only list sid objects and
  1255. since sid object doesn't have parents, GetParentType for sid objcet
  1256. returns the name of object sid is assigned to.*/
  1257. if(p1 &&
  1258. p2 &&
  1259. (p1->GetObjectType() == p2->GetObjectType()) &&
  1260. (p1->GetName() == p2->GetName()) &&
  1261. (p1->GetParentType() == GetBaseAzObject()->GetType()))
  1262. {
  1263. return TRUE;
  1264. }
  1265. return FALSE;
  1266. }
  1267. HRESULT
  1268. CSecurityPropertyPage::
  1269. DoOneAction(ActionItem* pActionItem,
  1270. LONG lPropId)
  1271. {
  1272. TRACE_METHOD_EX(DEB_SNAPIN,CSecurityPropertyPage,DoOneAction)
  1273. CBaseAz* pBaseAz = GetBaseAzObject();
  1274. if(pActionItem->action == ACTION_ADD)
  1275. return pBaseAz->AddMember(lPropId,
  1276. pActionItem->m_pMemberAz);
  1277. else
  1278. return pBaseAz->RemoveMember(lPropId,
  1279. pActionItem->m_pMemberAz);
  1280. }
  1281. BOOL
  1282. CSecurityPropertyPage::
  1283. OnApply()
  1284. {
  1285. TRACE_METHOD_EX(DEB_SNAPIN,CSecurityPropertyPage,OnApply)
  1286. if(!IsDirty())
  1287. return TRUE;
  1288. if(DoActionsFromActionMap(m_mapAdminActionItem,AZ_PROP_POLICY_ADMINS) &&
  1289. DoActionsFromActionMap(m_mapReadersActionItem,AZ_PROP_POLICY_READERS) &&
  1290. DoActionsFromActionMap(m_mapDelegatedUsersActionItem,AZ_PROP_DELEGATED_POLICY_USERS))
  1291. {
  1292. HRESULT hr = GetBaseAzObject()->Submit();
  1293. if(FAILED(hr))
  1294. {
  1295. //Display Generic Error
  1296. CString strError;
  1297. GetSystemError(strError, hr);
  1298. ::DisplayError(m_hWnd,
  1299. IDS_GENERIC_PROPERTY_SAVE_ERROR,
  1300. (LPCTSTR)strError);
  1301. return FALSE;
  1302. }
  1303. else
  1304. {
  1305. ReloadAdminList();
  1306. SetDirty(FALSE);
  1307. return TRUE;
  1308. }
  1309. }
  1310. return FALSE;
  1311. }
  1312. /******************************************************************************
  1313. Class: CAuditPropertyPage
  1314. Purpose: Audit Property Page
  1315. ******************************************************************************/
  1316. BEGIN_MESSAGE_MAP(CAuditPropertyPage,CBaseRolePropertyPage)
  1317. ON_BN_CLICKED(IDC_AUDIT_AUTHORIZATION_MANAGER, OnDirty)
  1318. ON_BN_CLICKED(IDC_AUDIT_STORE, OnDirty)
  1319. ON_NOTIFY(NM_CLICK, IDC_AUDIT_HELP_LINK, OnLinkClick)
  1320. ON_NOTIFY(NM_RETURN, IDC_AUDIT_HELP_LINK, OnLinkClick)
  1321. END_MESSAGE_MAP()
  1322. void
  1323. CAuditPropertyPage::
  1324. OnLinkClick(NMHDR* /*pNotifyStruct*/, LRESULT* /*pResult*/)
  1325. {
  1326. CDisplayHelpFromPropPageExecContext ctx;
  1327. ctx.m_strHelpPath= L"AuthM.chm::/authm_resources.htm";
  1328. ctx.m_pComponentDataObject= GetBaseNode()->GetComponentDataObject();
  1329. VERIFY(GetBaseNode()->GetComponentDataObject()->PostExecMessage(&ctx,NULL));
  1330. ctx.Wait();
  1331. }
  1332. BOOL
  1333. CAuditPropertyPage::
  1334. OnInitDialog()
  1335. {
  1336. TRACE_METHOD_EX(DEB_SNAPIN,CAuditPropertyPage,OnInitDialog)
  1337. CBaseAz* pBaseAz = GetBaseAzObject();
  1338. //At application level runtime auditing has different
  1339. //lable
  1340. if(APPLICATION_AZ == pBaseAz->GetObjectType())
  1341. {
  1342. CString strLabel;
  1343. if(strLabel.LoadString(IDS_APP_AUDIT_STRING))
  1344. {
  1345. GetDlgItem(IDC_AUDIT_AUTHORIZATION_MANAGER)->SetWindowText(strLabel);
  1346. }
  1347. }
  1348. BOOL bGenerateAudit = FALSE;
  1349. BOOL bStoreSacl = FALSE;
  1350. //Check is Generation of Audit by authorization store is supported
  1351. if(SUCCEEDED(pBaseAz->GetProperty(AZ_PROP_GENERATE_AUDITS,&bGenerateAudit)))
  1352. {
  1353. m_bRunTimeAuditSupported = TRUE;
  1354. }
  1355. //Check if Generation of Audit by underlying store is supported
  1356. if(SUCCEEDED(pBaseAz->GetProperty(AZ_PROP_APPLY_STORE_SACL,&bStoreSacl)))
  1357. {
  1358. m_bStoreSaclSupported = TRUE;
  1359. }
  1360. CButton* pBtnRuntimeAudit = (CButton*)GetDlgItem(IDC_AUDIT_AUTHORIZATION_MANAGER);
  1361. CButton* pBtnSacl = (CButton*)GetDlgItem(IDC_AUDIT_STORE);
  1362. if(IsReadOnly())
  1363. {
  1364. pBtnRuntimeAudit->EnableWindow(FALSE);
  1365. pBtnSacl->EnableWindow(FALSE);
  1366. }
  1367. if(m_bRunTimeAuditSupported)
  1368. {
  1369. pBtnRuntimeAudit->SetCheck(bGenerateAudit ? BST_CHECKED : BST_UNCHECKED);
  1370. }
  1371. BOOL bParentStateStaticVisible = FALSE;
  1372. if(m_bStoreSaclSupported)
  1373. {
  1374. pBtnSacl->SetCheck(bStoreSacl ? BST_CHECKED : BST_UNCHECKED);
  1375. int idStrParentState = GetParentAuditStateStringId(AZ_PROP_APPLY_STORE_SACL);
  1376. if(idStrParentState != -1)
  1377. {
  1378. CString strParentState;
  1379. strParentState.LoadString(idStrParentState);
  1380. GetDlgItem(IDC_PARENT_SACL_STATE)->SetWindowText(strParentState);
  1381. bParentStateStaticVisible = TRUE;
  1382. }
  1383. }
  1384. MoveAndHideControls(m_bRunTimeAuditSupported,
  1385. m_bStoreSaclSupported,
  1386. bParentStateStaticVisible);
  1387. SetInit(TRUE);
  1388. return TRUE;
  1389. }
  1390. //+----------------------------------------------------------------------------
  1391. // Function: MoveAndHideControls
  1392. // Synopsis: Helper function to move and hide controls at initialization time
  1393. //-----------------------------------------------------------------------------
  1394. void
  1395. CAuditPropertyPage::
  1396. MoveAndHideControls(BOOL bRunTimeAuditSupported,
  1397. BOOL bStoreSaclSupported,
  1398. BOOL bParentStateShown)
  1399. {
  1400. //
  1401. //There is assumption here that controls are in following order.
  1402. //1)Runtime Client Context checkbox
  1403. //2)Policy store change checkbox
  1404. //3)Static control displayig state of 2) at parent level
  1405. //4)Help link
  1406. //
  1407. //if this order is getting changed. Order of this code must be changed.
  1408. //Get Coordinates of controls
  1409. RECT rcRuntimeAuditCheckBox;
  1410. ZeroMemory(&rcRuntimeAuditCheckBox, sizeof(RECT));
  1411. CButton* pBtnRuntimeAudit = (CButton*)GetDlgItem(IDC_AUDIT_AUTHORIZATION_MANAGER);
  1412. pBtnRuntimeAudit->GetClientRect(&rcRuntimeAuditCheckBox);
  1413. pBtnRuntimeAudit->MapWindowPoints(this,&rcRuntimeAuditCheckBox);
  1414. RECT rcSaclCheckBox;
  1415. ZeroMemory(&rcSaclCheckBox, sizeof(RECT));
  1416. CButton* pBtnSacl = (CButton*)GetDlgItem(IDC_AUDIT_STORE);
  1417. pBtnSacl->GetClientRect(&rcSaclCheckBox);
  1418. pBtnSacl->MapWindowPoints(this,&rcSaclCheckBox);
  1419. RECT rcParentStateStatic;
  1420. ZeroMemory(&rcParentStateStatic, sizeof(RECT));
  1421. CWnd* pParentStateStaic = GetDlgItem(IDC_PARENT_SACL_STATE);
  1422. pParentStateStaic->GetClientRect(&rcParentStateStatic);
  1423. pParentStateStaic->MapWindowPoints(this,&rcParentStateStatic);
  1424. RECT rcHelpLinkWindow;
  1425. ZeroMemory(&rcHelpLinkWindow, sizeof(RECT));
  1426. CWnd* pHelpLinkWindow = GetDlgItem(IDC_AUDIT_HELP_LINK);
  1427. pHelpLinkWindow->GetClientRect(&rcHelpLinkWindow);
  1428. pHelpLinkWindow->MapWindowPoints(this,&rcHelpLinkWindow);
  1429. int iMoveup = 0;
  1430. if(!bRunTimeAuditSupported)
  1431. {
  1432. pBtnRuntimeAudit->ShowWindow(SW_HIDE);
  1433. iMoveup = rcSaclCheckBox.top - rcRuntimeAuditCheckBox.top;
  1434. }
  1435. if(bStoreSaclSupported)
  1436. {
  1437. if(iMoveup)
  1438. {
  1439. rcSaclCheckBox.top -= iMoveup;
  1440. rcSaclCheckBox.bottom -= iMoveup;
  1441. pBtnSacl->MoveWindow(&rcSaclCheckBox);
  1442. }
  1443. }
  1444. else
  1445. {
  1446. pBtnSacl->ShowWindow(SW_HIDE);
  1447. iMoveup += (rcParentStateStatic.top - rcSaclCheckBox.top);
  1448. }
  1449. if(bParentStateShown)
  1450. {
  1451. if(iMoveup)
  1452. {
  1453. rcParentStateStatic.top -= iMoveup;
  1454. rcParentStateStatic.bottom -= iMoveup;
  1455. pParentStateStaic->MoveWindow(&rcParentStateStatic);
  1456. }
  1457. }
  1458. else
  1459. {
  1460. pParentStateStaic->ShowWindow(SW_HIDE);
  1461. iMoveup += (rcHelpLinkWindow.top - rcParentStateStatic.top);
  1462. }
  1463. if(iMoveup)
  1464. {
  1465. rcHelpLinkWindow.top -= iMoveup;
  1466. rcHelpLinkWindow.bottom -= iMoveup;
  1467. pHelpLinkWindow->MoveWindow(&rcHelpLinkWindow);
  1468. }
  1469. }
  1470. //+----------------------------------------------------------------------------
  1471. // Function: GetParentAuditStateStringId
  1472. // Synopsis: This function gets resource id for message which explains
  1473. // if lPropId is already set at parents
  1474. // Arguments:
  1475. // Returns: -1 the message is not to be displayed.
  1476. //-----------------------------------------------------------------------------
  1477. int
  1478. CAuditPropertyPage::
  1479. GetParentAuditStateStringId(LONG lPropId)
  1480. {
  1481. TRACE_METHOD_EX(DEB_SNAPIN,CAuditPropertyPage,GetParentAuditStateStringId)
  1482. if(lPropId != AZ_PROP_APPLY_STORE_SACL)
  1483. {
  1484. ASSERT(FALSE);
  1485. return -1;
  1486. }
  1487. CBaseAz* pBaseAz = GetBaseAzObject();
  1488. BOOL bPropSetForApp = FALSE;
  1489. BOOL bPropSetForAuthMan = FALSE;
  1490. if(pBaseAz->GetObjectType() == SCOPE_AZ)
  1491. {
  1492. //Check if Applicaiton has this property set
  1493. CBaseAz* pApplicationAz = pBaseAz->GetParentAz();
  1494. if(FAILED(pApplicationAz->GetProperty(lPropId,&bPropSetForApp)))
  1495. {
  1496. bPropSetForApp = FALSE;
  1497. }
  1498. //Check if Authorization Manager has this property set
  1499. CBaseAz* pAuthorizationManager = pApplicationAz->GetParentAz();
  1500. if(FAILED(pAuthorizationManager->GetProperty(lPropId,&bPropSetForAuthMan)))
  1501. {
  1502. bPropSetForAuthMan = FALSE;
  1503. }
  1504. }
  1505. else if(pBaseAz->GetObjectType() == APPLICATION_AZ)
  1506. {
  1507. //
  1508. //Check if Authorization Manager has this property set
  1509. //
  1510. CBaseAz* pAuthorizationManager = pBaseAz->GetParentAz();
  1511. ASSERT(pAuthorizationManager);
  1512. if(FAILED(pAuthorizationManager->GetProperty(lPropId,&bPropSetForAuthMan)))
  1513. {
  1514. bPropSetForAuthMan = FALSE;
  1515. }
  1516. }
  1517. int idstr = -1;
  1518. if(bPropSetForAuthMan && bPropSetForApp)
  1519. {
  1520. idstr = IDS_SACL_SET_FOR_APP_AUTH;
  1521. }
  1522. else if(bPropSetForAuthMan)
  1523. {
  1524. idstr = IDS_SACL_SET_FOR_AUTH;
  1525. }
  1526. else if(bPropSetForApp)
  1527. {
  1528. idstr = IDS_SACL_SET_FOR_APP;
  1529. }
  1530. return idstr;
  1531. }
  1532. BOOL
  1533. CAuditPropertyPage::
  1534. OnApply()
  1535. {
  1536. TRACE_METHOD_EX(DEB_SNAPIN,CAuditPropertyPage,OnApply)
  1537. if(!IsDirty())
  1538. return TRUE;
  1539. HRESULT hr = S_OK;
  1540. BOOL bDisplayAuditMessageBox = FALSE;
  1541. CBaseAz* pBaseAz = GetBaseAzObject();
  1542. do
  1543. {
  1544. if(m_bRunTimeAuditSupported)
  1545. {
  1546. //Get the original setting
  1547. BOOL bOriginalSetting = FALSE;
  1548. hr = pBaseAz->GetProperty(AZ_PROP_GENERATE_AUDITS,&bOriginalSetting);
  1549. BREAK_ON_FAIL_HRESULT(hr);
  1550. //Get the new setting
  1551. CButton* pBtn = (CButton*)GetDlgItem(IDC_AUDIT_AUTHORIZATION_MANAGER);
  1552. BOOL bNewSetting = (pBtn->GetCheck() == BST_CHECKED);
  1553. if(bNewSetting != bOriginalSetting)
  1554. {
  1555. if(bNewSetting)
  1556. {
  1557. //We are turning auditing on, show the messagebox
  1558. bDisplayAuditMessageBox = TRUE;
  1559. }
  1560. hr = pBaseAz->SetProperty(AZ_PROP_GENERATE_AUDITS,bNewSetting);
  1561. BREAK_ON_FAIL_HRESULT(hr);
  1562. }
  1563. }
  1564. if(m_bStoreSaclSupported)
  1565. {
  1566. //Get the original setting
  1567. BOOL bOriginalSetting = FALSE;
  1568. hr = pBaseAz->GetProperty(AZ_PROP_APPLY_STORE_SACL,&bOriginalSetting);
  1569. BREAK_ON_FAIL_HRESULT(hr);
  1570. //Get the new setting
  1571. CButton * pBtn = (CButton*)GetDlgItem(IDC_AUDIT_STORE);
  1572. BOOL bNewSetting = (pBtn->GetCheck() == BST_CHECKED);
  1573. if(bNewSetting != bOriginalSetting)
  1574. {
  1575. if(bNewSetting)
  1576. {
  1577. //We are turning auditing on, show the messagebox
  1578. bDisplayAuditMessageBox = TRUE;
  1579. }
  1580. hr = pBaseAz->SetProperty(AZ_PROP_APPLY_STORE_SACL,(pBtn->GetCheck() == BST_CHECKED));
  1581. BREAK_ON_FAIL_HRESULT(hr);
  1582. }
  1583. }
  1584. }while(0);
  1585. if(SUCCEEDED(hr))
  1586. {
  1587. hr = pBaseAz->Submit();
  1588. CHECK_HRESULT(hr);
  1589. }
  1590. if(FAILED(hr))
  1591. {
  1592. //Display Generic Error
  1593. CString strError;
  1594. GetSystemError(strError, hr);
  1595. ::DisplayError(m_hWnd,
  1596. IDS_GENERIC_PROPERTY_SAVE_ERROR,
  1597. (LPCTSTR)strError);
  1598. return FALSE;
  1599. }
  1600. else
  1601. {
  1602. //Everything successful. Display Audit Message if required
  1603. if(bDisplayAuditMessageBox)
  1604. {
  1605. DisplayWarning(m_hWnd,IDS_AUDIT_REQUIRE_EXTRA_SETTING);
  1606. }
  1607. SetDirty(FALSE);
  1608. return TRUE;
  1609. }
  1610. }
  1611. /******************************************************************************
  1612. Class: CRoleGeneralPropertyPage
  1613. Purpose: General Property Page for Role
  1614. ******************************************************************************/
  1615. BEGIN_MESSAGE_MAP(CRoleGeneralPropertyPage, CGeneralPropertyPage)
  1616. ON_EN_CHANGE(IDC_EDIT_NAME, OnDirty)
  1617. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnDirty)
  1618. ON_BN_CLICKED(IDC_BUTTON_DEFINITION,OnShowDefinition)
  1619. END_MESSAGE_MAP()
  1620. void
  1621. CRoleGeneralPropertyPage::
  1622. OnShowDefinition()
  1623. {
  1624. TRACE_METHOD_EX(DEB_SNAPIN,CRoleGeneralPropertyPage,OnShowDefinition)
  1625. CRoleAz* pRoleAz = dynamic_cast<CRoleAz*>(GetBaseAzObject());
  1626. ASSERT(pRoleAz);
  1627. HRESULT hr = S_OK;
  1628. do
  1629. {
  1630. //Get Member Tasks
  1631. CList<CBaseAz*,CBaseAz*> listTask;
  1632. hr = pRoleAz->GetMembers(AZ_PROP_ROLE_TASKS, listTask);
  1633. BREAK_ON_FAIL_HRESULT(hr);
  1634. //Get Member Operations
  1635. CList<CBaseAz*, CBaseAz*> listOperations;
  1636. hr = pRoleAz->GetMembers(AZ_PROP_ROLE_OPERATIONS, listOperations);
  1637. BREAK_ON_FAIL_HRESULT(hr);
  1638. BOOL bRoleFromDefinition = FALSE;
  1639. //A Role Created From Role Definition( i.e. created via snapin)
  1640. //should not have any member operations and should only have only
  1641. //one task and that task should have RoleDefinition Bit on.
  1642. if(listOperations.IsEmpty() && listTask.GetCount() == 1)
  1643. {
  1644. CTaskAz* pTaskAz = (CTaskAz*)listTask.GetHead();
  1645. if(pTaskAz->IsRoleDefinition())
  1646. {
  1647. bRoleFromDefinition = TRUE;
  1648. if(!DisplayRoleDefintionPropertyPages(pTaskAz))
  1649. {
  1650. RemoveItemsFromList(listTask);
  1651. }
  1652. }
  1653. }
  1654. if(!bRoleFromDefinition)
  1655. {
  1656. RemoveItemsFromList(listTask);
  1657. RemoveItemsFromList(listOperations);
  1658. CRoleDefDialog dlgRoleDef(*pRoleAz);
  1659. dlgRoleDef.DoModal();
  1660. }
  1661. }while(0);
  1662. }
  1663. BOOL
  1664. CRoleGeneralPropertyPage::
  1665. DisplayRoleDefintionPropertyPages(IN CTaskAz* pTaskAz)
  1666. {
  1667. TRACE_METHOD_EX(DEB_SNAPIN,CRoleGeneralPropertyPage,DisplayRoleDefintionPropertyPages)
  1668. if(!pTaskAz)
  1669. {
  1670. ASSERT(pTaskAz);
  1671. return FALSE;
  1672. }
  1673. HRESULT hr = S_OK;
  1674. do
  1675. {
  1676. //Create a Node for it(COOKIE)
  1677. CTaskNode * pTaskNode = new CTaskNode(GetBaseNode()->GetComponentDataObject(),
  1678. GetBaseNode()->GetAdminManagerNode(),
  1679. pTaskAz);
  1680. if(!pTaskNode)
  1681. {
  1682. hr = E_OUTOFMEMORY;
  1683. break;
  1684. }
  1685. pTaskNode->NodeForPropSheet();
  1686. pTaskNode->SetContainer(GetBaseNode()->GetAdminManagerNode());
  1687. CPropPageExecContext ctx;
  1688. ctx.pTreeNode = pTaskNode;
  1689. ctx.pComponentDataObject = GetBaseNode()->GetComponentDataObject();
  1690. VERIFY(GetBaseNode()->GetComponentDataObject()->PostExecMessage(&ctx,(WPARAM)FALSE));
  1691. ctx.Wait();
  1692. }while(0);
  1693. if(SUCCEEDED(hr))
  1694. return TRUE;
  1695. else
  1696. return FALSE;
  1697. }
  1698. HRESULT
  1699. AddSingleActionItem(IN CBaseAz* pMemberAz,
  1700. IN CSortListCtrl& refListCtrl,
  1701. IN OUT CList<ActionItem*,ActionItem*>& listActionItem,
  1702. IN UINT uiFlags)
  1703. {
  1704. if(!pMemberAz)
  1705. {
  1706. ASSERT(pMemberAz);
  1707. return E_POINTER;
  1708. }
  1709. //
  1710. //Check if item is already present in the list
  1711. //
  1712. ActionItem* pCurActionItem = NULL;
  1713. POSITION pos = listActionItem.GetHeadPosition();
  1714. for( int i = 0; i < listActionItem.GetCount(); ++i)
  1715. {
  1716. pCurActionItem = listActionItem.GetNext(pos);
  1717. if(pCurActionItem->action == ACTION_REMOVED)
  1718. {
  1719. pCurActionItem = NULL;
  1720. continue;
  1721. }
  1722. CBaseAz* pCurBaseAz = pCurActionItem->m_pMemberAz;
  1723. ASSERT(pCurBaseAz);
  1724. if((pCurBaseAz->GetObjectType() == pMemberAz->GetObjectType()) &&
  1725. (pCurBaseAz->GetName() == pMemberAz->GetName()))
  1726. {
  1727. //Item already present
  1728. break;
  1729. }
  1730. pCurActionItem = NULL;
  1731. pCurBaseAz = NULL;
  1732. }
  1733. //
  1734. //Item is already in the list
  1735. //
  1736. if(pCurActionItem)
  1737. {
  1738. //
  1739. //If Pending action on the item is remove, change it to none
  1740. //
  1741. if(pCurActionItem->action == ACTION_REMOVE)
  1742. {
  1743. pCurActionItem->action = ACTION_NONE;
  1744. }
  1745. else //pCurActionItem->action == ACTION_NONE
  1746. //pCurActionItem->action == ACTION_ADD
  1747. {
  1748. return HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS);
  1749. }
  1750. }
  1751. else
  1752. {
  1753. //Create a new Action item
  1754. pCurActionItem = new ActionItem(pMemberAz);
  1755. if(!pCurActionItem)
  1756. return E_OUTOFMEMORY;
  1757. pCurActionItem->action = ACTION_ADD;
  1758. listActionItem.AddTail(pCurActionItem);
  1759. }
  1760. //Add Current Item to listcontrol
  1761. AddActionItemToListCtrl(&refListCtrl,
  1762. 0,
  1763. pCurActionItem,
  1764. uiFlags);
  1765. return S_OK;
  1766. }
  1767. //+----------------------------------------------------------------------------
  1768. // Function:AddMembers
  1769. // Synopsis:Add List of BaseAz items to list of action items.
  1770. //-----------------------------------------------------------------------------
  1771. void
  1772. AddActionItems(IN CList<CBaseAz*,CBaseAz*>& listMembers,
  1773. IN CSortListCtrl& refListCtrl,
  1774. IN HWND hWnd,
  1775. IN OUT CList<ActionItem*,ActionItem*>& listActionItem,
  1776. IN UINT uiFlags)
  1777. {
  1778. TRACE_FUNCTION_EX(DEB_SNAPIN,AddActionItems)
  1779. if(listMembers.IsEmpty())
  1780. return ;
  1781. while(listMembers.GetCount())
  1782. {
  1783. //Add Member
  1784. CBaseAz* pMember = listMembers.RemoveHead();
  1785. ASSERT(pMember);
  1786. HRESULT hr = AddSingleActionItem(pMember,
  1787. refListCtrl,
  1788. listActionItem,
  1789. uiFlags);
  1790. if(FAILED(hr))
  1791. {
  1792. if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
  1793. {
  1794. hr = S_OK;
  1795. }
  1796. else
  1797. {
  1798. //Display Generic Error.
  1799. CString strError;
  1800. GetSystemError(strError, hr);
  1801. ::DisplayError(hWnd,
  1802. IDS_ERROR_ADD_MEMBER_OBJECT,
  1803. (LPCTSTR)strError,
  1804. (LPCTSTR)pMember->GetName());
  1805. }
  1806. delete pMember;
  1807. pMember = NULL;
  1808. }
  1809. }
  1810. refListCtrl.Sort();
  1811. }
  1812. void
  1813. RemoveMember(ActionItem* pActionItem)
  1814. {
  1815. if(!pActionItem)
  1816. {
  1817. ASSERT(pActionItem);
  1818. return;
  1819. }
  1820. if(pActionItem->action == ACTION_NONE)
  1821. pActionItem->action = ACTION_REMOVE;
  1822. else
  1823. {
  1824. //If this item was a newly added item,
  1825. //marked it Removed. We won't attepmt to
  1826. //remove it from the object
  1827. pActionItem->action = ACTION_REMOVED;
  1828. }
  1829. }
  1830. /******************************************************************************
  1831. Class: CRoleDefDialog
  1832. Purpose: Displays the role definition for role created out side UI.
  1833. ******************************************************************************/
  1834. BEGIN_MESSAGE_MAP(CRoleDefDialog, CHelpEnabledDialog)
  1835. //{{AFX_MSG_MAP(CTaskDefinitionPropertyPage)
  1836. ON_BN_CLICKED(IDC_ADD, OnButtonAdd)
  1837. ON_BN_CLICKED(IDC_REMOVE, OnButtonRemove)
  1838. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_OP_TASK, OnListCtrlItemChanged)
  1839. ON_NOTIFY(LVN_DELETEITEM, IDC_LIST_OP_TASK, OnListCtrlItemDeleted)
  1840. ON_NOTIFY(LVN_INSERTITEM, IDC_LIST_OP_TASK, OnListCtrlItemInserted)
  1841. //}}AFX_MSG_MAP
  1842. END_MESSAGE_MAP()
  1843. CRoleDefDialog::
  1844. CRoleDefDialog(CRoleAz& refRoleAz)
  1845. :CHelpEnabledDialog(IDD_ROLE_DEF_DIALOG),
  1846. m_refRoleAz(refRoleAz),
  1847. m_bDirty(FALSE),
  1848. m_listCtrl(COL_NAME | COL_TYPE | COL_DESCRIPTION,
  1849. TRUE,
  1850. Col_For_Task_Role)
  1851. {
  1852. //Check if Role Object is Readonly
  1853. BOOL bWrite = FALSE;
  1854. m_bReadOnly = TRUE;
  1855. HRESULT hr = m_refRoleAz.IsWritable(bWrite);
  1856. if(SUCCEEDED(hr))
  1857. m_bReadOnly = !bWrite;
  1858. }
  1859. CRoleDefDialog::
  1860. ~CRoleDefDialog()
  1861. {
  1862. RemoveItemsFromList(m_listActionItem);
  1863. }
  1864. BOOL
  1865. CRoleDefDialog::
  1866. OnInitDialog()
  1867. {
  1868. TRACE_METHOD_EX(DEB_SNAPIN,CRoleDefDialog,OnInitDialog)
  1869. VERIFY(m_listCtrl.SubclassDlgItem(IDC_LIST_OP_TASK,this));
  1870. m_listCtrl.Initialize();
  1871. HRESULT hr = S_OK;
  1872. do
  1873. {
  1874. //Add Member Tasks
  1875. CList<CBaseAz*,CBaseAz*> listTasks;
  1876. hr = m_refRoleAz.GetMembers(AZ_PROP_ROLE_TASKS,
  1877. listTasks);
  1878. BREAK_ON_FAIL_HRESULT(hr);
  1879. hr = MakeBaseAzListToActionItemList(listTasks,
  1880. m_listActionItem);
  1881. BREAK_ON_FAIL_HRESULT(hr);
  1882. //Add Member Operations
  1883. CList<CBaseAz*,CBaseAz*> listOperations;
  1884. hr = m_refRoleAz.GetMembers(AZ_PROP_ROLE_OPERATIONS,
  1885. listOperations);
  1886. BREAK_ON_FAIL_HRESULT(hr);
  1887. hr = MakeBaseAzListToActionItemList(listOperations,
  1888. m_listActionItem);
  1889. BREAK_ON_FAIL_HRESULT(hr);
  1890. //And Tasks and Operations to list control
  1891. AddActionItemFromListToListCtrl(m_listActionItem,
  1892. &m_listCtrl,
  1893. COL_NAME | COL_TYPE | COL_DESCRIPTION,
  1894. FALSE);
  1895. }while(0);
  1896. //Make controls readonly
  1897. if(IsReadOnly())
  1898. {
  1899. GetDlgItem(IDC_ADD)->EnableWindow(FALSE);
  1900. GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
  1901. }
  1902. return TRUE;
  1903. }
  1904. void
  1905. CRoleDefDialog::
  1906. OnOK()
  1907. {
  1908. TRACE_METHOD_EX(DEB_SNAPIN,CRoleDefDialog,OnOK)
  1909. POSITION pos = m_listActionItem.GetHeadPosition();
  1910. BOOL bErrorDisplayed = FALSE;
  1911. HRESULT hr = S_OK;
  1912. for( int i = 0; i < m_listActionItem.GetCount(); ++i)
  1913. {
  1914. ActionItem* pActionItem = m_listActionItem.GetNext(pos);
  1915. //We need to take action only for add or remove
  1916. if(pActionItem->action == ACTION_ADD ||
  1917. pActionItem->action == ACTION_REMOVE)
  1918. {
  1919. LONG lPropId = AZ_PROP_ROLE_TASKS;
  1920. if(pActionItem->m_pMemberAz->GetObjectType() == OPERATION_AZ)
  1921. lPropId = AZ_PROP_ROLE_OPERATIONS;
  1922. if(pActionItem->action == ACTION_ADD)
  1923. hr = m_refRoleAz.AddMember(lPropId,
  1924. pActionItem->m_pMemberAz);
  1925. else
  1926. hr = m_refRoleAz.RemoveMember(lPropId,
  1927. pActionItem->m_pMemberAz);
  1928. if(FAILED(hr))
  1929. {
  1930. CString strError;
  1931. GetSystemError(strError, hr);
  1932. ::DisplayError(m_hWnd,
  1933. (pActionItem->action == ACTION_ADD) ? IDS_ADD_FAILED : IDS_DELETE_FAILED,
  1934. (LPCTSTR)strError,
  1935. (LPCTSTR)(pActionItem->m_pMemberAz->GetName()));
  1936. bErrorDisplayed = TRUE;
  1937. break;
  1938. }
  1939. else
  1940. {
  1941. if(pActionItem->action == ACTION_ADD)
  1942. //Item has been added
  1943. pActionItem->action = ACTION_NONE;
  1944. else
  1945. //Item has been removed
  1946. pActionItem->action = ACTION_REMOVED;
  1947. }
  1948. }
  1949. }
  1950. if(SUCCEEDED(hr))
  1951. {
  1952. hr = m_refRoleAz.Submit();
  1953. }
  1954. if(FAILED(hr))
  1955. {
  1956. if(!bErrorDisplayed)
  1957. {
  1958. //Display Generic Error
  1959. CString strError;
  1960. GetSystemError(strError, hr);
  1961. ::DisplayError(m_hWnd,
  1962. IDS_GENERIC_PROPERTY_SAVE_ERROR,
  1963. (LPCTSTR)strError);
  1964. }
  1965. }
  1966. else
  1967. {
  1968. CHelpEnabledDialog::OnOK();
  1969. }
  1970. }
  1971. void
  1972. CRoleDefDialog::
  1973. OnButtonRemove()
  1974. {
  1975. //Remember the Position of first selected entry.
  1976. int iFirstSelectedItem = m_listCtrl.GetNextItem(-1, LVIS_SELECTED);
  1977. int iSelectedItem = -1;
  1978. while( (iSelectedItem = m_listCtrl.GetNextItem(iSelectedItem, LVIS_SELECTED)) != -1)
  1979. {
  1980. RemoveMember((ActionItem*)(m_listCtrl.GetItemData(iSelectedItem)));
  1981. m_listCtrl.DeleteItem(iSelectedItem);
  1982. iSelectedItem--;
  1983. }
  1984. if(m_listCtrl.GetItemCount() <= iFirstSelectedItem)
  1985. --iFirstSelectedItem;
  1986. SelectListCtrlItem(&m_listCtrl, iFirstSelectedItem);
  1987. }
  1988. void
  1989. CRoleDefDialog::
  1990. OnListCtrlItemChanged(NMHDR* /*pNotifyStruct*/, LRESULT* pResult)
  1991. {
  1992. if(!pResult)
  1993. return;
  1994. *pResult = 0;
  1995. if(!IsReadOnly())
  1996. {
  1997. EnableButtonIfSelectedInListCtrl(&m_listCtrl,
  1998. (CButton*)GetDlgItem(IDC_REMOVE));
  1999. }
  2000. }
  2001. void
  2002. CRoleDefDialog::
  2003. OnListCtrlItemDeleted(NMHDR* /*pNotifyStruct*/, LRESULT* /*pResult*/)
  2004. {
  2005. SetDirty();
  2006. }
  2007. void
  2008. CRoleDefDialog::
  2009. OnButtonAdd()
  2010. {
  2011. CContainerAz* pContainerAz = m_refRoleAz.GetParentAz();
  2012. ASSERT(pContainerAz);
  2013. CList<CBaseAz*,CBaseAz*> listObjectsSelected;
  2014. if(!GetSelectedDefinitions(TRUE,
  2015. pContainerAz,
  2016. listObjectsSelected))
  2017. {
  2018. return;
  2019. }
  2020. //Add selected members to appropriate property and to listctrl
  2021. AddActionItems(listObjectsSelected,
  2022. m_listCtrl,
  2023. m_hWnd,
  2024. m_listActionItem,
  2025. COL_NAME | COL_TYPE | COL_DESCRIPTION);
  2026. return;
  2027. }
  2028. //+----------------------------------------------------------------------------
  2029. // Function:BringPropSheetToForeGround
  2030. // Synopsis:Finds the property sheet for pNode and brings it to forground
  2031. // Returns: True if property sheet exists and is brought to foreground
  2032. // else FALSE
  2033. //-----------------------------------------------------------------------------
  2034. BOOL
  2035. BringPropSheetToForeGround(CRoleComponentDataObject *pComponentData,
  2036. CTreeNode * pNode)
  2037. {
  2038. TRACE_FUNCTION_EX(DEB_SNAPIN,BringPropSheetToForeGround)
  2039. if(!pNode || !pComponentData)
  2040. {
  2041. ASSERT(pNode);
  2042. ASSERT(pComponentData);
  2043. return FALSE;
  2044. }
  2045. HRESULT hr = S_OK;
  2046. // create a data object for this node
  2047. CComPtr<IDataObject> spDataObject;
  2048. hr = pComponentData->QueryDataObject((MMC_COOKIE)pNode, CCT_SCOPE, &spDataObject);
  2049. ASSERT(SUCCEEDED(hr));
  2050. // get an interface to a sheet provider
  2051. CComPtr<IPropertySheetProvider> spSheetProvider;
  2052. hr = pComponentData->GetConsole()->QueryInterface(IID_IPropertySheetProvider,(void**)&spSheetProvider);
  2053. ASSERT(SUCCEEDED(hr));
  2054. //HACK: FindPropertySheet requires IComponent only for comparing objects.
  2055. //Create a new IComponent and pass it to function and then relesae it
  2056. LPCOMPONENT pComponent = NULL;
  2057. hr = pComponentData->CreateComponent(&pComponent);
  2058. if(SUCCEEDED(hr) && pComponent)
  2059. {
  2060. hr = spSheetProvider->FindPropertySheet((MMC_COOKIE)pNode, pComponent, spDataObject);
  2061. //Release the IComponent
  2062. pComponent->Release();
  2063. if(hr == S_OK)
  2064. return TRUE;
  2065. }
  2066. return FALSE;
  2067. }
  2068. //+----------------------------------------------------------------------------
  2069. // Function:FindOrCreateModelessPropertySheet
  2070. // Synopsis:Displays property sheet for pCookieNode. If a propertysheet is
  2071. // already up, function brings it to foreground, otherwise it creates
  2072. // a new propertysheet. This should be used to create propertysheet
  2073. // in response to events other that click properties context menu.
  2074. // Arguments:
  2075. // Returns:
  2076. //-----------------------------------------------------------------------------
  2077. HRESULT
  2078. FindOrCreateModelessPropertySheet(CRoleComponentDataObject *pComponentData,
  2079. CTreeNode* pCookieNode)
  2080. {
  2081. TRACE_FUNCTION_EX(DEB_SNAPIN,FindOrCreateModelessPropertySheet)
  2082. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2083. if(!pComponentData || !pCookieNode)
  2084. {
  2085. ASSERT(pComponentData);
  2086. ASSERT(pCookieNode);
  2087. }
  2088. if(BringPropSheetToForeGround(pComponentData, pCookieNode))
  2089. {
  2090. //There is already a property sheet for this CookieNode.
  2091. //We no longer need this Node
  2092. delete pCookieNode;
  2093. return S_OK;
  2094. }
  2095. HRESULT hr = S_OK;
  2096. //bring up new property sheet for the pCookieNode
  2097. do
  2098. {
  2099. // get an interface to a sheet provider
  2100. CComPtr<IPropertySheetProvider> spSheetProvider;
  2101. hr = pComponentData->GetConsole()->QueryInterface(IID_IPropertySheetProvider,(void**)&spSheetProvider);
  2102. BREAK_ON_FAIL_HRESULT(hr);
  2103. // get an interface to a sheet callback
  2104. CComPtr<IPropertySheetCallback> spSheetCallback;
  2105. hr = pComponentData->GetConsole()->QueryInterface(IID_IPropertySheetCallback,(void**)&spSheetCallback);
  2106. BREAK_ON_FAIL_HRESULT(hr);
  2107. // create a data object for this node
  2108. CComPtr<IDataObject> spDataObject;
  2109. hr = pComponentData->QueryDataObject((MMC_COOKIE)pCookieNode, CCT_SCOPE, &spDataObject);
  2110. BREAK_ON_FAIL_HRESULT(hr);
  2111. // get a sheet
  2112. hr = spSheetProvider->CreatePropertySheet(_T("SHEET TITLE"), TRUE, (MMC_COOKIE)pCookieNode, spDataObject, 0x0 /*dwOptions*/);
  2113. BREAK_ON_FAIL_HRESULT(hr);
  2114. HWND hWnd = NULL;
  2115. hr = pComponentData->GetConsole()->GetMainWindow(&hWnd);
  2116. ASSERT(SUCCEEDED(hr));
  2117. IUnknown* pUnkComponentData = pComponentData->GetUnknown(); // no addref
  2118. hr = spSheetProvider->AddPrimaryPages(pUnkComponentData,
  2119. TRUE /*bCreateHandle*/,
  2120. hWnd,
  2121. TRUE /* bScopePane*/);
  2122. BREAK_ON_FAIL_HRESULT(hr);
  2123. hr = spSheetProvider->Show(reinterpret_cast<LONG_PTR>(hWnd), 0);
  2124. BREAK_ON_FAIL_HRESULT(hr);
  2125. }while(0);
  2126. return hr;
  2127. }