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.

796 lines
21 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. evntdata.cpp
  5. Abstract:
  6. This module is responsible for handling the notification
  7. calls from MMC CSakData.
  8. Author:
  9. Rohde Wakefield [rohde] 06-Mar-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "CSakSnap.h"
  14. #include "CSakData.h"
  15. UINT CSakData::m_CFMachineName =
  16. RegisterClipboardFormat( L"MMC_SNAPIN_MACHINE_NAME" );
  17. HRESULT
  18. CSakData::OnFolder(
  19. IN IDataObject* pDataObject,
  20. IN LPARAM arg,
  21. IN LPARAM param
  22. )
  23. /*++
  24. Routine Description:
  25. Param is the unique identifier ( an HSCOPEITEM of the
  26. expanding or contracting item )
  27. Arguments:
  28. pNode - The node which is expanding.
  29. arg -
  30. param -
  31. Return Value:
  32. S_OK - Created successfully.
  33. E_xxxxxxxxxxx - Failure occurred.
  34. --*/
  35. {
  36. WsbTraceIn( L"CSakData::OnFolder", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  37. HRESULT hr = S_OK;
  38. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  39. try {
  40. // if the arg is TRUE, the node is being expanded.
  41. if( arg )
  42. {
  43. CComPtr<ISakNode> pNode;
  44. // Get the basehsm out of the data record.
  45. GetBaseHsmFromDataObject ( pDataObject, &pNode );
  46. if( !pNode ) {
  47. // The dataobject is not one of ours - we must be extending another
  48. // snapin.
  49. // Get the root node from UnkRootNode ( it has already been created
  50. // by Initialize )
  51. WsbAffirmPointer( m_pRootNode );
  52. // We're an extension snapin.
  53. // Get the server focus from the data object.
  54. //
  55. CString hsmName;
  56. WsbAffirmHr( GetServerFocusFromDataObject( pDataObject, hsmName ) );
  57. if( hsmName == "" ) {
  58. m_ManageLocal = TRUE;
  59. m_HsmName = "";
  60. } else {
  61. m_ManageLocal = FALSE;
  62. // eliminate starting \\ if there is one. Computer management
  63. // precedes the server name with \\.
  64. if( hsmName.Left( 2 ) == L"\\\\" ) {
  65. int len = hsmName.GetLength( );
  66. m_HsmName = hsmName.Right( len - 2 );
  67. } else {
  68. m_HsmName = hsmName;
  69. }
  70. }
  71. // Set the Hsm name in SakData and HsmCom objects
  72. WsbAffirmHr( InitializeRootNode( ) );
  73. // Create a scope pane item and insert it
  74. SCOPEDATAITEM sdi;
  75. ZeroMemory( &sdi, sizeof sdi );
  76. sdi.mask = SDI_STR |
  77. SDI_PARAM |
  78. SDI_IMAGE |
  79. SDI_OPENIMAGE |
  80. SDI_PARENT;
  81. sdi.relativeID = ( HSCOPEITEM )( param );
  82. sdi.displayname = MMC_CALLBACK;
  83. WsbAffirmHr( m_pRootNode->GetScopeCloseIcon( m_State, &sdi.nImage ) );
  84. WsbAffirmHr( m_pRootNode->GetScopeOpenIcon( m_State, &sdi.nOpenImage ) );
  85. // This is a special token for the extension root node
  86. sdi.lParam = EXTENSION_RS_FOLDER_PARAM;
  87. // Insert the node into the scope pane and save the scope ID
  88. WsbAffirmHr( m_pNameSpace->InsertItem( &sdi ) );
  89. WsbAffirmHr( m_pRootNode->SetScopeID( ( HSCOPEITEM )( sdi.ID ) ) );
  90. m_RootNodeInitialized = TRUE;
  91. } else {
  92. GUID nodeGuid;
  93. WsbAffirmHr( pNode->GetNodeType( &nodeGuid ) );
  94. if( IsEqualGUID( nodeGuid, cGuidHsmCom ) ) {
  95. if( !m_RootNodeInitialized ) {
  96. m_RootNodeInitialized = TRUE;
  97. //
  98. // Set the scopeitem in the node
  99. //
  100. WsbAffirmHr( pNode->SetScopeID( ( HSCOPEITEM )( param ) ) );
  101. //
  102. // Update the text and icon ( text is wrong if loaded
  103. // from file and command line switch given for
  104. // different machine
  105. //
  106. SCOPEDATAITEM sdi;
  107. ZeroMemory( &sdi, sizeof sdi );
  108. sdi.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE;
  109. sdi.ID = ( HSCOPEITEM )( param );
  110. sdi.displayname = MMC_CALLBACK;
  111. WsbAffirmHr( pNode->GetScopeCloseIcon( m_State, &sdi.nImage ) );
  112. WsbAffirmHr( pNode->GetScopeOpenIcon( m_State, &sdi.nOpenImage ) );
  113. WsbAffirmHr( m_pNameSpace->SetItem( &sdi ) );
  114. }
  115. }
  116. //
  117. // Initialize child node list prior to graphically enumerating them
  118. //
  119. WsbAffirmHr( EnsureChildrenAreCreated( pNode ) );
  120. //
  121. // Param contains the HSCOPEITEM of the node being opened.
  122. //
  123. WsbAffirmHr( EnumScopePane( pNode, ( HSCOPEITEM )( param ) ) );
  124. }
  125. }
  126. } WsbCatch( hr );
  127. WsbTraceOut( L"CSakData::OnFolder", L"hr = <%ls>", WsbHrAsString( hr ) );
  128. return( hr );
  129. }
  130. ////////////////////////////////////////////////////////////////////////////////////
  131. //
  132. // Description: Get the server name from the supplied data object. The dataobject
  133. // is implemented by the snapin we are extending
  134. //
  135. HRESULT CSakData::GetServerFocusFromDataObject( IDataObject *pDataObject, CString& HsmName )
  136. {
  137. HRESULT hr = S_OK;
  138. try {
  139. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  140. FORMATETC formatetc = { (CLIPFORMAT)m_CFMachineName, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  141. // Allocate memory for the stream
  142. // Note: we add 2 bytes because Computer Management puts \\ at the
  143. // beginning of the computer name. - AHB 12/22/97
  144. //
  145. stgmedium.hGlobal = GlobalAlloc( GMEM_SHARE, sizeof( WCHAR ) * ( MAX_PATH + 1 + 2 ) );
  146. WsbAffirmPointer( stgmedium.hGlobal )
  147. // Attempt to get data from the object
  148. WsbAffirmHr( pDataObject->GetDataHere( &formatetc, &stgmedium ) );
  149. HsmName = ( OLECHAR * ) stgmedium.hGlobal;
  150. GlobalFree( stgmedium.hGlobal );
  151. } WsbCatch ( hr ) ;
  152. return hr;
  153. }
  154. HRESULT
  155. CSakData::OnShow(
  156. IN IDataObject* pDataObject,
  157. IN LPARAM arg,
  158. IN LPARAM param
  159. )
  160. /*++
  161. Routine Description:
  162. The result view is just about to be shown.
  163. Set the headers for the result view.
  164. Param is the unique identifier ( an HSCOPEITEM ) of the
  165. selected or deselected item.
  166. Arguments:
  167. pNode - The node which is showing.
  168. arg -
  169. param -
  170. Return Value:
  171. S_OK - Created successfully.
  172. E_xxxxxxxxxxx - Failure occurred.
  173. --*/
  174. {
  175. WsbTraceIn( L"CSakData::OnShow", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  176. HRESULT hr = S_OK;
  177. try {
  178. CComPtr<ISakNode> pNode;
  179. // Get the basehsm out of the data record.
  180. GetBaseHsmFromDataObject ( pDataObject, &pNode );
  181. //
  182. // Arg is TRUE when it is time to enumerate
  183. //
  184. if( arg ) {
  185. //
  186. // Initialize child node list prior to graphically enumerating them
  187. //
  188. WsbAffirmHr( EnsureChildrenAreCreated( pNode ) );
  189. //
  190. // Enumerate both the scope and result views. "Param" contains the
  191. // HSCOPEITEM of the node being shown.
  192. //
  193. WsbAffirmHr( EnumScopePane( pNode, ( HSCOPEITEM )( param ) ) );
  194. } else {
  195. //
  196. // Free data associated with the result pane items, because
  197. // your node is no longer being displayed.
  198. // Note: The console will remove the items from the result pane
  199. //
  200. }
  201. } WsbCatch( hr );
  202. WsbTraceOut( L"CSakData::OnShow", L"hr = <%ls>", WsbHrAsString( hr ) );
  203. return( hr );
  204. }
  205. HRESULT
  206. CSakData::OnSelect(
  207. IN IDataObject* pDataObject,
  208. IN LPARAM arg,
  209. IN LPARAM param
  210. )
  211. /*++
  212. Routine Description:
  213. Called when a "folder" ( node ) is going to be opened ( not expanded ).
  214. Param is the unique identifier ( an HSCOPEITEM of the
  215. expanding or contracting item )
  216. Arguments:
  217. pNode - The node which is expanding.
  218. arg -
  219. param -
  220. Return Value:
  221. S_OK - Created successfully.
  222. E_xxxxxxxxxxx - Failure occurred.
  223. --*/
  224. {
  225. WsbTraceIn( L"CSakData::OnSelect", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  226. HRESULT hr = S_OK;
  227. WsbTraceOut( L"CSakData::OnSelect", L"hr = <%ls>", WsbHrAsString( hr ) );
  228. return( hr );
  229. }
  230. HRESULT
  231. CSakData::OnMinimize(
  232. IN IDataObject* pDataObject,
  233. IN LPARAM arg,
  234. IN LPARAM param
  235. )
  236. /*++
  237. Routine Description:
  238. Arguments:
  239. pNode - The node which is expanding.
  240. arg -
  241. param -
  242. Return Value:
  243. S_OK - Created successfully.
  244. E_xxxxxxxxxxx - Failure occurred.
  245. --*/
  246. {
  247. WsbTraceIn( L"CSakData::OnMinimize", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  248. HRESULT hr = S_OK;
  249. WsbTraceOut( L"CSakData::OnMinimize", L"hr = <%ls>", WsbHrAsString( hr ) );
  250. return( hr );
  251. }
  252. HRESULT
  253. CSakData::OnContextHelp(
  254. IN IDataObject* pDataObject,
  255. IN LPARAM arg,
  256. IN LPARAM param
  257. )
  258. /*++
  259. Routine Description:
  260. Called when help is selected on a node. Shows the top level help.
  261. Arguments:
  262. pNode - The node which is requesting help.
  263. arg -
  264. param -
  265. Return Value:
  266. S_OK - Created successfully.
  267. E_xxxxxxxxxxx - Failure occurred.
  268. --*/
  269. {
  270. WsbTraceIn( L"CSakData::OnContextHelp", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  271. HRESULT hr = S_OK;
  272. try {
  273. //
  274. // Get the help interface
  275. //
  276. CComPtr<IDisplayHelp> pDisplayHelp;
  277. WsbAffirmHr( m_pConsole.QueryInterface( &pDisplayHelp ) );
  278. //
  279. // Form up the correct name
  280. //
  281. CWsbStringPtr helpFile;
  282. WsbAffirmHr( helpFile.LoadFromRsc( _Module.m_hInst, IDS_HELPFILELINK ) );
  283. WsbAffirmHr( helpFile.Append( L"::/rss_node_howto.htm" ) );
  284. //
  285. // And show it
  286. //
  287. WsbAffirmHr( pDisplayHelp->ShowTopic( helpFile ) );
  288. } WsbCatch( hr );
  289. WsbTraceOut( L"CSakData::OnContextHelp", L"hr = <%ls>", WsbHrAsString( hr ) );
  290. return( hr );
  291. }
  292. HRESULT
  293. CSakData::EnumScopePane(
  294. IN ISakNode* pNode,
  295. IN HSCOPEITEM pParent
  296. )
  297. /*++
  298. Routine Description:
  299. Insert the items into the scopepane under the item which is represented by
  300. cookie and pParent.
  301. Arguments:
  302. pNode - The node which is expanding.
  303. arg -
  304. param -
  305. Return Value:
  306. S_OK - Created successfully.
  307. E_xxxxxxxxxxx - Failure occurred.
  308. --*/
  309. {
  310. WsbTraceIn( L"CSakData::EnumScopePane", L"pNode = <0x%p>, pParent = <0x%p>", pNode, pParent );
  311. HRESULT hr = S_OK;
  312. try {
  313. //
  314. // Verify params
  315. //
  316. WsbAffirmPointer( pNode );
  317. WsbAffirmPointer( pParent );
  318. //
  319. // make sure we QI'ed for the interface
  320. //
  321. WsbAffirmPointer( m_pNameSpace );
  322. //
  323. // Avoid enumerating the same node twice. Once enumerated, a node remembers it.
  324. //
  325. BOOL isEnumerated;
  326. WsbAffirmHr( pNode->GetEnumState( &isEnumerated ) );
  327. if( !isEnumerated ) {
  328. //
  329. // This node has NOT been enumerated in the tree.
  330. //
  331. if( S_OK == pNode->IsContainer( ) ) {
  332. CComPtr<IEnumUnknown> pEnum; // child enumerator object
  333. CComQIPtr<ISakNode, &IID_ISakNode> pBaseHsmChild; // child pointer to BaseHsm interface
  334. // Create an Enumeration object for the children and enumerate them
  335. WsbAffirmHr( pNode->EnumChildren( &pEnum ) );
  336. CComPtr<IUnknown> pUnkChild; // pointer to next child in list
  337. while( pEnum->Next( 1, &pUnkChild, NULL ) == S_OK ) {
  338. pBaseHsmChild = pUnkChild;
  339. WsbAffirmPointer( pBaseHsmChild );
  340. //
  341. // If this is a leaf node, don't enumerate in scope pane.
  342. //
  343. if( pBaseHsmChild->IsContainer( ) != S_OK ) {
  344. pBaseHsmChild.Release( );
  345. pUnkChild.Release( );
  346. continue;
  347. }
  348. //
  349. // Set up a SCOPEDATAITEM for this child node and insert the child into the scope treeview
  350. //
  351. SCOPEDATAITEM childScopeItem;
  352. memset( &childScopeItem, 0, sizeof( SCOPEDATAITEM ) );
  353. //
  354. // Set String to be callback
  355. //
  356. childScopeItem.displayname = MMC_CALLBACK;
  357. childScopeItem.mask |= SDI_STR;
  358. //
  359. // Add "expandable" indicator to tree node if
  360. // this node has children. Fake out number
  361. // of children.
  362. //
  363. if( pBaseHsmChild->IsContainer( ) == S_OK ) {
  364. childScopeItem.cChildren = 1;
  365. childScopeItem.mask |= SDI_CHILDREN;
  366. }
  367. //
  368. // Set child node's scope item parent.
  369. //
  370. childScopeItem.relativeID = pParent;
  371. childScopeItem.mask |= SDI_PARENT;
  372. //
  373. // Set the param in the ScopeItem to the unknown pointer
  374. // to this node, so that when this scopeitem is sent back
  375. // to us, we can get it out and use it to look up
  376. // node-specific info.
  377. //
  378. WsbAffirmHr( GetCookieFromBaseHsm( pBaseHsmChild, (MMC_COOKIE*)(&childScopeItem.lParam) ) );
  379. childScopeItem.mask |= SDI_PARAM;
  380. childScopeItem.mask |= SDI_STATE;
  381. childScopeItem.nState = 0;
  382. //
  383. // Note - After insertion into the tree, the SCOPEITEM ID member contains the handle to
  384. // the newly inserted item
  385. //
  386. WsbAffirmHr ( pBaseHsmChild->GetScopeCloseIcon( m_State, &childScopeItem.nImage ) );
  387. childScopeItem.mask |= SDI_IMAGE;
  388. WsbAffirmHr ( pBaseHsmChild->GetScopeOpenIcon( m_State, &childScopeItem.nOpenImage ) );
  389. childScopeItem.mask |= SDI_OPENIMAGE;
  390. WsbAffirmHr( m_pNameSpace->InsertItem( &childScopeItem ) );
  391. WsbAffirm( childScopeItem.ID != NULL, E_UNEXPECTED );
  392. //
  393. // Set the scopeitem id in the node object
  394. //
  395. WsbAffirmHr( pBaseHsmChild->SetScopeID( childScopeItem.ID ) );
  396. //
  397. // release the test interface pointer and string for next node
  398. //
  399. pBaseHsmChild.Release( );
  400. pUnkChild.Release( );
  401. }
  402. //
  403. // Indicate that this node has been enumerated
  404. //
  405. WsbAffirmHr( pNode->SetEnumState( TRUE ) );
  406. }
  407. }
  408. } WsbCatch( hr );
  409. WsbTraceOut( L"CSakData::EnumScopePane", L"hr = <%ls>", WsbHrAsString( hr ) );
  410. return( hr );
  411. }
  412. HRESULT
  413. CSakData::EnsureChildrenAreCreated(
  414. IN ISakNode * pNode
  415. )
  416. /*++
  417. Routine Description:
  418. Guarantee that the immediate children of a particular node are created
  419. in our hierarchical list of nodes.
  420. Arguments:
  421. pNode - The node to check.
  422. Return Value:
  423. S_OK - Created successfully.
  424. E_xxxxxxxxxxx - Failure occurred.
  425. --*/
  426. {
  427. WsbTraceIn( L"CSakData::EnsureChildrenAreCreated", L"pNode = <0x%p>", pNode );
  428. HRESULT hr = S_OK;
  429. try {
  430. //
  431. // Create the node's children if the node's list of children is
  432. // currently invalid ( i.e. - never created, or out-of-date )
  433. //
  434. if( pNode->ChildrenAreValid( ) == S_FALSE ) {
  435. WsbAffirmHr( CreateChildNodes( pNode ) );
  436. }
  437. } WsbCatch( hr );
  438. WsbTraceOut( L"CSakData::EnsureChildrenAreCreated", L"hr = <%ls>", WsbHrAsString( hr ) );
  439. return( hr );
  440. }
  441. HRESULT
  442. CSakData::OnRemoveChildren(
  443. IN IDataObject* pDataObject
  444. )
  445. /*++
  446. Routine Description:
  447. Arguments:
  448. pDataObject - The node
  449. Return Value:
  450. S_OK - Removed successfully.
  451. E_xxxxxxxxxxx - Failure occurred.
  452. --*/
  453. {
  454. WsbTraceIn( L"CSakData::OnRemoveChildren", L"pDataObject = <0x%p>", pDataObject );
  455. HRESULT hr = S_OK;
  456. try {
  457. CComPtr<ISakNode> pNode;
  458. WsbAffirmHr( GetBaseHsmFromDataObject( pDataObject, &pNode ) );
  459. WsbAffirmHr( RemoveChildren( pNode ) );
  460. } WsbCatch( hr );
  461. WsbTraceOut( L"CSakData::OnRemoveChildren", L"hr = <%ls>", WsbHrAsString( hr ) );
  462. return( hr );
  463. }
  464. HRESULT
  465. CSakData::RemoveChildren(
  466. IN ISakNode* pNode
  467. )
  468. /*++
  469. Routine Description:
  470. Recursively clean up the cookies for this node's children,
  471. but not this node itself.
  472. Arguments:
  473. pNode - The node
  474. Return Value:
  475. S_OK - Removed successfully.
  476. E_xxxxxxxxxxx - Failure occurred.
  477. --*/
  478. {
  479. WsbTraceIn( L"CSakData::RemoveChildren", L"pNode = <0x%p>", pNode );
  480. HRESULT hr = S_OK;
  481. try {
  482. CComPtr<IEnumUnknown> pEnum; // child enumerator object
  483. CComPtr<ISakNode> pChild; // child pointer to BaseHsm interface
  484. // Create an Enumeration object for the children and enumerate them
  485. WsbAffirmHr( pNode->EnumChildren( &pEnum ) );
  486. CComPtr<IUnknown> pUnkChild; // pointer to next child in list
  487. while( pEnum->Next( 1, &pUnkChild, NULL ) == S_OK ) {
  488. WsbAffirmHr( pUnkChild.QueryInterface( &pChild ) );
  489. RemoveChildren( pChild ); // OK to fail and keep going
  490. DetachFromNode( pChild );
  491. pUnkChild.Release( );
  492. pChild.Release( );
  493. }
  494. } WsbCatch( hr );
  495. WsbTraceOut( L"CSakData::RemoveChildren", L"hr = <%ls>", WsbHrAsString( hr ) );
  496. return( hr );
  497. }
  498. STDMETHODIMP
  499. CSakData::DetachFromNode(
  500. IN ISakNode* pNode )
  501. /*++
  502. Routine Description:
  503. Called when a node is terminating in order for sakdata to remove
  504. any cookies holding onto node.
  505. Arguments:
  506. pNode - The node
  507. Return Value:
  508. S_OK - Removed successfully.
  509. E_xxxxxxxxxxx - Failure occurred.
  510. --*/
  511. {
  512. WsbTraceIn( L"CSakData::DetachFromNode", L"" );
  513. HRESULT hr = S_OK;
  514. try {
  515. WsbAffirmPointer( pNode );
  516. RS_PRIVATE_DATA data;
  517. WsbAffirmHr( pNode->GetPrivateData( &data ) );
  518. CSakDataNodePrivate* pNodePriv = (CSakDataNodePrivate*)data;
  519. if( pNodePriv && SUCCEEDED( CSakDataNodePrivate::Verify( pNodePriv ) ) ) {
  520. delete pNodePriv;
  521. }
  522. } WsbCatch( hr );
  523. WsbTraceOut( L"CSakData::DetachFromNode", L"" );
  524. return( hr );
  525. }