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.

1134 lines
33 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1997 - 1999
  4. Module Name:
  5. LogMacNd.cpp
  6. Abstract:
  7. Implementation file for the CLoggingMachineNode class.
  8. Revision History:
  9. mmaguire 12/03/97
  10. byao 6/11/98 Added asynchrnous connect
  11. --*/
  12. //////////////////////////////////////////////////////////////////////////////
  13. //////////////////////////////////////////////////////////////////////////////
  14. // BEGIN INCLUDES
  15. //
  16. // standard includes:
  17. //
  18. #include "Precompiled.h"
  19. //
  20. // where we can find declaration for main class in this file:
  21. //
  22. #include "LogMacNd.h"
  23. #include "LogComp.h"
  24. #include "SnapinNode.cpp" // Template implementation
  25. //
  26. // where we can find declarations needed in this file:
  27. //
  28. #include "NapUtil.h"
  29. #include "MachineEnumTask.h"
  30. #include "NodeTypeGUIDS.h"
  31. //
  32. // END INCLUDES
  33. //////////////////////////////////////////////////////////////////////////////
  34. //////////////////////////////////////////////////////////////////////////////
  35. /*++
  36. CLoggingMachineNode::IsSupportedGUID
  37. Used to determine whether we extend the node type of a given GUID, and sets
  38. the m_enumExtendedSnapin variable to indicate what snapin we are extending.
  39. --*/
  40. //////////////////////////////////////////////////////////////////////////////
  41. BOOL CLoggingMachineNode::IsSupportedGUID( GUID & guid )
  42. {
  43. if( IsEqualGUID( guid, InternetAuthenticationServiceGUID_ROOTNODETYPE ) )
  44. {
  45. m_enumExtendedSnapin = INTERNET_AUTHENTICATION_SERVICE_SNAPIN;
  46. return TRUE;
  47. }
  48. else
  49. {
  50. if( IsEqualGUID( guid, NetworkConsoleGUID_ROOTNODETYPE) )
  51. {
  52. m_enumExtendedSnapin = NETWORK_MANAGEMENT_SNAPIN;
  53. return TRUE;
  54. }
  55. else
  56. {
  57. if( IsEqualGUID( guid, RoutingAndRemoteAccessGUID_MACHINENODETYPE ) )
  58. {
  59. m_enumExtendedSnapin = RRAS_SNAPIN;
  60. return TRUE;
  61. }
  62. }
  63. }
  64. return FALSE;
  65. }
  66. //////////////////////////////////////////////////////////////////////////////
  67. /*++
  68. CLoggingMachineNode::GetExtNodeObject
  69. Depending on which snapin we are extending, when queried for a node object
  70. corresponding to a particular machine, we must decide which node we want
  71. to give a pointer to.
  72. When we extend a snapin like IAS or Network Management, where there is one
  73. instance of a snapin per machine being configured, we simply return a pointer
  74. to "this" -- this CLoggingMachineNode object is the single one being administed.
  75. When we extend a snapin like RRAS where there is an "Enterprise" view and
  76. one snapin may need to manage a view of multiple machines, this CLoggingMachineNode
  77. will act as a redirector to a CLoggingMachineNode in a list of m_mapMachineNodes it
  78. maintains which corresponds to the appropriate machines.
  79. --*/
  80. //////////////////////////////////////////////////////////////////////////////
  81. CSnapInItem * CLoggingMachineNode::GetExtNodeObject(LPDATAOBJECT pDataObject, CLoggingMachineNode * pDataClass )
  82. {
  83. TRACE_FUNCTION("CLoggingMachineNode::GetExtNodeObject");
  84. if( m_enumExtendedSnapin == INTERNET_AUTHENTICATION_SERVICE_SNAPIN
  85. || m_enumExtendedSnapin == NETWORK_MANAGEMENT_SNAPIN )
  86. {
  87. // There is one instance of a machine node per snapin.
  88. // This machine node is a "virtual root" that shadows the node being extended.
  89. m_fNodeHasUI = TRUE;
  90. return this;
  91. }
  92. else
  93. {
  94. try
  95. {
  96. _ASSERTE( m_enumExtendedSnapin == RRAS_SNAPIN );
  97. // There are many machine nodes and one extension snapin needs to handle them all.
  98. // We use this function to extract the machine name from the clipboard format.
  99. // It will set the corrent value in m_bstrServerAddress.
  100. m_fAlreadyAnalyzedDataClass = FALSE;
  101. InitDataClass( pDataObject, pDataClass );
  102. // See if we already have a CLoggingMachineNode object corresponding to the
  103. // machine named in m_bstrServerAddress and insert it if we do not.
  104. LOGGINGSERVERSMAP::iterator theIterator;
  105. std::basic_string< wchar_t > MyString = m_bstrServerAddress;
  106. BOOL bAddedAsLocal = ExtractComputerAddedAsLocal(pDataObject);
  107. // local machine has special entry
  108. if(bAddedAsLocal)
  109. MyString = _T("");
  110. CLoggingMachineNode * pMachineNode = NULL;
  111. theIterator = m_mapMachineNodes.find(MyString);
  112. if( theIterator == m_mapMachineNodes.end() )
  113. {
  114. // We need to insert a new CLoggingMachineNode object for m_bstrServerAddress.
  115. pMachineNode = new CLoggingMachineNode();
  116. pMachineNode->m_pComponentData = m_pComponentData;
  117. pMachineNode->m_enumExtendedSnapin = m_enumExtendedSnapin;
  118. // RRAS refresh advise setup F bug 213623:
  119. m_spRtrAdviseSink.p = CRtrAdviseSinkForIAS<CLoggingMachineNode>::SetAdvise(pMachineNode, pDataObject);
  120. // ~RRAS
  121. m_mapMachineNodes.insert( LOGGINGSERVERSMAP::value_type( MyString, pMachineNode ) );
  122. // ISSUE: We should be able to use the pair returned from insert above,
  123. // but for now, just use find again.
  124. theIterator = m_mapMachineNodes.find(MyString);
  125. }
  126. else
  127. {
  128. pMachineNode = (CLoggingMachineNode*)theIterator->second;
  129. }
  130. // RRAS refresh advise setup F bug 213623:
  131. if(!pMachineNode->m_spRtrAdviseSink)
  132. pMachineNode->m_spRtrAdviseSink.p = CRtrAdviseSinkForIAS<CLoggingMachineNode>::SetAdvise(pMachineNode, pDataObject);
  133. // ~RRAS
  134. pMachineNode->m_fNodeHasUI = TRUE;
  135. // We already have a CLoggingMachineNode for this object.
  136. return theIterator->second;
  137. }
  138. catch(...)
  139. {
  140. // Error.
  141. return NULL;
  142. }
  143. }
  144. }
  145. //////////////////////////////////////////////////////////////////////////////
  146. /*++
  147. CLoggingMachineNode::OnRRASChange
  148. // OnRRASChange -- to decide if to show LOGGING node under the machine node
  149. // Only show LOGGING node if NT Accounting is selected
  150. --*/
  151. HRESULT CLoggingMachineNode::OnRRASChange(
  152. /* [in] */ LONG_PTR ulConnection,
  153. /* [in] */ DWORD dwChangeType,
  154. /* [in] */ DWORD dwObjectType,
  155. /* [in] */ LPARAM lUserParam,
  156. /* [in] */ LPARAM lParam)
  157. {
  158. HRESULT hr = S_OK;
  159. hr = TryShow(NULL);
  160. return S_OK;
  161. }
  162. HRESULT CLoggingMachineNode::OnRemoveChildren(
  163. LPARAM arg
  164. , LPARAM param
  165. , IComponentData * pComponentData
  166. , IComponent * pComponent
  167. , DATA_OBJECT_TYPES type
  168. )
  169. {
  170. // logging node will be removed, so we should set the ID to 0
  171. if(m_pLoggingNode)
  172. m_pLoggingNode->m_scopeDataItem.ID = 0;
  173. // disconnect RRAS on change notify
  174. // RRAS refresh
  175. if(m_spRtrAdviseSink != NULL)
  176. {
  177. m_spRtrAdviseSink->ReleaseSink();
  178. m_spRtrAdviseSink.Release();
  179. }
  180. m_fNodeHasUI = FALSE;
  181. return S_OK;
  182. }
  183. //========================
  184. //========================
  185. HRESULT CLoggingMachineNode::TryShow(BOOL* pbVisible )
  186. {
  187. HRESULT hr = S_OK;
  188. CComPtr<IConsole> spConsole;
  189. CComPtr<IConsoleNameSpace> spConsoleNameSpace;
  190. BOOL bShow = FALSE;
  191. if(!m_bServerSupported || !m_fAlreadyAnalyzedDataClass || !m_pLoggingNode || !m_fNodeHasUI)
  192. return hr;
  193. // when RRAS_SNAPIN extension
  194. if(m_enumExtendedSnapin == RRAS_SNAPIN)
  195. {
  196. BSTR bstrMachine = NULL;
  197. if(!m_bConfigureLocal)
  198. bstrMachine = m_bstrServerAddress;
  199. bShow = ( IsRRASConfigured(bstrMachine)&& (IsRRASUsingNTAccounting(bstrMachine) || IsRRASUsingNTAuthentication(bstrMachine)) );
  200. }
  201. // IAS, show only IAS service is installed on the machine
  202. else if (INTERNET_AUTHENTICATION_SERVICE_SNAPIN == m_enumExtendedSnapin)
  203. {
  204. hr = IfServiceInstalled(m_bstrServerAddress, _T("IAS"), &bShow);
  205. if(hr != S_OK) return hr;
  206. }
  207. else // always show
  208. {
  209. bShow = TRUE;
  210. }
  211. // deal with the node
  212. hr = m_pComponentData->m_spConsole->QueryInterface(
  213. IID_IConsoleNameSpace,
  214. (VOID**)(&spConsoleNameSpace) );
  215. if(S_OK != hr)
  216. goto Error;
  217. if ( bShow && m_pLoggingNode->m_scopeDataItem.ID == NULL) // show the node
  218. {
  219. hr = spConsoleNameSpace->InsertItem( &(m_pLoggingNode->m_scopeDataItem) );
  220. // _ASSERT( NULL != m_pLoggingNode->m_scopeDataItem.ID );
  221. }
  222. else if (!bShow && m_pLoggingNode->m_scopeDataItem.ID != NULL) // hide
  223. { // hide the node
  224. hr = spConsoleNameSpace->DeleteItem( m_pLoggingNode->m_scopeDataItem.ID, TRUE );
  225. m_pLoggingNode->m_scopeDataItem.ID = NULL;
  226. }
  227. if(hr == S_OK && pbVisible)
  228. *pbVisible = bShow;
  229. Error:
  230. return hr;
  231. }
  232. //////////////////////////////////////////////////////////////////////////////
  233. /*++
  234. CLoggingMachineNode::CLoggingMachineNode
  235. Constructor
  236. --*/
  237. //////////////////////////////////////////////////////////////////////////////
  238. CLoggingMachineNode::CLoggingMachineNode(): CSnapinNode<CLoggingMachineNode, CLoggingComponentData, CLoggingComponent>( NULL )
  239. {
  240. TRACE_FUNCTION("CLoggingMachineNode::CLoggingMachineNode");
  241. // The children subnodes have not yet been created.
  242. m_pLoggingNode = NULL;
  243. // Set the display name for this object
  244. m_bstrDisplayName = L"@Some Machine";
  245. // In IComponentData::Initialize, we are asked to inform MMC of
  246. // the icons we would like to use for the scope pane.
  247. // Here we store an index to which of these images we
  248. // want to be used to display this node
  249. m_scopeDataItem.nImage = IDBI_NODE_MACHINE_CLOSED;
  250. m_scopeDataItem.nOpenImage = IDBI_NODE_MACHINE_OPEN;
  251. //
  252. // initialize all the SDO pointers
  253. //
  254. m_spDictionarySdo = NULL;
  255. m_fAlreadyAnalyzedDataClass = FALSE;
  256. // connected?
  257. m_fSdoConnected = FALSE;
  258. // helper class that connect to server asynchrnously
  259. m_pConnectionToServer = NULL;
  260. // default to not configuring the local machine
  261. m_bConfigureLocal = FALSE;
  262. m_fNodeHasUI = FALSE;
  263. // if the server being focused is supported by this node
  264. m_bServerSupported = TRUE;
  265. m_enumExtendedSnapin = INTERNET_AUTHENTICATION_SERVICE_SNAPIN;
  266. }
  267. //////////////////////////////////////////////////////////////////////////////
  268. /*++
  269. CLoggingMachineNode::~CLoggingMachineNode
  270. Destructor
  271. --*/
  272. //////////////////////////////////////////////////////////////////////////////
  273. CLoggingMachineNode::~CLoggingMachineNode()
  274. {
  275. TRACE_FUNCTION("CLoggingMachineNode::~CLoggingMachineNode");
  276. if( NULL != m_pConnectionToServer )
  277. {
  278. m_pConnectionToServer->Release(TRUE);
  279. }
  280. // Delete children nodes
  281. delete m_pLoggingNode;
  282. // Delete the list of machines in case we are extending a snapin with
  283. // enterprise view like RRAS.
  284. LOGGINGSERVERSMAP::iterator theIterator;
  285. for( theIterator = m_mapMachineNodes.begin(); theIterator != m_mapMachineNodes.end(); ++theIterator )
  286. {
  287. delete theIterator->second;
  288. }
  289. m_mapMachineNodes.clear();
  290. }
  291. //////////////////////////////////////////////////////////////////////////////
  292. /*++
  293. CLoggingMachineNode::GetResultPaneColInfo
  294. See CSnapinNode::GetResultPaneColInfo (which this method overrides) for detailed info.
  295. --*/
  296. //////////////////////////////////////////////////////////////////////////////
  297. LPOLESTR CLoggingMachineNode::GetResultPaneColInfo(int nCol)
  298. {
  299. TRACE_FUNCTION("CLoggingMachineNode::GetResultPaneColInfo");
  300. if (nCol == 0)
  301. {
  302. return m_bstrDisplayName;
  303. }
  304. // TODO : Return the text for other columns
  305. return OLESTR("Running");
  306. }
  307. //////////////////////////////////////////////////////////////////////////////
  308. /*++
  309. CLoggingMachineNode::OnExpand
  310. See CSnapinNode::OnExpand (which this method overrides) for detailed info.
  311. --*/
  312. //////////////////////////////////////////////////////////////////////////////
  313. HRESULT CLoggingMachineNode::OnExpand(
  314. LPARAM arg
  315. , LPARAM param
  316. , IComponentData * pComponentData
  317. , IComponent * pComponent
  318. , DATA_OBJECT_TYPES type
  319. )
  320. {
  321. TRACE_FUNCTION("CLoggingMachineNode::OnExpand");
  322. IConsoleNameSpace * pConsoleNameSpace;
  323. HRESULT hr = S_FALSE;
  324. if( TRUE == arg )
  325. {
  326. // we are expanding the root node -- which is the machine node here.
  327. // Try to create the children of this Machine node
  328. if( NULL == m_pLoggingNode )
  329. {
  330. m_pLoggingNode = new CLoggingMethodsNode(
  331. this,
  332. m_enumExtendedSnapin == RRAS_SNAPIN
  333. );
  334. }
  335. if( NULL == m_pLoggingNode )
  336. {
  337. hr = E_OUTOFMEMORY;
  338. // Use MessageBox() rather than IConsole::MessageBox() here because the
  339. // first time this gets called m_ipConsole is not fully initialized
  340. // ISSUE: The above statement is probably not true for this node.
  341. ::MessageBox( NULL, L"@Unable to allocate new nodes", L"CLoggingMachineNode::OnExpand", MB_OK );
  342. return(hr);
  343. }
  344. //
  345. // we need to get all the SDO pointers, this include the SdoServer,
  346. // Dictionary, Profile collection, policy collection and condition collection
  347. //
  348. //todo: report error when not connected?
  349. hr = BeginConnectAction();
  350. if ( FAILED(hr) )
  351. {
  352. return hr;
  353. }
  354. // But to get that, first we need IConsole
  355. CComPtr<IConsole> spConsole;
  356. if( pComponentData != NULL )
  357. {
  358. spConsole = ((CLoggingComponentData*)pComponentData)->m_spConsole;
  359. }
  360. else
  361. {
  362. // We should have a non-null pComponent
  363. spConsole = ((CLoggingComponent*)pComponent)->m_spConsole;
  364. }
  365. _ASSERTE( spConsole != NULL );
  366. hr = spConsole->QueryInterface(IID_IConsoleNameSpace, (VOID**)(&pConsoleNameSpace) );
  367. _ASSERT( S_OK == hr );
  368. // This was done in MeanGene's Step 3 -- I'm guessing MMC wants this filled in
  369. m_pLoggingNode->m_scopeDataItem.relativeID = (HSCOPEITEM) param;
  370. #ifndef ALWAYS_SHOW_RAP_NODE
  371. hr = TryShow(NULL);
  372. #else
  373. hr = pConsoleNameSpace->InsertItem( &(m_pLoggingNode->m_scopeDataItem) );
  374. _ASSERT( NULL != m_pLoggingNode->m_scopeDataItem.ID );
  375. #endif
  376. pConsoleNameSpace->Release(); // Don't forget to do this!
  377. }
  378. else // arg != TRUE so not expanding
  379. {
  380. // do nothing for now -- I don't think arg = FALSE is even implemented
  381. // for MMC v. 1.0 or 1.1
  382. }
  383. return hr;
  384. }
  385. //////////////////////////////////////////////////////////////////////////////
  386. /*++
  387. CLoggingMachineNode::OnRename
  388. See CSnapinNode::OnRename (which this method overrides) for detailed info.
  389. --*/
  390. //////////////////////////////////////////////////////////////////////////////
  391. HRESULT CLoggingMachineNode::OnRename(
  392. LPARAM arg
  393. , LPARAM param
  394. , IComponentData * pComponentData
  395. , IComponent * pComponent
  396. , DATA_OBJECT_TYPES type
  397. )
  398. {
  399. TRACE_FUNCTION("MachineNode::OnRename");
  400. HRESULT hr = S_FALSE;
  401. //ISSUE: Consider moving this into base CNAPNode class or a CLeafNode class
  402. OLECHAR * pTemp = new OLECHAR[lstrlen((OLECHAR*) param) + 1];
  403. if ( NULL == pTemp )
  404. {
  405. return S_FALSE;
  406. }
  407. lstrcpy( pTemp, (OLECHAR*) param );
  408. m_bstrDisplayName = pTemp;
  409. return S_OK;
  410. }
  411. //////////////////////////////////////////////////////////////////////////////
  412. /*++
  413. CLoggingMachineNode::SetVerbs
  414. See CSnapinNode::SetVerbs (which this method overrides) for detailed info.
  415. --*/
  416. //////////////////////////////////////////////////////////////////////////////
  417. HRESULT CLoggingMachineNode::SetVerbs( IConsoleVerb * pConsoleVerb )
  418. {
  419. TRACE_FUNCTION("CLoggingMachineNode::SetVerbs");
  420. HRESULT hr = S_OK;
  421. // We want the user to be able to choose Properties on this node
  422. hr = pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  423. // We want the default verb to be Properties
  424. hr = pConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  425. // We want the user to be able to delete this node
  426. hr = pConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  427. // We want the user to be able to rename this node
  428. hr = pConsoleVerb->SetVerbState( MMC_VERB_RENAME, ENABLED, TRUE );
  429. return hr;
  430. }
  431. //////////////////////////////////////////////////////////////////////////////
  432. /*++
  433. CLoggingMachineNode::GetComponentData
  434. This method returns our unique CComponentData object representing the scope
  435. pane of this snapin.
  436. It relies upon the fact that each node has a pointer to its parent,
  437. except for the root node, which instead has a member variable pointing
  438. to CComponentData.
  439. This would be a useful function to use if, for example, you need a reference
  440. to some IConsole but you weren't passed one. You can use GetComponentData
  441. and then use the IConsole pointer which is a member variable of our
  442. CComponentData object.
  443. --*/
  444. //////////////////////////////////////////////////////////////////////////////
  445. CLoggingComponentData * CLoggingMachineNode::GetComponentData( void )
  446. {
  447. TRACE_FUNCTION("CLoggingMachineNode::GetComponentData");
  448. return m_pComponentData;
  449. }
  450. //+---------------------------------------------------------------------------
  451. //
  452. // Function: CLoggingMachineNode::InitClipboardFormat
  453. //
  454. // Synopsis: initialize the clipboard format that's used to pass computer name
  455. // from the primary snap-in and extension snap-in
  456. //
  457. // Arguments: None
  458. //
  459. // Returns: Nothing
  460. //
  461. // History: Created Header byao 2/25/98 7:04:33 PM
  462. //
  463. //+---------------------------------------------------------------------------
  464. void CLoggingMachineNode::InitClipboardFormat()
  465. {
  466. TRACE_FUNCTION("CLoggingMachineNode::InitClipboardFormat");
  467. // Init a clipboard format which will allow us to exchange
  468. // machine name information.
  469. m_CCF_MMC_SNAPIN_MACHINE_NAME = (CLIPFORMAT) RegisterClipboardFormat(_T("MMC_SNAPIN_MACHINE_NAME"));
  470. }
  471. //+---------------------------------------------------------------------------
  472. //
  473. // Function: CLoggingMachineNode::InitDataClass
  474. //
  475. // Synopsis: gets passed the IDataObject sent to the extension snapin for this
  476. // node, queries this IDataObject for the name of the machine
  477. // which this snapin is extending
  478. //
  479. // Arguments: None
  480. //
  481. // Returns: Nothing
  482. //
  483. // History: Created Header mmaguire 2/25/98 9:07 PM
  484. //
  485. //+---------------------------------------------------------------------------
  486. void CLoggingMachineNode::InitDataClass(IDataObject* pDataObject, CSnapInItem* pDefault)
  487. {
  488. TRACE_FUNCTION("CLoggingMachineNode::InitDataClass");
  489. // Check for preconditions.
  490. if( m_fAlreadyAnalyzedDataClass )
  491. {
  492. // We have already performed any work we needed to do with the dataobject here.
  493. return;
  494. }
  495. if (pDataObject == NULL)
  496. {
  497. return;
  498. }
  499. HRESULT hr;
  500. // OLECHAR szMachineName[IAS_MAX_COMPUTERNAME_LENGTH];
  501. // Try a large size because RRAS seems to want 2048
  502. OLECHAR szMachineName[4000];
  503. // Fill the structures which will tell the IDataObject what information
  504. // we want it to give us.
  505. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  506. FORMATETC formatetc = { m_CCF_MMC_SNAPIN_MACHINE_NAME,
  507. NULL,
  508. DVASPECT_CONTENT,
  509. -1,
  510. TYMED_HGLOBAL
  511. };
  512. // Allocate enough global memory for the IDataObject to write
  513. // the max computer name length.
  514. stgmedium.hGlobal = GlobalAlloc(0, sizeof(OLECHAR)*(IAS_MAX_COMPUTERNAME_LENGTH) );
  515. if (stgmedium.hGlobal == NULL)
  516. {
  517. return;
  518. }
  519. // Ask the IDataObject for the computer name.
  520. hr = pDataObject->GetDataHere(&formatetc, &stgmedium);
  521. if (SUCCEEDED(hr))
  522. {
  523. // Parse the data given back to us.
  524. // Create a stream on HGLOBAL
  525. CComPtr<IStream> spStream;
  526. hr = CreateStreamOnHGlobal(stgmedium.hGlobal, FALSE, &spStream);
  527. if (SUCCEEDED(hr))
  528. {
  529. // Read from the stream.
  530. unsigned long uWritten;
  531. hr = spStream->Read(szMachineName, sizeof(OLECHAR)*(IAS_MAX_COMPUTERNAME_LENGTH), &uWritten);
  532. if( SUCCEEDED(hr) )
  533. {
  534. m_bstrServerAddress = szMachineName;
  535. // check to see if we are configuring the local machine
  536. CString strLocalMachine;
  537. DWORD dwSize = MAX_COMPUTERNAME_LENGTH;
  538. ::GetComputerName(strLocalMachine.GetBuffer(dwSize), &dwSize);
  539. strLocalMachine.ReleaseBuffer();
  540. // If the machine name we read was either an empty string,
  541. // or it equals the name of the current computer,
  542. // then we are configuring the local machine.
  543. if ( ! szMachineName[0] || strLocalMachine.CompareNoCase(szMachineName) == 0)
  544. {
  545. m_bConfigureLocal = TRUE;
  546. }
  547. }
  548. else
  549. {
  550. ShowErrorDialog( NULL, USE_DEFAULT, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  551. }
  552. }
  553. }
  554. GlobalFree(stgmedium.hGlobal);
  555. if( SUCCEEDED( hr ) )
  556. {
  557. // If we made it to here with an successful HRESULT, we have successfully analyzed
  558. // the IDataObject and we set this flag so that we don't do this work again.
  559. m_fAlreadyAnalyzedDataClass = TRUE;
  560. }
  561. }
  562. //////////////////////////////////////////////////////////////////////////////
  563. /*++
  564. CLoggingMachineNode::TaskNotify
  565. See CSnapinNode::TaskNotify (which this method overrides) for detailed info.
  566. --*/
  567. //////////////////////////////////////////////////////////////////////////////
  568. STDMETHODIMP CLoggingMachineNode::TaskNotify(
  569. IDataObject * pDataObject
  570. , VARIANT * pvarg
  571. , VARIANT * pvparam
  572. )
  573. {
  574. TRACE_FUNCTION("CLoggingMachineNode::TaskNotify");
  575. // Check for preconditions:
  576. // None.
  577. if ( !m_fSdoConnected )
  578. {
  579. return S_OK;
  580. }
  581. HRESULT hr = S_FALSE;
  582. if (pvarg->vt == VT_I4)
  583. {
  584. switch (pvarg->lVal)
  585. {
  586. case MACHINE_TASK__DEFINE_NETWORK_ACCESS_POLICY:
  587. hr = OnTaskPadDefineNetworkAccessPolicy( pDataObject, pvarg, pvparam );
  588. break;
  589. default:
  590. break;
  591. }
  592. }
  593. // ISSUE: What should I be returning here?
  594. return hr;
  595. }
  596. //////////////////////////////////////////////////////////////////////////////
  597. /*++
  598. CLoggingMachineNode::EnumTasks
  599. See CSnapinNode::EnumTasks (which this method overrides) for detailed info.
  600. --*/
  601. //////////////////////////////////////////////////////////////////////////////
  602. STDMETHODIMP CLoggingMachineNode::EnumTasks(
  603. IDataObject * pDataObject
  604. , BSTR szTaskGroup
  605. , IEnumTASK** ppEnumTASK
  606. )
  607. {
  608. TRACE_FUNCTION("CLoggingMachineNode::EnumTasks");
  609. // Check for preconditions:
  610. // None.
  611. if ( !m_fSdoConnected )
  612. {
  613. return S_OK;
  614. }
  615. HRESULT hr = S_OK;
  616. CMachineEnumTask * pMachineEnumTask = new CMachineEnumTask( (CMachineNode *) this );
  617. if ( pMachineEnumTask == NULL )
  618. {
  619. hr = E_OUTOFMEMORY;
  620. }
  621. else
  622. {
  623. // Make sure release works properly on failure.
  624. pMachineEnumTask ->AddRef ();
  625. hr = pMachineEnumTask ->Init( pDataObject, szTaskGroup);
  626. if( hr == S_OK )
  627. {
  628. hr = pMachineEnumTask->QueryInterface( IID_IEnumTASK, (void **)ppEnumTASK );
  629. }
  630. pMachineEnumTask->Release();
  631. }
  632. return hr;
  633. }
  634. //////////////////////////////////////////////////////////////////////////////
  635. /*++
  636. CLoggingMachineNode::OnTaskPadDefineNetworkAccessPolicy
  637. Respond to the Define Network Access Policy taskpad command.
  638. --*/
  639. //////////////////////////////////////////////////////////////////////////////
  640. HRESULT CLoggingMachineNode::OnTaskPadDefineNetworkAccessPolicy(
  641. IDataObject * pDataObject
  642. , VARIANT * pvarg
  643. , VARIANT * pvparam
  644. )
  645. {
  646. TRACE_FUNCTION("CLoggingMachineNode::OnTaskPadDefineNetworkAccessPolicy");
  647. // Check for preconditions:
  648. // None.
  649. if ( !m_fSdoConnected )
  650. {
  651. return S_OK;
  652. }
  653. HRESULT hr = S_OK ;
  654. bool bDummy = TRUE;
  655. // Simulate a call to the OnNewPolicy message on the CPoliciesNode object,
  656. // just as if the user had clicked on New Policy
  657. _ASSERTE( m_pLoggingNode != NULL );
  658. // The process command message will need a pointer to CSnapInObjectRoot
  659. CLoggingComponentData *pComponentData = GetComponentData();
  660. _ASSERTE( pComponentData != NULL );
  661. /*
  662. hr = m_pPoliciesNode->OnNewPolicy(
  663. bDummy // Not needed.
  664. , (CSnapInObjectRoot *) pComponentData
  665. );
  666. */
  667. return hr;
  668. }
  669. //////////////////////////////////////////////////////////////////////////////
  670. /*++
  671. CLoggingMachineNode::BeginConnectAction
  672. --*/
  673. //////////////////////////////////////////////////////////////////////////////
  674. HRESULT CLoggingMachineNode::BeginConnectAction( void )
  675. {
  676. TRACE_FUNCTION("CLoggingMachineNode::BeginConnectAction");
  677. HRESULT hr;
  678. if( NULL != m_pConnectionToServer )
  679. {
  680. // Already begun.
  681. return S_FALSE;
  682. }
  683. m_pConnectionToServer = new CLoggingConnectionToServer(
  684. (CLoggingMachineNode *) this,
  685. m_bstrServerAddress,
  686. m_enumExtendedSnapin == INTERNET_AUTHENTICATION_SERVICE_SNAPIN );
  687. if( ! m_pConnectionToServer )
  688. {
  689. ShowErrorDialog( NULL, IDS_ERROR_CANT_CREATE_OBJECT, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  690. return E_OUTOFMEMORY;
  691. }
  692. m_pConnectionToServer->AddRef();
  693. // This starts the connect action off in another thread.
  694. CLoggingComponentData * pComponentData = GetComponentData();
  695. _ASSERTE( pComponentData != NULL );
  696. _ASSERTE( pComponentData->m_spConsole != NULL );
  697. HWND hWndMainWindow;
  698. hr = pComponentData->m_spConsole->GetMainWindow( &hWndMainWindow );
  699. _ASSERTE( SUCCEEDED( hr ) );
  700. _ASSERTE( NULL != hWndMainWindow );
  701. // This modeless dialog will take care of calling InitSdoPointers
  702. // when it is notified by the worker thread it creates that
  703. // the connect action got an SDO pointer.
  704. HWND hWndConnectDialog = m_pConnectionToServer->Create( hWndMainWindow );
  705. if( ! hWndConnectDialog )
  706. {
  707. // Error -- couldn't create window.
  708. ShowErrorDialog( NULL, USE_DEFAULT, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  709. return E_FAIL;
  710. }
  711. if ( m_enumExtendedSnapin != INTERNET_AUTHENTICATION_SERVICE_SNAPIN )
  712. {
  713. //
  714. // don't show the "Connecting ... " window for IAS, because IAS UI
  715. // already does that
  716. //
  717. // MAM 07/27/98 -- Don't show any connection window at all -- we will
  718. // change the policies icon to an hourglass.
  719. //pConnectionToServer->ShowWindow(SW_SHOW);
  720. }
  721. return S_OK;
  722. }
  723. //+---------------------------------------------------------------------------
  724. //
  725. // Function: CLoggingMachineNode::LoadSdoData
  726. //
  727. // Synopsis: load data from SDO
  728. //
  729. // Arguments: BOOL fDSAvailable -- is DS service available for this machine?
  730. //
  731. // Returns: HRESULT -
  732. //
  733. // History: Created Header byao 6/11/98 3:17:21 PM
  734. // Created for asynchrnous connect call
  735. //+---------------------------------------------------------------------------
  736. HRESULT CLoggingMachineNode::LoadSdoData(BOOL fDSAvailable)
  737. {
  738. TRACE_FUNCTION("CLoggingMachineNode::LoadSdoData");
  739. HRESULT hr = S_OK;
  740. m_fDSAvailable = fDSAvailable;
  741. // Retrieve the SDO interfaces which were obtained
  742. // during the Connect action.
  743. ISdo* pServiceSdo;
  744. // Make sure this is NULL before we try to set it.
  745. pServiceSdo = NULL;
  746. hr = m_pConnectionToServer->GetSdoService( &pServiceSdo );
  747. if( FAILED( hr ) || ! pServiceSdo )
  748. {
  749. ErrorTrace(ERROR_NAPMMC_MACHINENODE, "Can't get Service Sdo");
  750. return hr;
  751. }
  752. // Give the policies node the pointer to the policies sdo collection.
  753. if ( m_pLoggingNode )
  754. {
  755. hr = m_pLoggingNode->InitSdoPointers(pServiceSdo);
  756. }
  757. m_fSdoConnected = TRUE;
  758. return hr;
  759. }
  760. //////////////////////////////////////////////////////////////////////////////
  761. /*++
  762. CServerNode::CheckConnectionToServer
  763. Use this to check that the connection to the server is up before you do
  764. anything with SDO pointers.
  765. Parameters
  766. BOOL fVerbose - set this to TRUE if you want messages output to user.
  767. --*/
  768. //////////////////////////////////////////////////////////////////////////////
  769. STDMETHODIMP CLoggingMachineNode::CheckConnectionToServer( BOOL fVerbose )
  770. {
  771. ATLTRACE(_T("# CLoggingMachineNode::CheckConnectionToServer\n"));
  772. if( ! m_pConnectionToServer )
  773. {
  774. if( fVerbose )
  775. {
  776. ShowErrorDialog( NULL, IDS_ERROR__NO_CONNECTION_ATTEMPTED, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  777. }
  778. return RPC_E_DISCONNECTED;
  779. }
  780. switch( m_pConnectionToServer->GetConnectionStatus() )
  781. {
  782. case NO_CONNECTION_ATTEMPTED:
  783. if( fVerbose )
  784. {
  785. ShowErrorDialog( NULL, IDS_ERROR__NO_CONNECTION_ATTEMPTED, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  786. }
  787. return RPC_E_DISCONNECTED;
  788. break;
  789. case CONNECTING:
  790. if( fVerbose )
  791. {
  792. ShowErrorDialog( NULL, IDS_ERROR__CONNECTION_IN_PROGRESS, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  793. }
  794. return RPC_E_DISCONNECTED;
  795. break;
  796. case CONNECTED:
  797. return S_OK;
  798. break;
  799. case CONNECTION_ATTEMPT_FAILED:
  800. if( fVerbose )
  801. {
  802. ShowErrorDialog( NULL, IDS_ERROR__CONNECTION_ATTEMPT_FAILED, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  803. }
  804. return RPC_E_DISCONNECTED;
  805. break;
  806. case CONNECTION_INTERRUPTED:
  807. if( fVerbose )
  808. {
  809. ShowErrorDialog( NULL, IDS_ERROR__CONNECTION_INTERRUPTED, NULL, S_OK, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  810. }
  811. return RPC_E_DISCONNECTED;
  812. break;
  813. default:
  814. // We shouldn't get here.
  815. _ASSERTE( FALSE );
  816. return E_FAIL;
  817. break;
  818. }
  819. }
  820. //////////////////////////////////////////////////////////////////////////////
  821. /*++
  822. CMachineNode::DataRefresh
  823. --*/
  824. //////////////////////////////////////////////////////////////////////////////
  825. // called to refresh the nodes
  826. HRESULT CLoggingMachineNode::DataRefresh()
  827. {
  828. HRESULT hr = S_OK;
  829. CComPtr<ISdo> spSdo;
  830. hr = m_pConnectionToServer->ReloadSdo(&spSdo, NULL);
  831. // refresh client node
  832. if(hr == S_OK)
  833. {
  834. hr = m_pLoggingNode->DataRefresh(spSdo);
  835. }
  836. return hr;
  837. }
  838. //////////////////////////////////////////////////////////////////////////////
  839. /*++
  840. CLoggingMachineNode::OnRefresh
  841. For more information, see CSnapinNode::OnRefresh which this method overrides.
  842. --*/
  843. //////////////////////////////////////////////////////////////////////////////
  844. HRESULT CLoggingMachineNode::OnRefresh(
  845. LPARAM arg
  846. , LPARAM param
  847. , IComponentData * pComponentData
  848. , IComponent * pComponent
  849. , DATA_OBJECT_TYPES type
  850. )
  851. {
  852. ATLTRACE(_T("# CServerNode::OnRefresh\n"));
  853. // Check for preconditions:
  854. //_ASSERTE( pComponentData != NULL || pComponent != NULL );
  855. return LoadCachedInfoFromSdo();
  856. }
  857. //////////////////////////////////////////////////////////////////////////////
  858. /*++
  859. CLoggingMachineNode::LoadCachedInfoFromSdo
  860. Causes this node and its children to re-read all their cached info from
  861. the SDO's. Call if you change something and you want to make sure that
  862. the display reflects this change.
  863. --*/
  864. //////////////////////////////////////////////////////////////////////////////
  865. HRESULT CLoggingMachineNode::LoadCachedInfoFromSdo( void )
  866. {
  867. ATLTRACE(_T("# CServerNode::LoadCachedInfoFromSdo\n"));
  868. // Check for preconditions:
  869. HRESULT hr;
  870. hr = m_pLoggingNode->LoadCachedInfoFromSdo();
  871. // Ignore failed HRESULT.
  872. return S_OK;
  873. }