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.

598 lines
16 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name:
  5. LoggingMethodsNode.cpp
  6. Abstract:
  7. Implementation file for the CLoggingMethodsNode class.
  8. Author:
  9. Michael A. Maguire 12/15/97
  10. Revision History:
  11. mmaguire 12/15/97 - created
  12. --*/
  13. //////////////////////////////////////////////////////////////////////////////
  14. //////////////////////////////////////////////////////////////////////////////
  15. // BEGIN INCLUDES
  16. //
  17. // standard includes:
  18. //
  19. #include "Precompiled.h"
  20. //
  21. // where we can find declaration for main class in this file:
  22. //
  23. #include "LoggingMethodsNode.h"
  24. //
  25. //
  26. // where we can find declarations needed in this file:
  27. //
  28. #include "LocalFileLoggingNode.h"
  29. #include "LogCompD.h" // this must be included before NodeWithResultChildrenList.cpp
  30. #include "LogComp.h" // this must be included before NodeWithResultChildrenList.cpp
  31. #include "NodeWithResultChildrenList.cpp" // Implementation of template class.
  32. #include "LogMacNd.h"
  33. #include "dbnode.h"
  34. //
  35. // END INCLUDES
  36. //////////////////////////////////////////////////////////////////////////////
  37. #define COLUMN_WIDTH__LOGGING_METHOD 150
  38. #define COLUMN_WIDTH__DESCRIPTION 300
  39. //////////////////////////////////////////////////////////////////////////////
  40. /*++
  41. CLoggingMethodsNode::CLoggingMethodsNode
  42. Constructor
  43. --*/
  44. //////////////////////////////////////////////////////////////////////////////
  45. CLoggingMethodsNode::CLoggingMethodsNode(
  46. CSnapInItem* pParentNode,
  47. bool extendRasNode
  48. )
  49. : MyBaseClass(pParentNode, (extendRasNode ? RAS_HELP_INDEX : 0)),
  50. m_ExtendRas(extendRasNode)
  51. {
  52. ATLTRACE(_T("# +++ CLoggingMethodsNode::CLoggingMethodsNode\n"));
  53. // Check for preconditions:
  54. // None.
  55. // Set the display name for this object
  56. TCHAR lpszName[IAS_MAX_STRING];
  57. int nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOGGING_METHODS_NODE__NAME, lpszName, IAS_MAX_STRING );
  58. _ASSERT( nLoadStringResult > 0 );
  59. m_bstrDisplayName = lpszName;
  60. // In IComponentData::Initialize, we are asked to inform MMC of
  61. // the icons we would like to use for the scope pane.
  62. // Here we store an index to which of these images we
  63. // want to be used to display this node
  64. m_scopeDataItem.nImage = IDBI_NODE_LOGGING_METHODS_CLOSED;
  65. m_scopeDataItem.nOpenImage = IDBI_NODE_LOGGING_METHODS_OPEN;
  66. }
  67. //////////////////////////////////////////////////////////////////////////////
  68. /*++
  69. CLoggingMethodsNode::InitSdoPointers
  70. Call as soon as you have constructed this class and pass in it's SDO pointer.
  71. --*/
  72. //////////////////////////////////////////////////////////////////////////////
  73. HRESULT CLoggingMethodsNode::InitSdoPointers( ISdo *pSdo )
  74. {
  75. ATLTRACE(_T("# CLoggingMethodsNode::InitSdoPointers\n"));
  76. // Check for preconditions:
  77. _ASSERTE( pSdo != NULL );
  78. HRESULT hr = S_OK;
  79. // Release the old pointer if we had one.
  80. if( m_spSdo != NULL )
  81. {
  82. m_spSdo.Release();
  83. }
  84. // Save our client sdo pointer.
  85. m_spSdo = pSdo;
  86. return hr;
  87. }
  88. //////////////////////////////////////////////////////////////////////////////
  89. /*++
  90. CLoggingMethodsNode::~CLoggingMethodsNode
  91. Destructor
  92. --*/
  93. //////////////////////////////////////////////////////////////////////////////
  94. CLoggingMethodsNode::~CLoggingMethodsNode()
  95. {
  96. }
  97. //////////////////////////////////////////////////////////////////////////////
  98. /*++
  99. CLoggingMethodsNode::GetResultPaneColInfo
  100. See CSnapinNode::GetResultPaneColInfo (which this method overrides) for detailed info.
  101. --*/
  102. //////////////////////////////////////////////////////////////////////////////
  103. OLECHAR* CLoggingMethodsNode::GetResultPaneColInfo(int nCol)
  104. {
  105. ATLTRACE(_T("# CLoggingMethodsNode::GetResultPaneColInfo\n"));
  106. // Check for preconditions:
  107. // None.
  108. if (nCol == 0 && m_bstrDisplayName != NULL)
  109. return m_bstrDisplayName;
  110. return NULL;
  111. }
  112. //////////////////////////////////////////////////////////////////////////////
  113. /*++
  114. CLoggingMethodsNode::SetVerbs
  115. See CSnapinNode::SetVerbs (which this method overrides) for detailed info.
  116. --*/
  117. //////////////////////////////////////////////////////////////////////////////
  118. HRESULT CLoggingMethodsNode::SetVerbs( IConsoleVerb * pConsoleVerb )
  119. {
  120. ATLTRACE(_T("# CLoggingMethodsNode::SetVerbs\n"));
  121. // Check for preconditions:
  122. // None.
  123. HRESULT hr = S_OK;
  124. hr = pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  125. // CLoggingMethodsNode has no properties
  126. // hr = pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, FALSE );
  127. // We don't want the user deleting or renaming this node, so we
  128. // don't set the MMC_VERB_RENAME or MMC_VERB_DELETE verbs.
  129. // By default, when a node becomes selected, these are disabled.
  130. // We want double-clicking on a collection node to show its children.
  131. // hr = pConsoleVerb->SetVerbState( MMC_VERB_OPEN, ENABLED, TRUE );
  132. // hr = pConsoleVerb->SetDefaultVerb( MMC_VERB_OPEN );
  133. return hr;
  134. }
  135. //+---------------------------------------------------------------------------
  136. //
  137. // Function: DataRefresh -- to support
  138. //
  139. // Class: CPoliciesNode
  140. //
  141. // Synopsis: Initialize the CPoliciesNode using the SDO pointers
  142. //
  143. // Arguments: ISdo* pMachineSdo - Server SDO
  144. // ISdoDictionaryOld* pDictionarySdo - Sdo Dictionary
  145. // Returns: HRESULT - how the initialization goes
  146. //
  147. // History: Created byao 2/6/98 8:03:12 PM
  148. //
  149. //+---------------------------------------------------------------------------
  150. HRESULT CLoggingMethodsNode::DataRefresh( ISdo* pSdo )
  151. {
  152. // Save away the interface pointers.
  153. m_spSdo = pSdo;
  154. HRESULT retval = S_OK;
  155. for (int i = 0; i < m_ResultChildrenList.GetSize(); ++i)
  156. {
  157. HRESULT hr = m_ResultChildrenList[i]->InitSdoPointers(pSdo);
  158. if (FAILED(hr))
  159. {
  160. retval = hr;
  161. }
  162. }
  163. return retval;
  164. }
  165. //////////////////////////////////////////////////////////////////////////////
  166. /*++
  167. CPoliciesNode::OnRefresh
  168. See CSnapinNode::OnRefresh (which this method overrides) for detailed info.
  169. --*/
  170. //////////////////////////////////////////////////////////////////////////////
  171. HRESULT CLoggingMethodsNode::OnRefresh(
  172. LPARAM arg
  173. , LPARAM param
  174. , IComponentData * pComponentData
  175. , IComponent * pComponent
  176. , DATA_OBJECT_TYPES type
  177. )
  178. {
  179. HRESULT hr = S_OK;
  180. CWaitCursor WC;
  181. CComPtr<IConsole> spConsole;
  182. // We need IConsole
  183. if( pComponentData != NULL )
  184. {
  185. spConsole = ((CLoggingComponentData*)pComponentData)->m_spConsole;
  186. }
  187. else
  188. {
  189. spConsole = ((CLoggingComponent*)pComponent)->m_spConsole;
  190. }
  191. _ASSERTE( spConsole != NULL );
  192. for (int i = 0; i < m_ResultChildrenList.GetSize(); ++i)
  193. {
  194. hr = BringUpPropertySheetForNode(
  195. m_ResultChildrenList[i],
  196. pComponentData,
  197. pComponent,
  198. spConsole
  199. );
  200. if (hr == S_OK)
  201. {
  202. // We found a property sheet already up for this node.
  203. ShowErrorDialog(
  204. NULL,
  205. IDS_ERROR_CLOSE_PROPERTY_SHEET,
  206. NULL,
  207. hr,
  208. 0,
  209. spConsole
  210. );
  211. return hr;
  212. }
  213. }
  214. // reload SDO
  215. hr = ((CLoggingMachineNode *) m_pParentNode)->DataRefresh();
  216. for (int i = 0; i < m_ResultChildrenList.GetSize(); ++i)
  217. {
  218. // Load cached info from SDO
  219. m_ResultChildrenList[i]->OnPropertyChange(
  220. arg,
  221. param,
  222. pComponentData,
  223. pComponent,
  224. type
  225. );
  226. }
  227. // refresh the node
  228. hr = MyBaseClass::OnRefresh( arg, param, pComponentData, pComponent, type);
  229. return hr;
  230. }
  231. //////////////////////////////////////////////////////////////////////////////
  232. /*++
  233. CLoggingMethodsNode::InsertColumns
  234. See CNodeWithResultChildrenList::InsertColumns (which this method overrides)
  235. for detailed info.
  236. --*/
  237. //////////////////////////////////////////////////////////////////////////////
  238. HRESULT CLoggingMethodsNode::InsertColumns( IHeaderCtrl* pHeaderCtrl )
  239. {
  240. ATLTRACE(_T("# CLoggingMethodsNode::InsertColumns\n"));
  241. // Check for preconditions:
  242. _ASSERTE( pHeaderCtrl != NULL );
  243. HRESULT hr;
  244. int nLoadStringResult;
  245. TCHAR szLoggingMethod[IAS_MAX_STRING];
  246. TCHAR szDescription[IAS_MAX_STRING];
  247. nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOGGING_METHODS_NODE__LOGGING_METHOD, szLoggingMethod, IAS_MAX_STRING );
  248. _ASSERT( nLoadStringResult > 0 );
  249. nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOGGING_METHODS_NODE__DESCRIPTION, szDescription, IAS_MAX_STRING );
  250. _ASSERT( nLoadStringResult > 0 );
  251. hr = pHeaderCtrl->InsertColumn( 0, szLoggingMethod, LVCFMT_LEFT, COLUMN_WIDTH__LOGGING_METHOD );
  252. _ASSERT( S_OK == hr );
  253. hr = pHeaderCtrl->InsertColumn( 1, szDescription, LVCFMT_LEFT, COLUMN_WIDTH__DESCRIPTION );
  254. _ASSERT( S_OK == hr );
  255. return hr;
  256. }
  257. //////////////////////////////////////////////////////////////////////////////
  258. /*++
  259. CLoggingMethodsNode::PopulateResultChildrenList
  260. See CNodeWithResultChildrenList::PopulateResultChildrenList (which this method overrides)
  261. for detailed info.
  262. --*/
  263. //////////////////////////////////////////////////////////////////////////////
  264. HRESULT CLoggingMethodsNode::PopulateResultChildrenList( void )
  265. {
  266. HRESULT hr = S_OK;
  267. if (m_ResultChildrenList.GetSize() == 0)
  268. {
  269. CLocalFileLoggingNode* localFile = 0;
  270. DatabaseNode* database = 0;
  271. do
  272. {
  273. localFile = new (std::nothrow) CLocalFileLoggingNode(this);
  274. if (localFile == 0)
  275. {
  276. hr = E_OUTOFMEMORY;
  277. break;
  278. }
  279. hr = localFile->InitSdoPointers(m_spSdo);
  280. if (FAILED(hr)) { break; }
  281. hr = AddChildToList(localFile);
  282. if (FAILED(hr)) { break; }
  283. // Check if the database accounting component is present.
  284. CComPtr<ISdo> dbAcct;
  285. hr = SDOGetSdoFromCollection(
  286. m_spSdo,
  287. PROPERTY_IAS_REQUESTHANDLERS_COLLECTION,
  288. PROPERTY_COMPONENT_ID,
  289. IAS_PROVIDER_MICROSOFT_DB_ACCT,
  290. &dbAcct
  291. );
  292. if (SUCCEEDED(hr))
  293. {
  294. database = new (std::nothrow) DatabaseNode(this);
  295. if (database == 0)
  296. {
  297. hr = E_OUTOFMEMORY;
  298. break;
  299. }
  300. hr = database->InitSdoPointers(m_spSdo);
  301. if (FAILED(hr)) { break; }
  302. hr = AddChildToList(database);
  303. if (FAILED(hr)) { break; }
  304. }
  305. else
  306. {
  307. // Suppress the error since it just means were managing a downlevel
  308. // machine.
  309. hr = S_OK;
  310. }
  311. m_bResultChildrenListPopulated = TRUE;
  312. }
  313. while (false);
  314. if (!m_bResultChildrenListPopulated)
  315. {
  316. m_ResultChildrenList.RemoveAll();
  317. delete localFile;
  318. delete database;
  319. }
  320. }
  321. return hr;
  322. }
  323. //////////////////////////////////////////////////////////////////////////////
  324. /*++
  325. CLoggingMethodsNode::GetComponentData
  326. This method returns our unique CComponentData object representing the scope
  327. pane of this snapin.
  328. It relies upon the fact that each node has a pointer to its parent,
  329. except for the root node, which instead has a member variable pointing
  330. to CComponentData.
  331. This would be a useful function to use if, for example, you need a reference
  332. to some IConsole but you weren't passed one. You can use GetComponentData
  333. and then use the IConsole pointer which is a member variable of our
  334. CComponentData object.
  335. --*/
  336. //////////////////////////////////////////////////////////////////////////////
  337. CLoggingComponentData * CLoggingMethodsNode::GetComponentData( void )
  338. {
  339. ATLTRACE(_T("# CLoggingMethodsNode::GetComponentData\n"));
  340. // Check for preconditions:
  341. _ASSERTE( m_pParentNode );
  342. return ((CLoggingMachineNode *) m_pParentNode)->GetComponentData();
  343. }
  344. //////////////////////////////////////////////////////////////////////////////
  345. /*++
  346. CLoggingMethodsNode::GetServerRoot
  347. This method returns the Server node under which this node can be found.
  348. It relies upon the fact that each node has a pointer to its parent,
  349. all the way up to the server node.
  350. This would be a useful function to use if, for example, you need a reference
  351. to some data specific to a server.
  352. --*/
  353. //////////////////////////////////////////////////////////////////////////////
  354. CLoggingMachineNode * CLoggingMethodsNode::GetServerRoot( void )
  355. {
  356. ATLTRACE(_T("# CLoggingMethodsNode::GetServerRoot\n"));
  357. // Check for preconditions:
  358. _ASSERTE( m_pParentNode != NULL );
  359. return (CLoggingMachineNode *) m_pParentNode;
  360. }
  361. //////////////////////////////////////////////////////////////////////////////
  362. /*++
  363. CLoggingMethodsNode::OnPropertyChange
  364. This is our own custom response to the MMCN_PROPERTY_CHANGE notification.
  365. MMC never actually sends this notification to our snapin with a specific lpDataObject,
  366. so it would never normally get routed to a particular node but we have arranged it
  367. so that our property pages can pass the appropriate CSnapInItem pointer as the param
  368. argument. In our CComponent::Notify override, we map the notification message to
  369. the appropriate node using the param argument.
  370. --*/
  371. //////////////////////////////////////////////////////////////////////////////
  372. HRESULT CLoggingMethodsNode::OnPropertyChange(
  373. LPARAM arg
  374. , LPARAM param
  375. , IComponentData * pComponentData
  376. , IComponent * pComponent
  377. , DATA_OBJECT_TYPES type
  378. )
  379. {
  380. ATLTRACE(_T("# CLoggingMethodsNode::OnPropertyChange\n"));
  381. // Check for preconditions:
  382. // None.
  383. return LoadCachedInfoFromSdo();
  384. }
  385. //////////////////////////////////////////////////////////////////////////////
  386. /*++
  387. CLoggingMethodsNode::LoadCachedInfoFromSdo
  388. Causes this node and its children to re-read all their cached info from
  389. the SDO's. Call if you change something and you want to make sure that
  390. the display reflects this change.
  391. --*/
  392. //////////////////////////////////////////////////////////////////////////////
  393. HRESULT CLoggingMethodsNode::LoadCachedInfoFromSdo()
  394. {
  395. HRESULT retval = S_OK;
  396. for (int i = 0; i < m_ResultChildrenList.GetSize(); ++i)
  397. {
  398. HRESULT hr = m_ResultChildrenList[i]->LoadCachedInfoFromSdo();
  399. if (FAILED(hr))
  400. {
  401. retval = hr;
  402. }
  403. }
  404. return retval;
  405. }
  406. //////////////////////////////////////////////////////////////////////////////
  407. /*++
  408. CPoliciesNode::FillData
  409. The server node need to override CSnapInItem's implementation of this so that
  410. we can
  411. also support a clipformat for exchanging machine names with any snapins
  412. extending us.
  413. --*/
  414. //////////////////////////////////////////////////////////////////////////////
  415. STDMETHODIMP CLoggingMethodsNode::FillData(CLIPFORMAT cf, LPSTREAM pStream)
  416. {
  417. ATLTRACE(_T("# CClientsNode::FillData\n"));
  418. // Check for preconditions:
  419. // None.
  420. HRESULT hr = DV_E_CLIPFORMAT;
  421. ULONG uWritten = 0;
  422. if (cf == CF_MMC_NodeID)
  423. {
  424. ::CString SZNodeID = (LPCTSTR)GetSZNodeType();
  425. if (INTERNET_AUTHENTICATION_SERVICE_SNAPIN == GetServerRoot()->m_enumExtendedSnapin)
  426. SZNodeID += L":Ext_IAS:";
  427. SZNodeID += GetServerRoot()->m_bstrServerAddress;
  428. DWORD dwIdSize = 0;
  429. SNodeID2* NodeId = NULL;
  430. BYTE *id = NULL;
  431. DWORD textSize = (SZNodeID.GetLength()+ 1) * sizeof(TCHAR);
  432. dwIdSize = textSize + sizeof(SNodeID2);
  433. try{
  434. NodeId = (SNodeID2 *)_alloca(dwIdSize);
  435. }
  436. catch(...)
  437. {
  438. hr = E_OUTOFMEMORY;
  439. return hr;
  440. }
  441. NodeId->dwFlags = 0;
  442. NodeId->cBytes = textSize;
  443. memcpy(NodeId->id,(BYTE*)(LPCTSTR)SZNodeID, textSize);
  444. hr = pStream->Write(NodeId, dwIdSize, &uWritten);
  445. return hr;
  446. }
  447. // Call the method which we're overriding to let it handle the
  448. // rest of the possible cases as usual.
  449. return MyBaseClass::FillData( cf, pStream );
  450. }