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.

388 lines
14 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. CSakData.h
  5. Abstract:
  6. IComponentData implementation for Snapin.
  7. Author:
  8. Rohde Wakefield [rohde] 12-Aug-1997
  9. Revision History:
  10. --*/
  11. #ifndef _CSAKDATA_H
  12. #define _CSAKDATA_H
  13. #define RS_SCOPE_IMAGE_ARRAY_MAX 100
  14. //typedef struct {
  15. // USHORT listViewId;
  16. // USHORT colCount;
  17. // USHORT columnWidths[BHSM_MAX_CHILD_PROPS];
  18. //} COLUMN_WIDTH_SET_PROP_PAGE;
  19. // Maximum number of listview controls that have their properties saved
  20. // #define MAX_LISTVIEWS 20
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CSakDataWnd window
  23. class CSakData;
  24. class CSakDataWnd : public CWnd
  25. {
  26. // Construction
  27. public:
  28. CSakDataWnd( ) {};
  29. BOOL Create( CSakData * pSakData );
  30. virtual void PostNcDestroy( );
  31. // Attributes
  32. public:
  33. CSakData * m_pSakData;
  34. // Operations
  35. public:
  36. // Overrides
  37. // ClassWizard generated virtual function overrides
  38. //{{AFX_VIRTUAL(CSakDataWnd)
  39. //}}AFX_VIRTUAL
  40. // Implementation
  41. public:
  42. virtual ~CSakDataWnd() {};
  43. // Generated message map functions
  44. #define WM_SAKDATA_UPDATE_ALL_VIEWS ( WM_USER + 1 )
  45. #define WM_SAKDATA_REFRESH_NODE ( WM_USER + 2 )
  46. void PostUpdateAllViews( MMC_COOKIE Cookie );
  47. void PostRefreshNode( MMC_COOKIE Cookie );
  48. protected:
  49. //{{AFX_MSG(CSakDataWnd)
  50. // NOTE - the ClassWizard will add and remove member functions here.
  51. //}}AFX_MSG
  52. virtual LONG OnUpdateAllViews( UINT, IN LONG lParam );
  53. virtual LONG OnRefreshNode( UINT, IN LONG lParam );
  54. DECLARE_MESSAGE_MAP()
  55. };
  56. class CSakDataNodePrivate
  57. {
  58. public:
  59. CSakDataNodePrivate( ISakNode* pNode );
  60. ~CSakDataNodePrivate( );
  61. static HRESULT Verify( CSakDataNodePrivate* pNodePriv );
  62. DWORD m_Magic;
  63. CComPtr<ISakNode> m_pNode;
  64. };
  65. #define RS_NODE_MAGIC_GOOD ((DWORD)0xF0E1D2C3)
  66. #define RS_NODE_MAGIC_DEFUNCT ((DWORD)0x4BADF00D)
  67. /////////////////////////////////////////////////////////////////////////////
  68. // COM class representing the SakSnap snapin object
  69. class ATL_NO_VTABLE CSakData :
  70. public IComponentData, // Access to cached info
  71. public IExtendPropertySheet2,// add pages to the property sheet of an item.
  72. public IExtendContextMenu, // add items to context menu of an item
  73. public ISnapinHelp2, // Add support for HTMLHelp
  74. public IDataObject, // To support data object queries.
  75. public ISakSnapAsk, // provided so that nodes can query snapin info
  76. public IPersistStream,
  77. public CComObjectRoot // handle object reference counts for objects
  78. // public CComCoClass<CSakData,&CLSID_HsmAdminData>
  79. {
  80. public:
  81. CSakData() {};
  82. BEGIN_COM_MAP(CSakData)
  83. COM_INTERFACE_ENTRY(IComponentData)
  84. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  85. COM_INTERFACE_ENTRY(IExtendPropertySheet2)
  86. COM_INTERFACE_ENTRY(IExtendContextMenu)
  87. COM_INTERFACE_ENTRY(IDataObject)
  88. COM_INTERFACE_ENTRY(ISakSnapAsk)
  89. COM_INTERFACE_ENTRY(ISnapinHelp)
  90. COM_INTERFACE_ENTRY(ISnapinHelp2)
  91. COM_INTERFACE_ENTRY(IPersistStream)
  92. END_COM_MAP()
  93. static UINT m_cfMultiSelect;
  94. static UINT m_cfObjectTypes;
  95. public:
  96. virtual const CLSID& GetCoClassID() = 0;
  97. virtual const BOOL IsPrimaryImpl() = 0;
  98. public:
  99. static UINT m_nImageArray[RS_SCOPE_IMAGE_ARRAY_MAX];
  100. static INT m_nImageCount;
  101. // IComponentData
  102. public:
  103. STDMETHOD( Initialize ) ( IUnknown* pUnk );
  104. STDMETHOD( CreateComponent ) ( IComponent** ppComponent );
  105. STDMETHOD( Notify ) ( IDataObject* pDataObject, MMC_NOTIFY_TYPE, LPARAM arg, LPARAM param );
  106. STDMETHOD( Destroy ) ( void );
  107. STDMETHOD( QueryDataObject ) ( MMC_COOKIE cookie, DATA_OBJECT_TYPES, IDataObject** ppDataObject);
  108. STDMETHOD( GetDisplayInfo ) ( SCOPEDATAITEM* pScopeItem);
  109. STDMETHOD( CompareObjects ) ( IDataObject* pDataObjectA, IDataObject* pDataObjectB);
  110. // IExtendPropertySheet interface
  111. public:
  112. STDMETHOD( CreatePropertyPages )( LPPROPERTYSHEETCALLBACK lpProvider, RS_NOTIFY_HANDLE handle, LPDATAOBJECT lpIDataObject );
  113. STDMETHOD( QueryPagesFor ) ( LPDATAOBJECT lpDataObject );
  114. // IExtendPropertySheet2 interface
  115. public:
  116. STDMETHOD( GetWatermarks ) ( IN LPDATAOBJECT pDataObject, OUT HBITMAP* pWatermark, OUT HBITMAP* pHeader, OUT HPALETTE* pPalette, OUT BOOL* pStretch );
  117. // IExtendContextMenu
  118. public:
  119. STDMETHOD( AddMenuItems ) ( IDataObject* pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG* pInsertionAllowed );
  120. STDMETHOD( Command ) ( long nCommandID, IDataObject* pDataObject );
  121. // ISnapinHelp2
  122. public:
  123. STDMETHOD( GetHelpTopic ) ( LPOLESTR * pHelpTopic );
  124. STDMETHOD( GetLinkedTopics ) ( LPOLESTR * pHelpTopic );
  125. // IDataObject methods
  126. public:
  127. // Implemented
  128. STDMETHOD( SetData ) ( LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium, BOOL bRelease );
  129. STDMETHOD( GetData ) ( LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium );
  130. STDMETHOD( GetDataHere ) ( LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium );
  131. STDMETHOD( EnumFormatEtc ) ( DWORD dwDirection, LPENUMFORMATETC* ppEnumFormatEtc );
  132. // IPersistStream methods
  133. STDMETHOD( Save )( IStream *pStm, BOOL fClearDirty );
  134. STDMETHOD( Load )( IStream *pStm );
  135. STDMETHOD( IsDirty )(void);
  136. STDMETHOD( GetSizeMax )( ULARGE_INTEGER *pcbSize );
  137. STDMETHOD( GetClassID )( CLSID *pClassID );
  138. // Not Implemented
  139. private:
  140. STDMETHOD( QueryGetData ) ( LPFORMATETC /*lpFormatetc*/ ) { return E_NOTIMPL; };
  141. STDMETHOD( GetCanonicalFormatEtc ) ( LPFORMATETC /*lpFormatetcIn*/, LPFORMATETC /*lpFormatetcOut*/ ) { return E_NOTIMPL; };
  142. STDMETHOD( DAdvise ) ( LPFORMATETC /*lpFormatetc*/, DWORD /*advf*/, LPADVISESINK /*pAdvSink*/, LPDWORD /*pdwConnection*/ ) { return E_NOTIMPL; };
  143. STDMETHOD( DUnadvise ) ( DWORD /*dwConnection*/ ) { return E_NOTIMPL; };
  144. STDMETHOD( EnumDAdvise ) ( LPENUMSTATDATA* /*ppEnumAdvise*/ ) { return E_NOTIMPL; };
  145. // ISakSnapAsk interface members
  146. public:
  147. STDMETHOD( GetNodeOfType ) ( REFGUID nodetype, ISakNode** ppUiNode );
  148. STDMETHOD( GetHsmServer ) ( IHsmServer** ppHsmServer );
  149. STDMETHOD( GetRmsServer ) ( IRmsServer** ppRmsServer );
  150. STDMETHOD( GetFsaServer ) ( IFsaServer** ppFsaServer );
  151. STDMETHOD( RefreshNode ) ( ISakNode* pNode );
  152. STDMETHOD( UpdateAllViews ) ( ISakNode* pUnkNode );
  153. STDMETHOD( ShowPropertySheet )( ISakNode* pUnkNode, IDataObject *pDataObject, INT initialPage );
  154. STDMETHOD( GetHsmName ) ( OUT OLECHAR ** pszName OPTIONAL );
  155. STDMETHOD( GetState ) ();
  156. STDMETHOD( Disable ) ( IN BOOL Disable = TRUE );
  157. STDMETHOD( IsDisabled ) ( );
  158. STDMETHOD( CreateWizard ) ( IN ISakWizard * pWizard );
  159. STDMETHOD( DetachFromNode ) ( IN ISakNode* pNode );
  160. // Pseudo Constructor / Destructor
  161. public:
  162. HRESULT FinalConstruct();
  163. void FinalRelease();
  164. ULONG InternalAddRef( );
  165. ULONG InternalRelease( );
  166. // helper method utilized by Data Object Functions
  167. private:
  168. HRESULT Retrieve ( const void* pBuffer, DWORD len, LPSTGMEDIUM lpMedium );
  169. HRESULT RetrieveDisplayName ( LPSTGMEDIUM lpMedium );
  170. HRESULT RetrieveNodeTypeData( LPSTGMEDIUM lpMedium );
  171. HRESULT RetrieveNodeTypeStringData( LPSTGMEDIUM lpMedium );
  172. HRESULT RetrieveClsid ( LPSTGMEDIUM lpMedium );
  173. static UINT m_cfDisplayName;
  174. static UINT m_cfNodeType;
  175. static UINT m_cfNodeTypeString;
  176. static UINT m_cfClassId;
  177. // Methods to work with the image lists
  178. private:
  179. HRESULT OnAddImages();
  180. // Methods to work between cookie, DataObject, and ISakNode*
  181. public:
  182. HRESULT GetBaseHsmFromDataObject ( IDataObject * pDataObject, ISakNode ** ppBaseHsm, IEnumGUID **ppObjectId = NULL, IEnumUnknown **ppUnkNode = NULL );
  183. HRESULT GetBaseHsmFromCookie ( MMC_COOKIE Cookie, ISakNode ** ppBaseHsm );
  184. HRESULT GetDataObjectFromBaseHsm ( ISakNode * pBaseHsm, IDataObject**ppDataObject );
  185. HRESULT GetDataObjectFromCookie ( MMC_COOKIE Cookie, IDataObject**ppDataObject );
  186. HRESULT GetCookieFromBaseHsm ( ISakNode * pBaseHsm, MMC_COOKIE * pCookie );
  187. HRESULT IsDataObjectMs ( IDataObject *pDataObject );
  188. HRESULT IsDataObjectOt ( IDataObject *pDataObject );
  189. HRESULT IsDataObjectMultiSelect ( IDataObject *pDataObject );
  190. // Helpers for un-ravelling multi-select data objects
  191. private:
  192. HRESULT GetBaseHsmFromMsDataObject ( IDataObject * pDataObject, ISakNode ** ppBaseHsm, IEnumGUID ** ppObjectId, IEnumUnknown **ppEnumUnk );
  193. HRESULT GetBaseHsmFromOtDataObject ( IDataObject * pDataObject, ISakNode ** ppBaseHsm, IEnumGUID ** ppObjectId, IEnumUnknown **ppEnumUnk );
  194. // Methods to work with nodes as data objects
  195. private:
  196. HRESULT SetContextType ( IDataObject* pDataObject, DATA_OBJECT_TYPES type );
  197. // Notify event handlers
  198. protected:
  199. HRESULT OnFolder ( IDataObject *pDataObject, LPARAM arg, LPARAM param );
  200. HRESULT OnShow ( IDataObject *pDataObject, LPARAM arg, LPARAM param );
  201. HRESULT OnSelect ( IDataObject *pDataObject, LPARAM arg, LPARAM param );
  202. HRESULT OnMinimize ( IDataObject *pDataObject, LPARAM arg, LPARAM param );
  203. HRESULT OnContextHelp ( IDataObject *pDataObject, LPARAM arg, LPARAM param );
  204. HRESULT OnRemoveChildren( IDataObject *pDataObject );
  205. HRESULT RemoveChildren( ISakNode *pNode );
  206. // Handle posted (delayed) messages from nodes.
  207. public:
  208. HRESULT InternalUpdateAllViews( MMC_COOKIE Cookie );
  209. HRESULT InternalRefreshNode( MMC_COOKIE Cookie );
  210. HRESULT RefreshNodeEx( ISakNode * pNode );
  211. private:
  212. // Initialize the root node
  213. HRESULT InitializeRootNode( void );
  214. // Guarantee that the children of a particular node are created in our hierarchical list.
  215. friend class CSakSnap;
  216. HRESULT EnsureChildrenAreCreated( ISakNode* pNode );
  217. HRESULT CreateChildNodes( ISakNode* pNode );
  218. // Enumerate the children of a node in scope pane.
  219. HRESULT EnumScopePane( ISakNode* pNode, HSCOPEITEM pParent );
  220. HRESULT FreeEnumChildren( ISakNode* pBaseHsmParent );
  221. // Connection helper functions
  222. HRESULT AffirmServiceConnection(INT ConnType);
  223. HRESULT VerifyConnection(INT ConnType);
  224. HRESULT ClearConnections( );
  225. HRESULT RawConnect(INT ConnType);
  226. HRESULT RunSetupWizard(IHsmServer * pServer );
  227. HRESULT RetargetSnapin( );
  228. // About Helper functions
  229. private:
  230. HRESULT AboutHelper(UINT nID, LPOLESTR* lpPtr);
  231. // Internal Data
  232. private:
  233. static UINT m_CFMachineName;
  234. HRESULT GetServerFocusFromDataObject(IDataObject *pDataObject, CString& HsmName);
  235. // Interface pointers
  236. CComPtr<IConsole> m_pConsole; // Console's IFrame interface
  237. CComPtr<IConsoleNameSpace> m_pNameSpace; // SakSnap interface pointer to scope pane
  238. CComPtr<IImageList> m_pImageScope; // SakSnap interface pointer to scope pane image list
  239. CComPtr<ISakNode> m_pRootNode; // Node tree root
  240. CComPtr<IHsmServer> m_pHsmServer; // Hsm Engine pointer
  241. CComPtr<IRmsServer> m_pRmsServer; // Rms pointer
  242. CComPtr<IFsaServer> m_pFsaServer; // Fsa pointer
  243. CString m_HsmName; // name of Hsm to connect to.
  244. BOOL m_ManageLocal; // To know if we should manage the local server.
  245. BOOL m_PersistManageLocal; // To know if snapin configuration is transient.
  246. BOOL m_RootNodeInitialized; // To know if we need to init node on expand
  247. // Persistence data and functions
  248. BOOL m_IsDirty;
  249. // Store user profile data for the listviews in the property sheets
  250. // Note: result view data is stored in CSakSnap
  251. // COLUMN_WIDTH_SET_PROP_PAGE m_ListViewWidths[MAX_LISTVIEWS];
  252. // USHORT m_cListViewWidths;
  253. void SetDirty( BOOL b = TRUE ) { m_IsDirty = b; }
  254. void ClearDirty() { m_IsDirty = FALSE; }
  255. BOOL ThisIsDirty() { return m_IsDirty; }
  256. BOOL m_State;
  257. void SetState( BOOL State );
  258. BOOL m_FirstTime;
  259. BOOL m_Disabled;
  260. // Variables to track RMS's state separately, since it can be delayed
  261. // in coming up when other services are OK
  262. HRESULT m_HrRmsConnect;
  263. // Static functions
  264. public:
  265. static INT AddImage( UINT rId );
  266. //
  267. // Command Line parsing functions
  268. //
  269. private:
  270. class CParamParse : public CCommandLineInfo {
  271. public:
  272. CParamParse( ) : m_ManageLocal( 0 ), m_SetHsmName( 0 ), m_SetManageLocal( 0 ), m_SetPersistManageLocal( 0 ) { }
  273. virtual void ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast );
  274. CString m_HsmName;
  275. BOOL m_ManageLocal;
  276. BOOL m_PersistManageLocal;
  277. BOOL m_SetHsmName;
  278. BOOL m_SetManageLocal;
  279. BOOL m_SetPersistManageLocal;
  280. static const CString m_DsFlag;
  281. };
  282. CParamParse m_Parse;
  283. void InitFromCommandLine( );
  284. CSakDataWnd *m_pWnd;
  285. };
  286. class CSakDataPrimaryImpl : public CSakData,
  287. public CComCoClass<CSakDataPrimaryImpl, &CLSID_HsmAdminDataSnapin>
  288. {
  289. public:
  290. DECLARE_REGISTRY_RESOURCEID(IDR_HsmAdminDataSnapin)
  291. virtual const CLSID & GetCoClassID() { return CLSID_HsmAdminDataSnapin; }
  292. virtual const BOOL IsPrimaryImpl() { return TRUE; }
  293. };
  294. class CSakDataExtensionImpl : public CSakData,
  295. public CComCoClass<CSakDataExtensionImpl, &CLSID_HsmAdminDataExtension>
  296. {
  297. public:
  298. DECLARE_REGISTRY_RESOURCEID(IDR_HsmAdminDataExtension)
  299. virtual const CLSID & GetCoClassID(){ return CLSID_HsmAdminDataExtension; }
  300. virtual const BOOL IsPrimaryImpl() { return FALSE; }
  301. };
  302. /////////////////////////////////////////////////////////////////////////////
  303. #endif