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.

934 lines
34 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #ifndef WSECMGR_SNAPMGR_H
  9. #define WSECMGR_SNAPMGR_H
  10. #include "resource.h" // main symbols
  11. #include "attr.h"
  12. #ifdef INITGUID
  13. #undef INITGUID
  14. #endif
  15. #include <gpedit.h>
  16. #include "uithread.h"
  17. #include "hidwnd.h"
  18. #include "wmihooks.h"
  19. #include "cookie.h"
  20. #define MAX_CONTEXT_MENU_STRLEN 128
  21. struct MENUDATARES
  22. {
  23. WCHAR szBuffer[MAX_CONTEXT_MENU_STRLEN*2];
  24. UINT uResID;
  25. };
  26. struct MENUMAP
  27. {
  28. MENUDATARES* dataRes;
  29. CONTEXTMENUITEM* ctxMenu;
  30. };
  31. #define DECLARE_MENU(theClass) \
  32. class theClass \
  33. { \
  34. public: \
  35. static LPCONTEXTMENUITEM GetContextMenuItem() { return GetMenuMap()->ctxMenu; }; \
  36. static MENUMAP* GetMenuMap(); \
  37. };
  38. #define BEGIN_MENU(theClass) \
  39. MENUMAP* theClass::GetMenuMap() {
  40. #define BEGIN_CTX static CONTEXTMENUITEM ctx[] = {
  41. #define CTX_ENTRY(cmdID, fFlags, fInsert) { L"",L"", cmdID, CCM_INSERTIONPOINTID_PRIMARY_TOP /*| fInsert*/, fFlags, 0 },
  42. #define END_CTX { NULL, NULL, 0, 0, 0, 0} };
  43. #define BEGIN_RES static MENUDATARES dataRes[] = {
  44. #define RES_ENTRY(resID) {L"", resID},
  45. #define END_RES { NULL, 0 } };
  46. #define END_MENU \
  47. static MENUMAP menuMap = { dataRes, ctx }; \
  48. return &menuMap; }
  49. enum
  50. {
  51. // Identifiers for each of the commands to be inserted into the context menu.
  52. IDM_ABOUT,
  53. IDM_ADD_ENTRY,
  54. IDM_ADD_FILES,
  55. IDM_ADD_GROUPS,
  56. IDM_ADD_REGISTRY,
  57. IDM_ADD_LOC,
  58. IDM_ANALYZE,
  59. IDM_APPLY,
  60. IDM_CUT,
  61. IDM_COPY,
  62. IDM_DELETE,
  63. IDM_GENERATE,
  64. IDM_NEW,
  65. IDM_PASTE,
  66. IDM_REAPPLY,
  67. IDM_REFRESH,
  68. IDM_RELOAD,
  69. IDM_REMOVE,
  70. IDM_REVERT,
  71. IDM_SAVE,
  72. IDM_SAVEAS,
  73. IDM_SUMMARY,
  74. IDM_ADD_FOLDER,
  75. IDM_ADD_ANAL_FILES,
  76. IDM_ADD_ANAL_FOLDER,
  77. IDM_ADD_ANAL_KEY,
  78. IDM_ASSIGN,
  79. IDM_SET_DB,
  80. IDM_NEW_DATABASE,
  81. IDM_OPEN_SYSTEM_DB,
  82. IDM_OPEN_PRIVATE_DB,
  83. IDM_OBJECT_SECURITY,
  84. IDM_DESCRIBE_LOCATION,
  85. IDM_DESCRIBE_PROFILE,
  86. IDM_IMPORT_POLICY,
  87. IDM_IMPORT_LOCAL_POLICY,
  88. IDM_EXPORT_POLICY,
  89. IDM_EXPORT_LOCALPOLICY,
  90. IDM_EXPORT_EFFECTIVE,
  91. IDM_VIEW_LOGFILE,
  92. IDM_SECURE_WIZARD,
  93. IDM_WHAT_ISTHIS
  94. };
  95. static HINSTANCE g_hDsSecDll = NULL;
  96. DECLARE_MENU(CSecmgrNodeMenuHolder)
  97. DECLARE_MENU(CAnalyzeNodeMenuHolder)
  98. DECLARE_MENU(CConfigNodeMenuHolder)
  99. DECLARE_MENU(CLocationNodeMenuHolder)
  100. DECLARE_MENU(CRSOPProfileNodeMenuHolder)
  101. DECLARE_MENU(CSSProfileNodeMenuHolder)
  102. DECLARE_MENU(CLocalPolNodeMenuHolder)
  103. DECLARE_MENU(CProfileNodeMenuHolder)
  104. DECLARE_MENU(CProfileAreaMenuHolder)
  105. DECLARE_MENU(CProfileSubAreaMenuHolder)
  106. DECLARE_MENU(CProfileSubAreaEventLogMenuHolder)
  107. DECLARE_MENU(CAnalyzeAreaMenuHolder)
  108. DECLARE_MENU(CAnalyzeGroupsMenuHolder)
  109. DECLARE_MENU(CAnalyzeRegistryMenuHolder)
  110. DECLARE_MENU(CAnalyzeFilesMenuHolder)
  111. DECLARE_MENU(CProfileGroupsMenuHolder)
  112. DECLARE_MENU(CProfileRegistryMenuHolder)
  113. DECLARE_MENU(CProfileFilesMenuHolder)
  114. DECLARE_MENU(CAnalyzeObjectsMenuHolder)
  115. BOOL LoadContextMenuResources(MENUMAP* pMenuMap);
  116. #define UAV_RESULTITEM_ADD 0x0001
  117. #define UAV_RESULTITEM_REMOVE 0x0002
  118. #define UAV_RESULTITEM_UPDATE 0x0004
  119. #define UAV_RESULTITEM_UPDATEALL 0x0008
  120. #define UAV_RESULTITEM_REDRAWALL 0x0010
  121. class CFolder;
  122. typedef struct _tag_SCE_COLUMNINFO {
  123. int colID; // The column id.
  124. int nCols; // Number of columns
  125. int nWidth; // The width of the column
  126. } SCE_COLUMNINFO, *PSCE_COLUMNINFO;
  127. typedef struct _tag_SCE_COLINFOARRAY {
  128. int iIndex;
  129. int nCols;
  130. int nWidth[1];
  131. } SCE_COLINFOARRAY, *PSCE_COLINFOARRAY;
  132. /////////////////////////////////////////////////////////////////////////////
  133. // Snapin
  134. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  135. int AppMessageBox(HWND hWnd,
  136. LPCTSTR lpText,
  137. LPCTSTR lpCaption=NULL,
  138. UINT uType=MB_OK|MB_ICONEXCLAMATION,
  139. int iSnapin=0);
  140. class CComponentDataImpl:
  141. public IComponentData,
  142. public IExtendPropertySheet,
  143. public IExtendContextMenu,
  144. public IPersistStream,
  145. public ISceSvcAttachmentData,
  146. public ISnapinHelp2,
  147. public CComObjectRoot
  148. {
  149. BEGIN_COM_MAP(CComponentDataImpl)
  150. COM_INTERFACE_ENTRY(IComponentData)
  151. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  152. COM_INTERFACE_ENTRY(IExtendContextMenu)
  153. COM_INTERFACE_ENTRY(IPersistStream)
  154. COM_INTERFACE_ENTRY(ISceSvcAttachmentData)
  155. COM_INTERFACE_ENTRY(ISnapinHelp2)
  156. END_COM_MAP()
  157. friend class CSnapin;
  158. friend class CDataObject;
  159. CComponentDataImpl();
  160. virtual ~CComponentDataImpl();
  161. public:
  162. static DWORD m_GroupMode;
  163. virtual const CLSID& GetCoClassID() = 0; // for both primary and extension implementation
  164. virtual const int GetImplType() = 0; // for both primary and extension implementation
  165. // IComponentData interface members
  166. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  167. STDMETHOD(CreateComponent)(LPCOMPONENT* ppComponent);
  168. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  169. STDMETHOD(Destroy)();
  170. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  171. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM* pScopeDataItem);
  172. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  173. // IExtendPropertySheet interface
  174. public:
  175. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  176. LONG_PTR handle,
  177. LPDATAOBJECT lpIDataObject);
  178. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  179. // IExtendContextMenu
  180. public:
  181. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG* pInsertionAllowed);
  182. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  183. public:
  184. // IPersistStream interface members
  185. STDMETHOD(GetClassID)(CLSID *pClassID);
  186. STDMETHOD(IsDirty)();
  187. STDMETHOD(Load)(IStream *pStm);
  188. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  189. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  190. // ISceSvcAttachmentData
  191. STDMETHOD(GetData)(SCESVC_HANDLE sceHandle,
  192. SCESVC_INFO_TYPE sceType,
  193. PVOID *ppvData,
  194. PSCE_ENUMERATION_CONTEXT psceEnumHandle);
  195. STDMETHOD(Initialize)(LPCTSTR ServiceName,
  196. LPCTSTR TemplateName,
  197. LPSCESVCATTACHMENTPERSISTINFO lpSceSvcPersistInfo,
  198. SCESVC_HANDLE *sceHandle);
  199. STDMETHOD(FreeBuffer)(PVOID pvData);
  200. STDMETHOD(CloseHandle)(SCESVC_HANDLE sceHandle);
  201. // ISnapinHelp2 helper function
  202. STDMETHOD(GetHelpTopic)(LPOLESTR *lpCompiledHelpFile)=0;
  203. STDMETHOD(GetHelpTopic)(LPOLESTR *pszHelpFile,LPCTSTR szFile);
  204. STDMETHOD(GetLinkedTopics)(LPOLESTR* lpCompiledHelpFiles);
  205. // Notify handler declarations
  206. private:
  207. HRESULT OnAdd(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  208. HRESULT OnDelete(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  209. HRESULT OnRename(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  210. HRESULT OnExpand(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  211. HRESULT OnSelect(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  212. HRESULT OnContextMenu(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  213. HRESULT OnProperties(LPARAM param);
  214. HRESULT OnCopyArea(LPCTSTR szTemplate,FOLDER_TYPES ft);
  215. HRESULT OnPasteArea(LPCTSTR szTemplate,FOLDER_TYPES ft);
  216. HRESULT OnOpenDataBase();
  217. HRESULT OnNewDatabase();
  218. HRESULT OnAssignConfiguration( SCESTATUS *pSceStatus);
  219. HRESULT OnSecureWizard();
  220. HRESULT OnSaveConfiguration();
  221. HRESULT OnImportPolicy(LPDATAOBJECT);
  222. HRESULT OnImportLocalPolicy(LPDATAOBJECT);
  223. HRESULT OnExportPolicy(BOOL bEffective);
  224. HRESULT OnAnalyze();
  225. BOOL GetFolderCopyPasteInfo(FOLDER_TYPES Folder,AREA_INFORMATION *Area, UINT *cf);
  226. #if DBG==1
  227. public:
  228. ULONG InternalAddRef()
  229. {
  230. return CComObjectRoot::InternalAddRef();
  231. }
  232. ULONG InternalRelease()
  233. {
  234. return CComObjectRoot::InternalRelease();
  235. }
  236. #endif // DBG==1
  237. // Scope item creation helpers
  238. private:
  239. CFolder* FindObject(MMC_COOKIE cookie, POSITION* thePos );
  240. HRESULT CreateFolderList(CFolder* pFolder, FOLDER_TYPES type, POSITION *pPos, INT *Count);
  241. INT CComponentDataImpl::AddLocationsToFolderList(HKEY hkey, DWORD dwMode, BOOL bCheckForDupes, POSITION *pPos);
  242. BOOL AddTemplateLocation(CFolder *pParent, CString szName, BOOL bIsFileName, BOOL bRefresh);
  243. BOOL IsNameInChildrenScopes(CFolder* pParent, LPCTSTR NameStr, MMC_COOKIE *theCookie);
  244. CFolder* CreateAndAddOneNode(CFolder* pParent, LPCTSTR Name, LPCTSTR Desc,
  245. FOLDER_TYPES type, BOOL bChildren, LPCTSTR szInfFile = NULL,
  246. PVOID pData = NULL,DWORD status = 0);
  247. void DeleteChildrenUnderNode(CFolder* pParent);
  248. void DeleteThisNode(CFolder* pNode);
  249. HRESULT DeleteOneTemplateNodes(MMC_COOKIE cookie);
  250. void DeleteList();
  251. void EnumerateScopePane(MMC_COOKIE cookie, HSCOPEITEM pParent);
  252. BOOL IsScopePaneNode(LPDATAOBJECT lpDataObject);
  253. DWORD GetModeBits()
  254. {
  255. switch (m_Mode)
  256. {
  257. case SCE_MODE_DOMAIN_COMPUTER:
  258. case SCE_MODE_OU_COMPUTER:
  259. case SCE_MODE_LOCAL_COMPUTER:
  260. case SCE_MODE_REMOTE_COMPUTER:
  261. return m_computerModeBits;
  262. break;
  263. case SCE_MODE_REMOTE_USER:
  264. case SCE_MODE_LOCAL_USER:
  265. case SCE_MODE_DOMAIN_USER:
  266. case SCE_MODE_OU_USER:
  267. return m_userModeBits;
  268. break;
  269. default:
  270. return m_computerModeBits;
  271. break;
  272. }
  273. };
  274. public:
  275. PEDITTEMPLATE GetTemplate(LPCTSTR szInfFile,AREA_INFORMATION aiAirea = AREA_ALL, DWORD *idErr = NULL);
  276. BOOL RemovePolicyEntries(PEDITTEMPLATE pet);
  277. HRESULT ReloadLocation(CFolder *pFolder);
  278. void DeleteTemplate(CString infFile);
  279. static BOOL LoadResources();
  280. void LoadSadInfo(BOOL bRequireAnalysis);
  281. void UnloadSadInfo();
  282. void RefreshSadInfo(BOOL fRemoveAnalDlg = TRUE);
  283. BOOL GetSadLoaded() { return SadLoaded; };
  284. PVOID GetSadHandle() { return SadHandle; };
  285. BOOL GetSadTransStarted() { return SadTransStarted; };
  286. void SetSadTransStarted(BOOL bTrans) { SadTransStarted = bTrans; };
  287. BOOL EngineTransactionStarted();
  288. BOOL EngineCommitTransaction();
  289. BOOL EngineRollbackTransaction();
  290. HRESULT AddDsObjectsToList(LPDATAOBJECT lpDataObject, MMC_COOKIE cookie, FOLDER_TYPES folderType, LPTSTR InfFile);
  291. HRESULT AddAnalysisFilesToList(LPDATAOBJECT lpDataObject, MMC_COOKIE cookie, FOLDER_TYPES folderType);
  292. HRESULT AddAnalysisFolderToList(LPDATAOBJECT lpDataObject, MMC_COOKIE cookie, FOLDER_TYPES folderType);
  293. HRESULT UpdateScopeResultObject(LPDATAOBJECT pDataObj,MMC_COOKIE cookie, AREA_INFORMATION area);
  294. void AddPopupDialog(LONG_PTR nID, CDialog *pDlg);
  295. CDialog *GetPopupDialog(LONG_PTR nID);
  296. void RemovePopupDialog(LONG_PTR nID);
  297. CDialog *
  298. MatchNextPopupDialog(
  299. POSITION &pos,
  300. LONG_PTR priKey,
  301. LONG_PTR *thisPos
  302. );
  303. PSCE_COLINFOARRAY GetColumnInfo( FOLDER_TYPES pType );
  304. void SetColumnInfo( FOLDER_TYPES pType, PSCE_COLINFOARRAY pInfo);
  305. DWORD SerializeColumnInfo(IStream *pStm, ULONG *pTotalWrite, BOOL bRead);
  306. void CloseAnalysisPane();
  307. BOOL LockAnalysisPane(BOOL bLock, BOOL fRemoveAnalDlg = TRUE);
  308. HWND GetParentWindow() { return m_hwndParent; }
  309. LPNOTIFY GetNotifier() { return m_pNotifier; }
  310. DWORD UpdateObjectStatus( CFolder *pParent, BOOL bUpdateThis = FALSE );
  311. int
  312. RefreshAllFolders();
  313. public:
  314. //
  315. // Information functions.
  316. //
  317. CFolder *GetAnalFolder()
  318. { return m_AnalFolder; };
  319. LPCONSOLENAMESPACE GetNameSpace()
  320. { return m_pScope; };
  321. DWORD GetComponentMode()
  322. { return m_Mode; };
  323. LPCONSOLE GetConsole()
  324. { return m_pConsole; };
  325. CWMIRsop * GetWMIRsop() {
  326. if (!m_pWMIRsop) {
  327. m_pWMIRsop = new CWMIRsop(m_pRSOPInfo);
  328. }
  329. return m_pWMIRsop;
  330. }
  331. void
  332. SetErroredLogFile( LPCTSTR pszFileName, LONG dwPosLow = 0);
  333. LPCTSTR GetErroredLogFile( LONG *dwPosLow = NULL)
  334. { if(dwPosLow) *dwPosLow = m_ErroredLogPos; return m_pszErroredLogFile; };
  335. void SetFlags( DWORD dwFlags, DWORD dwMask = -1)
  336. { m_dwFlags = dwFlags | (dwMask & m_dwFlags); };
  337. public:
  338. //
  339. // UI add function helpers
  340. //
  341. HRESULT
  342. GetAddObjectSecurity( // Gets valid object security settings
  343. HWND hwndParent,
  344. LPCTSTR strFile,
  345. BOOL bContainer,
  346. SE_OBJECT_TYPE SeType,
  347. PSECURITY_DESCRIPTOR &pSelSD,
  348. SECURITY_INFORMATION &SelSeInfo,
  349. BYTE &ConfigStatus
  350. );
  351. BOOL GetWorkingDir(
  352. GWD_TYPES uIDDir,
  353. LPTSTR *pStr,
  354. BOOL bSet = FALSE,
  355. BOOL bFile = FALSE
  356. );
  357. public:
  358. DWORD GetGroupMode();
  359. enum {
  360. flag_showLogFile = 0x00000001
  361. };
  362. LPRSOPINFORMATION m_pRSOPInfo;
  363. private:
  364. bool m_bEnumerateScopePaneCalled;
  365. LPCONSOLENAMESPACE m_pScope; // My interface pointer to the scope pane
  366. LPCONSOLE m_pConsole;
  367. BOOL m_bIsDirty;
  368. BOOL m_bIsLocked;
  369. CString SadName;
  370. CString SadDescription;
  371. CString SadAnalyzeStamp;
  372. CString SadConfigStamp;
  373. BOOL SadLoaded;
  374. SCESTATUS SadErrored;
  375. PVOID SadHandle;
  376. BOOL SadTransStarted;
  377. DWORD m_nNewTemplateIndex;
  378. DWORD m_Mode; // The Mode we are in
  379. DWORD m_computerModeBits; // Bits describing functionality changes in this mode
  380. DWORD m_userModeBits; // Bits describing functionality changes in this mode
  381. // The name of the template file for MB_SINGLE_TEMPLATE_ONLY modes
  382. LPTSTR m_szSingleTemplateName;
  383. BOOL m_bDeleteSingleTemplate; // True if we need to delete the template on exit
  384. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  385. void ClearDirty() { m_bIsDirty = FALSE; }
  386. BOOL ThisIsDirty() { return m_bIsDirty; }
  387. void AddScopeItemToResultPane(MMC_COOKIE cookie);
  388. HRESULT AddAttrPropPages(LPPROPERTYSHEETCALLBACK lpProvider,CFolder *pFolder,LONG_PTR handle);
  389. BOOL m_bComputerTemplateDirty;
  390. CMap<CString, LPCTSTR, PEDITTEMPLATE, PEDITTEMPLATE&> m_Templates;
  391. BOOL m_fSvcNotReady;
  392. HWND m_hwndParent;
  393. CHiddenWnd *m_pNotifier;
  394. CFolder * m_AnalFolder;
  395. CFolder * m_ConfigFolder;
  396. CList<CFolder*, CFolder*> m_scopeItemList;
  397. CMap<LONG_PTR, LONG_PTR, CDialog *, CDialog *&> m_scopeItemPopups;
  398. LPGPEINFORMATION m_pGPTInfo;
  399. CWinThread *m_pUIThread; // The thread that creates dialog boxes for this component data item
  400. CString m_strDisplay; // The static display string used for GetDisplayInfo
  401. CString m_strTempFile; // The temporary file name to delete for HTML error pages
  402. LPTSTR m_pszErroredLogFile; // Error log.
  403. LONG m_ErroredLogPos; // The last write position of the error log file.
  404. DWORD m_dwFlags;
  405. CMap<FOLDER_TYPES, FOLDER_TYPES, PSCE_COLINFOARRAY, PSCE_COLINFOARRAY&> m_mapColumns;
  406. CMap<UINT, UINT, LPTSTR, LPTSTR&> m_aDirs;
  407. CWMIRsop *m_pWMIRsop;
  408. CRITICAL_SECTION csAnalysisPane;
  409. BOOL m_bCriticalSet;
  410. };
  411. //
  412. // define classes for differnt class IDs
  413. //
  414. #define SCE_IMPL_TYPE_EXTENSION 1
  415. #define SCE_IMPL_TYPE_SCE 2
  416. #define SCE_IMPL_TYPE_SAV 3
  417. #define SCE_IMPL_TYPE_LS 4
  418. #define SCE_IMPL_TYPE_RSOP 4
  419. // extension snapin implementation
  420. class CComponentDataExtensionImpl : public CComponentDataImpl,
  421. // public ISnapinHelp,
  422. public CComCoClass<CComponentDataExtensionImpl, &CLSID_Snapin>
  423. {
  424. //BEGIN_COM_MAP(CComponentDataExtensionImpl)
  425. // COM_INTERFACE_ENTRY(ISnapinHelp)
  426. //END_COM_MAP()
  427. public:
  428. DECLARE_REGISTRY(CSnapin, _T("Wsecedit.Extension.1"), _T("Wsecedit.Extension"), IDS_EXTENSION_DESC, THREADFLAGS_BOTH)
  429. virtual const CLSID & GetCoClassID() { return CLSID_Snapin; }
  430. virtual const int GetImplType() { return SCE_IMPL_TYPE_EXTENSION; }
  431. // ISnapinHelp2
  432. STDMETHOD(GetHelpTopic)(LPOLESTR *pszHelpFile);
  433. };
  434. // RSOP extension snapin implementation
  435. class CComponentDataRSOPImpl : public CComponentDataImpl,
  436. public CComCoClass<CComponentDataRSOPImpl, &CLSID_RSOPSnapin>
  437. {
  438. //BEGIN_COM_MAP(CComponentDataRSOPImpl)
  439. // COM_INTERFACE_ENTRY(ISnapinHelp)
  440. //END_COM_MAP()
  441. public:
  442. DECLARE_REGISTRY(CSnapin, _T("Wsecedit.RSOP.1"), _T("Wsecedit.RSOP"), IDS_RSOP_DESC, THREADFLAGS_BOTH)
  443. virtual const CLSID & GetCoClassID() { return CLSID_RSOPSnapin; }
  444. virtual const int GetImplType() { return SCE_IMPL_TYPE_RSOP; }
  445. // ISnapinHelp2
  446. STDMETHOD(GetHelpTopic)(LPOLESTR *pszHelpFile);
  447. };
  448. // SCE standalone snapin implementation
  449. class CComponentDataSCEImpl : public CComponentDataImpl,
  450. public CComCoClass<CComponentDataSCEImpl, &CLSID_SCESnapin>
  451. {
  452. //BEGIN_COM_MAP(CComponentDataSCEImpl)
  453. // COM_INTERFACE_ENTRY(ISnapinHelp)
  454. //END_COM_MAP()
  455. public:
  456. DECLARE_REGISTRY(CSnapin, _T("Wsecedit.SCE.1"), _T("Wsecedit.SCE"), IDS_SCE_DESC, THREADFLAGS_BOTH)
  457. virtual const CLSID & GetCoClassID() { return CLSID_SCESnapin; }
  458. virtual const int GetImplType() { return SCE_IMPL_TYPE_SCE; }
  459. // ISnapinHelp2
  460. STDMETHOD(GetHelpTopic)(LPOLESTR *pszHelpFile);
  461. };
  462. // SAV standalone snapin implementation
  463. class CComponentDataSAVImpl : public CComponentDataImpl,
  464. public CComCoClass<CComponentDataSAVImpl, &CLSID_SAVSnapin>
  465. {
  466. //BEGIN_COM_MAP(CComponentDataSAVImpl)
  467. // COM_INTERFACE_ENTRY(ISnapinHelp)
  468. //END_COM_MAP()
  469. public:
  470. DECLARE_REGISTRY(CSnapin, _T("Wsecedit.SAV.1"), _T("Wsecedit.SAV"), IDS_SAV_DESC, THREADFLAGS_BOTH)
  471. virtual const CLSID & GetCoClassID() { return CLSID_SAVSnapin; }
  472. virtual const int GetImplType() { return SCE_IMPL_TYPE_SAV; }
  473. // ISnapinHelp2
  474. STDMETHOD(GetHelpTopic)(LPOLESTR *pszHelpFile);
  475. };
  476. // LS standalone snapin implementation
  477. class CComponentDataLSImpl : public CComponentDataImpl,
  478. public CComCoClass<CComponentDataLSImpl, &CLSID_LSSnapin>
  479. {
  480. //BEGIN_COM_MAP(CComponentDataLSImpl)
  481. // COM_INTERFACE_ENTRY(ISnapinHelp)
  482. //END_COM_MAP()
  483. public:
  484. DECLARE_REGISTRY(CSnapin, _T("Wsecedit.LS.1"), _T("Wsecedit.LS"), IDS_LS_DESC, THREADFLAGS_BOTH)
  485. virtual const CLSID & GetCoClassID() { return CLSID_LSSnapin; }
  486. virtual const int GetImplType() { return SCE_IMPL_TYPE_LS; }
  487. // ISnapinHelp2
  488. STDMETHOD(GetHelpTopic)(LPOLESTR *pszHelpFile);
  489. };
  490. class CSnapin :
  491. public IComponent,
  492. public IExtendContextMenu, // Step 3
  493. public IExtendPropertySheet,
  494. public IExtendControlbar,
  495. public IResultDataCompare,
  496. public CComObjectRoot
  497. {
  498. public:
  499. CSnapin();
  500. virtual ~CSnapin();
  501. BEGIN_COM_MAP(CSnapin)
  502. COM_INTERFACE_ENTRY(IComponent)
  503. COM_INTERFACE_ENTRY(IExtendContextMenu)
  504. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  505. COM_INTERFACE_ENTRY(IExtendControlbar)
  506. COM_INTERFACE_ENTRY(IResultDataCompare)
  507. END_COM_MAP()
  508. friend class CDataObject;
  509. friend class CComponentDataImpl;
  510. static long lDataObjectRefCount;
  511. static CList<CResult*, CResult*> m_PropertyPageList;
  512. // IComponent interface members
  513. public:
  514. STDMETHOD(Initialize)(LPCONSOLE lpConsole);
  515. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  516. STDMETHOD(Destroy)(MMC_COOKIE cookie);
  517. STDMETHOD(GetResultViewType)(MMC_COOKIE cookie, LPOLESTR* ppViewType, LONG* pViewOptions);
  518. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  519. LPDATAOBJECT* ppDataObject);
  520. STDMETHOD(GetDisplayInfo)(RESULTDATAITEM* pResultDataItem);
  521. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  522. // IResultDataCompare
  523. STDMETHOD(Compare)(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult);
  524. // IExtendControlbar
  525. STDMETHOD(SetControlbar)(LPCONTROLBAR pControlbar);
  526. STDMETHOD(ControlbarNotify)(MMC_NOTIFY_TYPE event, MMC_COOKIE arg, MMC_COOKIE param);
  527. // Helpers for CSnapin
  528. public:
  529. void SetIComponentData(CComponentDataImpl* pData);
  530. int GetImplType()
  531. {
  532. CComponentDataImpl *pData =
  533. dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  534. ASSERT(pData != NULL);
  535. if (pData != NULL)
  536. return pData->GetImplType();
  537. return 0;
  538. }
  539. #if DBG==1
  540. public:
  541. int dbg_cRef;
  542. ULONG InternalAddRef()
  543. {
  544. ++dbg_cRef;
  545. return CComObjectRoot::InternalAddRef();
  546. }
  547. ULONG InternalRelease()
  548. {
  549. --dbg_cRef;
  550. return CComObjectRoot::InternalRelease();
  551. }
  552. #endif // DBG==1
  553. // Notify event handlers
  554. protected:
  555. HRESULT OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  556. HRESULT OnShow(LPDATAOBJECT pDataObj, MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  557. HRESULT OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  558. HRESULT OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  559. HRESULT OnPropertyChange(LPDATAOBJECT lpDataObject); // Step 3
  560. HRESULT OnUpdateView(LPDATAOBJECT lpDataObject,LPARAM data, LPARAM hint);
  561. HRESULT OnDeleteObjects(LPDATAOBJECT lpDataObject,DATA_OBJECT_TYPES cctType, MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  562. // IExtendContextMenu
  563. public:
  564. PEDITTEMPLATE GetTemplate(LPCTSTR szInfFile, AREA_INFORMATION aiArea = AREA_ALL,DWORD *idErr = NULL);
  565. PSCE_PROFILE_INFO GetBaseInfo(PSCE_PROFILE_INFO *pBaseInfo, DWORD dwArea, PSCE_ERROR_LOG_INFO *ErrBuf =NULL );
  566. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG* pInsertionAllowed);
  567. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  568. // IExtendPropertySheet interface
  569. public:
  570. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  571. LONG_PTR handle,
  572. LPDATAOBJECT lpIDataObject);
  573. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  574. // Helper functions
  575. protected:
  576. CResult* FindResult(MMC_COOKIE cookie, POSITION* thePos);
  577. void Construct();
  578. void LoadResources();
  579. HRESULT InitializeHeaders(MMC_COOKIE cookie);
  580. void EnumerateResultPane(MMC_COOKIE cookie, HSCOPEITEM pParent, LPDATAOBJECT pDataObj);
  581. void CreateProfileResultList(MMC_COOKIE cookie, FOLDER_TYPES type, PEDITTEMPLATE pSceInfo,LPDATAOBJECT pDataObj);
  582. void CreateAnalysisResultList(MMC_COOKIE cookie, FOLDER_TYPES type,
  583. PEDITTEMPLATE pSceInfo, PEDITTEMPLATE pBase,LPDATAOBJECT pDataObj);
  584. void CreateLocalPolicyResultList(MMC_COOKIE cookie, FOLDER_TYPES type,
  585. PEDITTEMPLATE pLocal, PEDITTEMPLATE pEffective,LPDATAOBJECT pDataObj);
  586. void CreateObjectResultList(MMC_COOKIE cookie, FOLDER_TYPES type, AREA_INFORMATION Area,
  587. PSCE_OBJECT_CHILDREN pObjList, PVOID pHandle,
  588. LPDATAOBJECT pDataObj );
  589. void CreateProfServiceResultList(MMC_COOKIE cookie, FOLDER_TYPES type, PEDITTEMPLATE pSceInfo,LPDATAOBJECT pDataObj);
  590. void CreateAnalysisServiceResultList(MMC_COOKIE cookie, FOLDER_TYPES type,
  591. PEDITTEMPLATE pSceInfo, PEDITTEMPLATE pBase,
  592. LPDATAOBJECT pDataObj );
  593. void DeleteServiceResultList(MMC_COOKIE);
  594. HRESULT EditThisService(CResult *pData, MMC_COOKIE cookie, RESULT_TYPES rsltType, HWND hwndParent);
  595. HRESULT GetDisplayInfoForServiceNode(RESULTDATAITEM *pResult, CFolder *pFolder, CResult *pData);
  596. void DeleteList(BOOL bDeleteResultItem);
  597. void CreateProfilePolicyResultList(MMC_COOKIE cookie, FOLDER_TYPES type, PEDITTEMPLATE pSceInfo,LPDATAOBJECT pDataObj);
  598. void CreateAnalysisPolicyResultList(MMC_COOKIE cookie, FOLDER_TYPES type,
  599. PEDITTEMPLATE pSceInfo, PEDITTEMPLATE pBase,LPDATAOBJECT pDataObj );
  600. void CreateProfileRegValueList(MMC_COOKIE cookie, PEDITTEMPLATE pSceInfo,LPDATAOBJECT pDataObj );
  601. void CreateAnalysisRegValueList(MMC_COOKIE cookie, PEDITTEMPLATE pSceInfo, PEDITTEMPLATE pBase,LPDATAOBJECT pDataObj,RESULT_TYPES type );
  602. HRESULT EditThisRegistryValue(CResult *pData, MMC_COOKIE cookie, RESULT_TYPES rsltType);
  603. HRESULT AddAttrPropPages(LPPROPERTYSHEETCALLBACK lpProvider,CResult *pResult,LONG_PTR handle);
  604. // Result pane helpers
  605. public:
  606. void SetupLinkServiceNodeToBase(BOOL bAdd, LONG_PTR theNode);
  607. void AddServiceNodeToProfile(PSCE_SERVICES pNode);
  608. int SetAnalysisInfo(ULONG_PTR dwItem, ULONG_PTR dwNew, CResult *pResult = NULL);
  609. int SetLocalPolInfo(ULONG_PTR dwItem, ULONG_PTR dwNew);
  610. void TransferAnalysisName(LONG_PTR dwItem);
  611. BOOL UpdateLocalPolRegValue( CResult * );
  612. LPTSTR GetAnalTimeStamp();
  613. CResult * AddResultItem(LPCTSTR Attrib, LONG_PTR setting, LONG_PTR base,
  614. RESULT_TYPES type, int status,MMC_COOKIE cookie,
  615. BOOL bVerify = FALSE, LPCTSTR unit = NULL, LONG_PTR nID = -1,
  616. PEDITTEMPLATE pBaseInfo = NULL,
  617. LPDATAOBJECT pDataObj = NULL,
  618. CResult *pResult = NULL,
  619. long hID = 0);
  620. CResult * AddResultItem(UINT rID, LONG_PTR setting, LONG_PTR base,
  621. RESULT_TYPES type, int status, MMC_COOKIE cookie,
  622. BOOL bVerify = FALSE, PEDITTEMPLATE pBaseInfo = NULL,
  623. LPDATAOBJECT pDataObj = NULL, long hID = 0);
  624. void AddResultItem(LPCTSTR szName,PSCE_GROUP_MEMBERSHIP grpTemplate,
  625. PSCE_GROUP_MEMBERSHIP grpInspect,MMC_COOKIE cookie,
  626. LPDATAOBJECT pDataObj);
  627. HRESULT InitializeBitmaps(MMC_COOKIE cookie);
  628. HWND GetParentWindow() { return m_hwndParent; }
  629. BOOL CheckEngineTransaction();
  630. // UI Helpers
  631. void HandleStandardVerbs(LPARAM arg, LPDATAOBJECT lpDataObject);
  632. void GetHelpTopic(long itemID, CString& helpTopic);
  633. public:
  634. LPCONSOLE
  635. GetConsole()
  636. { return m_pConsole; };
  637. DWORD
  638. UpdateAnalysisInfo( // Effects priviledge areas only.
  639. CResult *pResult,
  640. BOOL bDelete,
  641. PSCE_PRIVILEGE_ASSIGNMENT *pInfo,
  642. LPCTSTR pszName = NULL
  643. );
  644. DWORD
  645. UpdateLocalPolInfo( // Effects priviledge areas only.
  646. CResult *pResult,
  647. BOOL bDelete,
  648. PSCE_PRIVILEGE_ASSIGNMENT *pInfo,
  649. LPCTSTR pszName = NULL
  650. );
  651. DWORD
  652. GetResultItemIDs(
  653. CResult *pResult,
  654. HRESULTITEM *pIDArray,
  655. int nIDArray
  656. );
  657. LPRESULTDATA
  658. GetResultPane()
  659. { return m_pResult; };
  660. CFolder* GetSelectedFolder()
  661. {
  662. return m_pSelectedFolder;
  663. };
  664. DWORD GetModeBits()
  665. {
  666. switch (((CComponentDataImpl *)m_pComponentData)->m_Mode)
  667. {
  668. case SCE_MODE_DOMAIN_COMPUTER:
  669. case SCE_MODE_OU_COMPUTER:
  670. case SCE_MODE_LOCAL_COMPUTER:
  671. case SCE_MODE_REMOTE_COMPUTER:
  672. return ((CComponentDataImpl *)m_pComponentData)->m_computerModeBits;
  673. break;
  674. case SCE_MODE_REMOTE_USER:
  675. case SCE_MODE_LOCAL_USER:
  676. case SCE_MODE_DOMAIN_USER:
  677. case SCE_MODE_OU_USER:
  678. return ((CComponentDataImpl *)m_pComponentData)->m_userModeBits;
  679. break;
  680. default:
  681. return ((CComponentDataImpl *)m_pComponentData)->m_computerModeBits;
  682. break;
  683. }
  684. }
  685. CWMIRsop* GetWMIRsop()
  686. {
  687. return ((CComponentDataImpl *)m_pComponentData)->GetWMIRsop();
  688. }
  689. LPCONSOLEVERB GetConsoleVerb() {return m_pConsoleVerb;};
  690. void AddPropertyPageRef(CResult* pData);
  691. void ReleasePropertyPage(CResult* pData);
  692. long GetUserRightAssignmentItemID(LPCWSTR szItem);
  693. // Interface pointers
  694. protected:
  695. LPCONSOLE m_pConsole; // Console's IFrame interface
  696. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  697. LPCOMPONENTDATA m_pComponentData;
  698. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  699. LPIMAGELIST m_pImageResult; // My interface pointer to the result pane image list
  700. LPTOOLBAR m_pToolbar1; // Toolbar for view
  701. LPTOOLBAR m_pToolbar2; // Toolbar for view
  702. LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  703. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  704. LPTSTR m_szAnalTimeStamp;
  705. CBitmap* m_pbmpToolbar1; // Imagelist for the first toolbar
  706. CBitmap* m_pbmpToolbar2; // Imagelist for the first toolbar
  707. // Header titles for each nodetype(s)
  708. protected:
  709. CString m_multistrDisplay;
  710. CString m_colName; // Name
  711. CString m_colDesc; // Description
  712. CString m_colAttr; // Attribute
  713. CString m_colBaseAnalysis; // Baseline setting for Analysis
  714. CString m_colBaseTemplate; // Baseline setting for Template
  715. CString m_colLocalPol; // Local policy setting
  716. CString m_colSetting; // Current Setting
  717. // result data
  718. private:
  719. HINSTANCE hinstAclUI;
  720. //CList<CResult*, CResult*> m_resultItemList;
  721. CMap<LONG_PTR, LONG_PTR, CAttribute *, CAttribute *&> m_resultItemPopups;
  722. CMap<LONG_PTR, LONG_PTR, CPropertySheet *, CPropertySheet *&> m_resultItemPropSheets;
  723. MMC_COOKIE m_ShowCookie;
  724. CWinThread *m_pUIThread;
  725. HWND m_hwndParent;
  726. CHiddenWnd *m_pNotifier;
  727. HANDLE m_resultItemHandle;
  728. CFolder *m_pSelectedFolder;
  729. CString m_strDisplay;
  730. int m_nColumns;
  731. };
  732. inline void CSnapin::SetIComponentData(CComponentDataImpl* pData)
  733. {
  734. ASSERT(pData); //Validate pData and m_pComponentData.
  735. ASSERT(m_pComponentData == NULL);
  736. if( !pData ) //Raid #550912, yanggao.
  737. {
  738. return;
  739. }
  740. LPUNKNOWN pUnk = pData->GetUnknown();
  741. HRESULT hr;
  742. hr = pUnk->QueryInterface(IID_IComponentData, reinterpret_cast<void**>(&m_pComponentData));
  743. ASSERT(hr == S_OK);
  744. }
  745. #define FREE_INTERNAL(pInternal) \
  746. ASSERT(pInternal != NULL); \
  747. do { if (pInternal != NULL) \
  748. GlobalFree(pInternal); } \
  749. while(0);
  750. void ConvertNameListToString(PSCE_NAME_LIST pList, LPTSTR *sz, BOOL fReverse=FALSE);
  751. int GetScopeImageIndex( FOLDER_TYPES type, DWORD status = -1 );
  752. int GetResultImageIndex( CFolder* pFolder, CResult* pResult );
  753. // Cliboard Types
  754. // Policy Area includes the Privileges Area
  755. #define CF_SCE_ACCOUNT_AREA TEXT("CF_SCE_ACCOUNT_AREA")
  756. #define CF_SCE_EVENTLOG_AREA TEXT("CF_SCE_EVENTLOG_AREA")
  757. #define CF_SCE_LOCAL_AREA TEXT("CF_SCE_LOCAL_AREA")
  758. #define CF_SCE_GROUPS_AREA TEXT("CF_SCE_GROUPS_AREA")
  759. #define CF_SCE_REGISTRY_AREA TEXT("CF_SCE_REGISTRY_AREA")
  760. #define CF_SCE_FILE_AREA TEXT("CF_SCE_FILE_AREA")
  761. #define CF_SCE_SERVICE_AREA TEXT("CF_SCE_SERVICE_AREA")
  762. extern UINT cfSceAccountArea; // in snapmgr.cpp
  763. extern UINT cfSceEventLogArea; // in snapmgr.cpp
  764. extern UINT cfSceLocalArea; // in snapmgr.cpp
  765. extern UINT cfSceGroupsArea; // in snapmgr.cpp
  766. extern UINT cfSceRegistryArea; // in snapmgr.cpp
  767. extern UINT cfSceFileArea; // in snapmgr.cpp
  768. extern UINT cfSceServiceArea; // in snapmgr.cpp
  769. extern SCE_COLUMNINFO g_columnInfo[]; // Default column information.
  770. #define MB_NO_NATIVE_NODES 0x00000001
  771. #define MB_SINGLE_TEMPLATE_ONLY 0x00000002
  772. #define MB_DS_OBJECTS_SECTION 0x00000004
  773. #define MB_NO_TEMPLATE_VERBS 0x00000008
  774. #define MB_STANDALONE_NAME 0x00000010
  775. #define MB_WRITE_THROUGH 0x00000020
  776. #define MB_ANALYSIS_VIEWER 0x00000040
  777. #define MB_TEMPLATE_EDITOR 0x00000080
  778. #define MB_LOCAL_POLICY 0x00000100
  779. #define MB_GROUP_POLICY 0x00000200
  780. #define MB_LOCALSEC 0x00000400
  781. #define MB_READ_ONLY 0x00000800
  782. #define MB_RSOP 0x00001000
  783. #define GT_COMPUTER_TEMPLATE (TEXT("[[ Computer Template (not for display) ]]"))
  784. #define GT_LAST_INSPECTION (TEXT("[[ Last Inspected Template (not for display) ]]"))
  785. #define GT_LOCAL_POLICY (TEXT("[[ Local Policy Template (not for display) ]]"))
  786. #define GT_LOCAL_POLICY_DELTA (TEXT("[[ Local Policy Template Changes (not for display) ]]"))
  787. #define GT_EFFECTIVE_POLICY (TEXT("[[ Effective Policy Template (not for display) ]]"))
  788. #define GT_DEFAULT_TEMPLATE (TEXT("[[ Default Template (not for display) ]]"))
  789. #define GT_RSOP_TEMPLATE (TEXT("[[ RSOP Template (not for display) ]]"))
  790. #define SCE_REGISTRY_KEY TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\SeCEdit")
  791. #define SCE_REGISTRY_DEFAULT_TEMPLATE TEXT("DefaultTemplate")
  792. #define DEFAULT_LOCATIONS_KEY SCE_REGISTRY_KEY TEXT("\\DefaultLocations")
  793. #define CONFIGURE_LOG_LOCATIONS_KEY TEXT("ConfigureLog")
  794. #define ANALYSIS_LOG_LOCATIONS_KEY TEXT("AnalysisLog")
  795. #define OPEN_DATABASE_LOCATIONS_KEY TEXT("Database")
  796. #define IMPORT_TEMPLATE_LOCATIONS_KEY TEXT("ImportTemplate")
  797. #define EXPORT_TEMPLATE_LOCATIONS_KEY TEXT("ExportTemplate")
  798. #endif // !WSECMGR_SNAPMGR_H