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.

572 lines
16 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: roledata.cpp
  7. //
  8. // Contents: Implementaion of Snapin's Root Node
  9. //
  10. // History: 07-26-2001 Hiteshr Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.h"
  14. //
  15. //CRoleRootData
  16. //
  17. // {356E1951-089F-4a2f-AD3E-775DB8B899E9}
  18. const GUID CRoleRootData::NodeTypeGUID =
  19. { 0x356e1951, 0x89f, 0x4a2f, { 0xad, 0x3e, 0x77, 0x5d, 0xb8, 0xb8, 0x99, 0xe9 } };
  20. const GUID CAdminManagerNode::NodeTypeGUID =
  21. // {579D6E87-2DDC-4a45-A12B-41FA73D4153C}
  22. { 0x579d6e87, 0x2ddc, 0x4a45, { 0xa1, 0x2b, 0x41, 0xfa, 0x73, 0xd4, 0x15, 0x3c } };
  23. const GUID CApplicationNode::NodeTypeGUID =
  24. // {F65C5386-6970-48b2-BF11-178C4B5DB18D}
  25. { 0xf65c5386, 0x6970, 0x48b2, { 0xbf, 0x11, 0x17, 0x8c, 0x4b, 0x5d, 0xb1, 0x8d } };
  26. const GUID CScopeNode::NodeTypeGUID =
  27. // {E114ECCB-03C9-45fa-97B1-AFACF1300AC3}
  28. { 0xe114eccb, 0x3c9, 0x45fa, { 0x97, 0xb1, 0xaf, 0xac, 0xf1, 0x30, 0xa, 0xc3 } };
  29. const GUID CGroupCollectionNode::NodeTypeGUID =
  30. // {6346FECB-D27F-446f-A388-FF32CE3649BB}
  31. { 0x6346fecb, 0xd27f, 0x446f, { 0xa3, 0x88, 0xff, 0x32, 0xce, 0x36, 0x49, 0xbb } };
  32. const GUID CRoleDefinitionCollectionNode::NodeTypeGUID =
  33. // {B3F21054-16DD-4528-98B9-64704F2DD72A}
  34. { 0xb3f21054, 0x16dd, 0x4528, { 0x98, 0xb9, 0x64, 0x70, 0x4f, 0x2d, 0xd7, 0x2a } };
  35. const GUID CTaskCollectionNode::NodeTypeGUID =
  36. // {D3BBCC7C-44A6-4914-ABC3-3A84D9D9293F}
  37. { 0xd3bbcc7c, 0x44a6, 0x4914, { 0xab, 0xc3, 0x3a, 0x84, 0xd9, 0xd9, 0x29, 0x3f } };
  38. const GUID CRoleCollectionNode::NodeTypeGUID =
  39. // {DB409E8C-94CC-4af7-A8EF-A3B850B14249}
  40. { 0xdb409e8c, 0x94cc, 0x4af7, { 0xa8, 0xef, 0xa3, 0xb8, 0x50, 0xb1, 0x42, 0x49 } };
  41. const GUID COperationCollectionNode::NodeTypeGUID =
  42. // {A5539402-429E-44d5-B99C-F0378AEE370B}
  43. { 0xa5539402, 0x429e, 0x44d5, { 0xb9, 0x9c, 0xf0, 0x37, 0x8a, 0xee, 0x37, 0xb } };
  44. const GUID CDefinitionCollectionNode::NodeTypeGUID =
  45. // {0E6E6CAC-5EB4-4d52-81D8-AC8CB4DF487C}
  46. { 0xe6e6cac, 0x5eb4, 0x4d52, { 0x81, 0xd8, 0xac, 0x8c, 0xb4, 0xdf, 0x48, 0x7c } };
  47. const GUID CRoleNode::NodeTypeGUID =
  48. // {94A20351-7977-4698-B8AC-D362504A7EEC}
  49. { 0x94a20351, 0x7977, 0x4698, { 0xb8, 0xac, 0xd3, 0x62, 0x50, 0x4a, 0x7e, 0xec } };
  50. const GUID CBaseLeafNode::NodeTypeGUID =
  51. // {475BFD50-96E4-407a-977E-E031747C3C50}
  52. { 0x475bfd50, 0x96e4, 0x407a, { 0x97, 0x7e, 0xe0, 0x31, 0x74, 0x7c, 0x3c, 0x50 } };
  53. DEBUG_DECLARE_INSTANCE_COUNTER(CRoleRootData);
  54. CRoleRootData::
  55. CRoleRootData(CComponentDataObject* pComponentData)
  56. :CRootData(pComponentData),
  57. m_bDeveloperMode(FALSE),
  58. m_dwADState(AD_STATE_UNKNOWN)
  59. {
  60. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN, CRoleRootData)
  61. DEBUG_INCREMENT_INSTANCE_COUNTER(CRoleRootData);
  62. m_bAdvancedView = FALSE;
  63. m_pColumnSet = NULL;
  64. }
  65. CRoleRootData::~CRoleRootData()
  66. {
  67. TRACE_DESTRUCTOR_EX(DEB_SNAPIN, CRoleRootData)
  68. DEBUG_DECREMENT_INSTANCE_COUNTER(CRoleRootData);
  69. }
  70. DWORD
  71. CRoleRootData::
  72. GetADState()
  73. {
  74. if( m_dwADState == AD_STATE_UNKNOWN)
  75. {
  76. if(m_ADInfo.GetRootDSE() == HRESULT_FROM_WIN32(ERROR_NO_SUCH_DOMAIN))
  77. m_dwADState = AD_NOT_AVAILABLE;
  78. else
  79. m_dwADState = AD_AVAILABLE;
  80. }
  81. return m_dwADState;
  82. }
  83. //+----------------------------------------------------------------------------
  84. // Function:OnOpenPolicyStore
  85. // Synopsis:Invokes the Dialog box for creating new policy store or
  86. // opening the existing store
  87. // Arguments:bNew If TRUE show Dialog box for new Policy Store else
  88. // show dialog box for opening exisitng policy store
  89. // Returns:
  90. //-----------------------------------------------------------------------------
  91. void
  92. CRoleRootData
  93. ::OnOpenPolicyStore(BOOL bNew)
  94. {
  95. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  96. if(bNew)
  97. {
  98. CNewAuthorizationStoreDlg dlgNewAuthzStore(GetComponentDataObject());
  99. dlgNewAuthzStore.DoModal();
  100. }
  101. else
  102. {
  103. COpenAuthorizationStoreDlg dlgOpenAuthzStore(GetComponentDataObject());
  104. dlgOpenAuthzStore.DoModal();
  105. }
  106. }
  107. void
  108. CRoleRootData::
  109. OnOptions()
  110. {
  111. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,OnOptions)
  112. BOOL bCurrentMode = m_bDeveloperMode;
  113. COptionDlg dlgOptions(m_bDeveloperMode);
  114. dlgOptions.DoModal();
  115. //Mode has been changed, refresh the screen
  116. if(bCurrentMode != m_bDeveloperMode)
  117. {
  118. //Call Refresh on Root which will refresh
  119. //all adminmanager objects under it.
  120. CNodeList tempNodeList;
  121. tempNodeList.AddTail(this);
  122. OnRefresh(GetComponentDataObject(), &tempNodeList);
  123. }
  124. }
  125. HRESULT
  126. CRoleRootData::OnCommand(long nCommandID,
  127. DATA_OBJECT_TYPES,
  128. CComponentDataObject* /*pComponentData*/,
  129. CNodeList* pNodeList)
  130. {
  131. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,OnCommand)
  132. //
  133. // Multiple selection not allowed
  134. //
  135. if (pNodeList->GetCount() > 1)
  136. {
  137. return E_FAIL;
  138. }
  139. switch (nCommandID)
  140. {
  141. case IDM_ROOT_OPEN_STORE:
  142. {
  143. OnOpenPolicyStore(FALSE);
  144. }
  145. break;
  146. case IDM_ROOT_NEW_STORE:
  147. {
  148. OnOpenPolicyStore(TRUE);
  149. }
  150. break;
  151. case IDM_ROOT_OPTIONS:
  152. {
  153. OnOptions();
  154. }
  155. break;
  156. default:
  157. ASSERT(FALSE);
  158. return E_FAIL;
  159. }
  160. // pComponentData->UpdateResultPaneView(this);
  161. return S_OK;
  162. }
  163. BOOL
  164. CRoleRootData::
  165. OnRefresh(CComponentDataObject* pComponentData,
  166. CNodeList* pNodeList)
  167. {
  168. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,OnRefresh)
  169. //This is the refresh for root node. There should never
  170. //be multiple selection
  171. if (pNodeList->GetCount() != 1) // single selection
  172. {
  173. return FALSE;
  174. }
  175. //Get all the container child of Root Object and refresh them.
  176. CNodeList * pChildNodeList = GetContainerChildList();
  177. if(!pChildNodeList || pChildNodeList->IsEmpty())
  178. {
  179. return FALSE;
  180. }
  181. BOOL bReturn = TRUE;
  182. POSITION pos = pChildNodeList->GetHeadPosition();
  183. while (pos != NULL)
  184. {
  185. CTreeNode* pChildNode = pNodeList->GetNext(pos);
  186. if(pChildNode)
  187. {
  188. //
  189. // Have each node refresh itself
  190. //
  191. CNodeList tempNodeList;
  192. tempNodeList.AddTail(pChildNode);
  193. if (!pChildNode->OnRefresh(pComponentData, &tempNodeList))
  194. {
  195. bReturn = FALSE;
  196. }
  197. }
  198. }
  199. return bReturn;
  200. }
  201. BOOL
  202. CRoleRootData::OnSetRefreshVerbState(DATA_OBJECT_TYPES /*type*/,
  203. BOOL* pbHide,
  204. CNodeList* /*pNodeList*/)
  205. {
  206. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,OnSetRefreshVerbState)
  207. *pbHide = FALSE;
  208. return TRUE;
  209. }
  210. BOOL
  211. CRoleRootData::OnEnumerate(CComponentDataObject* /*pComponentData*/, BOOL)
  212. {
  213. TRACE_METHOD_EX(DEB_SNAPIN, CRoleRootData, OnEnumerate)
  214. return TRUE; // there are already children, add them to the UI now
  215. }
  216. HRESULT
  217. CRoleRootData::IsDirty()
  218. {
  219. TRACE_METHOD_EX(DEB_SNAPIN, CRoleRootData, IsDirty)
  220. return CRootData::IsDirty();
  221. }
  222. #define AUTHORIZATION_MANAGER_STREAM_VERSION ((DWORD)0x07)
  223. const CString&
  224. CRoleRootData::
  225. GetXMLStorePath()
  226. {
  227. //default is current working directory
  228. if(m_strXMLStoreDirectory.IsEmpty())
  229. {
  230. GetCurrentWorkingDirectory(m_strXMLStoreDirectory);
  231. }
  232. return m_strXMLStoreDirectory;
  233. }
  234. void
  235. CRoleRootData::
  236. SetXMLStorePath(const CString& strXMLStorePath)
  237. {
  238. m_strXMLStoreDirectory = strXMLStorePath;
  239. }
  240. HRESULT
  241. CRoleRootData::Load(IStream* pStm)
  242. {
  243. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,Load)
  244. // assume never get multiple loads
  245. if(!m_containerChildList.IsEmpty() || !m_leafChildList.IsEmpty())
  246. return E_FAIL;
  247. //if Options are specified at commandline, we don't
  248. //read console file
  249. if(commandLineOptions.CommandLineOptionSpecified())
  250. {
  251. return OpenAdminManager(NULL,
  252. TRUE,
  253. commandLineOptions.GetStoreType(),
  254. commandLineOptions.GetStoreName(),
  255. GetXMLStorePath(),
  256. this,
  257. GetComponentDataObject());
  258. }
  259. HRESULT hr = S_OK;
  260. do
  261. {
  262. ULONG cbRead;
  263. // read the version ##
  264. DWORD dwVersion;
  265. hr = pStm->Read((void*)&dwVersion,sizeof(DWORD), &cbRead);
  266. BREAK_ON_FAIL_HRESULT(hr);
  267. ASSERT(cbRead == sizeof(DWORD));
  268. if (dwVersion != AUTHORIZATION_MANAGER_STREAM_VERSION)
  269. {
  270. Dbg(DEB_SNAPIN,"Invaild version number\n");
  271. hr = E_FAIL;
  272. break;
  273. }
  274. // read authorization manager mode
  275. hr = pStm->Read((void*)&m_bDeveloperMode,sizeof(BOOL), &cbRead);
  276. BREAK_ON_FAIL_HRESULT(hr);
  277. ASSERT(cbRead == sizeof(BOOL));
  278. //read xml store path
  279. //Read the Length of XML Store path
  280. INT nLenXMLStorePath;
  281. hr = pStm->Read((void*)&nLenXMLStorePath,sizeof(INT), &cbRead);
  282. BREAK_ON_FAIL_HRESULT(hr);
  283. ASSERT(cbRead == sizeof(INT));
  284. //Read XML Store path
  285. if(nLenXMLStorePath > 0)
  286. {
  287. LPWSTR pszBuffer = (LPWSTR)LocalAlloc(LPTR,nLenXMLStorePath*sizeof(WCHAR));
  288. if(!pszBuffer)
  289. return E_OUTOFMEMORY;
  290. hr = pStm->Read((void*)pszBuffer,sizeof(WCHAR)*nLenXMLStorePath, &cbRead);
  291. BREAK_ON_FAIL_HRESULT(hr);
  292. ASSERT(cbRead == sizeof(WCHAR)*nLenXMLStorePath);
  293. m_strXMLStoreDirectory = pszBuffer;
  294. LocalFree(pszBuffer);
  295. }
  296. UINT nCount;
  297. // load the list of Authorization Managers
  298. hr = pStm->Read((void*)&nCount,sizeof(UINT), &cbRead);
  299. BREAK_ON_FAIL_HRESULT(hr);
  300. ASSERT(cbRead == sizeof(UINT));
  301. CComponentDataObject* pComponentData = GetComponentDataObject();
  302. for (int k=0; k< (int)nCount; k++)
  303. {
  304. hr = CAdminManagerNode::CreateFromStream(pStm,this,pComponentData);
  305. BREAK_ON_FAIL_HRESULT(hr);
  306. }
  307. }while(0);
  308. return hr;
  309. }
  310. HRESULT
  311. CRoleRootData::Save(IStream* pStm, BOOL fClearDirty)
  312. {
  313. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData, Save)
  314. UINT nCount;
  315. ULONG cbWrite;
  316. HRESULT hr = S_OK;
  317. do
  318. {
  319. // write the version ##
  320. DWORD dwVersion = AUTHORIZATION_MANAGER_STREAM_VERSION;
  321. hr = pStm->Write((void*)&dwVersion, sizeof(DWORD),&cbWrite);
  322. BREAK_ON_FAIL_HRESULT(hr);
  323. ASSERT(cbWrite == sizeof(DWORD));
  324. // save authorization manager mode
  325. hr = pStm->Write((void*)&m_bDeveloperMode, sizeof(BOOL),&cbWrite);
  326. BREAK_ON_FAIL_HRESULT(hr);
  327. ASSERT(cbWrite == sizeof(BOOL));
  328. //
  329. //Save the xml store path
  330. //
  331. //Save the length of xml store path
  332. INT nLenXMLStorePath = m_strXMLStoreDirectory.GetLength();
  333. if(nLenXMLStorePath)
  334. nLenXMLStorePath++; //save null also
  335. hr = pStm->Write((void*)&nLenXMLStorePath, sizeof(INT),&cbWrite);
  336. BREAK_ON_FAIL_HRESULT(hr);
  337. ASSERT(cbWrite == sizeof(INT));
  338. if(nLenXMLStorePath)
  339. {
  340. //save the xml store path
  341. hr = pStm->Write((void*)(LPCTSTR)m_strXMLStoreDirectory, sizeof(WCHAR)*nLenXMLStorePath,&cbWrite);
  342. BREAK_ON_FAIL_HRESULT(hr);
  343. ASSERT(cbWrite == sizeof(WCHAR)*nLenXMLStorePath);
  344. }
  345. // write # of Authorization Manager Loaded
  346. nCount = (UINT)m_containerChildList.GetCount();
  347. hr = pStm->Write((void*)&nCount, sizeof(UINT),&cbWrite);
  348. BREAK_ON_FAIL_HRESULT(hr);
  349. ASSERT(cbWrite == sizeof(UINT));
  350. // loop through the list of servers and serialize them
  351. POSITION pos;
  352. for (pos = m_containerChildList.GetHeadPosition(); pos != NULL; )
  353. {
  354. CAdminManagerNode* pAdminManagerNode =
  355. (CAdminManagerNode*)m_containerChildList.GetNext(pos);
  356. hr = pAdminManagerNode->SaveToStream(pStm);
  357. BREAK_ON_FAIL_HRESULT(hr);
  358. }
  359. }while(0);
  360. if (fClearDirty)
  361. SetDirtyFlag(FALSE);
  362. return hr;
  363. }
  364. CColumnSet*
  365. CRoleRootData::GetColumnSet()
  366. {
  367. TRACE_METHOD_EX(DEB_SNAPIN, CRoleRootData, GetColumnSet);
  368. if (m_pColumnSet == NULL)
  369. {
  370. m_pColumnSet = ((CRoleComponentDataObject*)GetComponentDataObject())->GetColumnSet(L"---Default Column Set---");
  371. }
  372. return m_pColumnSet;
  373. }
  374. HRESULT
  375. CRoleRootData::GetResultViewType(CComponentDataObject*,
  376. LPOLESTR *ppViewType,
  377. long *pViewOptions)
  378. {
  379. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,GetResultViewType)
  380. if(!ppViewType || !pViewOptions)
  381. {
  382. ASSERT(FALSE);
  383. return E_POINTER;
  384. }
  385. HRESULT hr = S_FALSE;
  386. if (m_containerChildList.IsEmpty() && m_leafChildList.IsEmpty())
  387. {
  388. Dbg(DEB_SNAPIN,"Result View Type is MessageView\n");
  389. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  390. LPOLESTR psz = NULL;
  391. StringFromCLSID(CLSID_MessageView, &psz);
  392. USES_CONVERSION;
  393. if (psz != NULL)
  394. {
  395. *ppViewType = psz;
  396. hr = S_OK;
  397. }
  398. }
  399. else
  400. {
  401. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  402. *ppViewType = NULL;
  403. hr = S_FALSE;
  404. }
  405. return hr;
  406. }
  407. HRESULT
  408. CRoleRootData::OnShow(LPCONSOLE lpConsole)
  409. {
  410. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,OnShow)
  411. CComPtr<IUnknown> spUnknown;
  412. CComPtr<IMessageView> spMessageView;
  413. HRESULT hr = lpConsole->QueryResultView(&spUnknown);
  414. if (FAILED(hr))
  415. return S_OK;
  416. hr = spUnknown->QueryInterface(IID_IMessageView, (PVOID*)&spMessageView);
  417. if (SUCCEEDED(hr))
  418. {
  419. //
  420. // Load and set the title text of the message view
  421. //
  422. CString szTitle;
  423. VERIFY(szTitle.LoadString(IDS_MESSAGE_VIEW_NO_POLICY_STORE_TITLE));
  424. spMessageView->SetTitleText(szTitle);
  425. //
  426. // Load and set the body text of the message view
  427. //
  428. CString szMessage;
  429. VERIFY(szMessage.LoadString(IDS_MESSAGE_VIEW_NO_POLICY_STORE_MESSAGE));
  430. spMessageView->SetBodyText(szMessage);
  431. spMessageView->SetIcon(Icon_Error);
  432. }
  433. return S_OK;
  434. }
  435. BOOL
  436. CRoleRootData::CanCloseSheets()
  437. {
  438. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,CanCloseSheets)
  439. return TRUE;
  440. }
  441. LPCONTEXTMENUITEM2
  442. CRoleRootData::OnGetContextMenuItemTable()
  443. {
  444. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData, OnGetContextMenuItemTable)
  445. return CRootDataMenuHolder::GetContextMenuItem();
  446. }
  447. BOOL
  448. CRoleRootData::OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem2,
  449. long*)
  450. {
  451. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,OnAddMenuItem)
  452. if(pContextMenuItem2->lCommandID == IDM_ROOT_NEW_STORE)
  453. {
  454. if(IsDeveloperMode())
  455. return TRUE;
  456. else
  457. return FALSE;
  458. }
  459. return TRUE;
  460. }
  461. BOOL CRoleRootData::HasPropertyPages(DATA_OBJECT_TYPES,
  462. BOOL* pbHideVerb,
  463. CNodeList*)
  464. {
  465. TRACE_METHOD_EX(DEB_SNAPIN,CRoleRootData,HasPropertyPages)
  466. *pbHideVerb = TRUE;
  467. return FALSE;
  468. }