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.

636 lines
20 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1997.
  5. //
  6. // File: rsoproot.h
  7. //
  8. // Contents: Definitions for the RSOP Snap-In classes
  9. //
  10. // Classes: CRSOPComponentData - Root RSOP snap-in node
  11. // CRSOPComponentDataCF - class factory for RSOPComponentData
  12. //
  13. // Functions:
  14. //
  15. // History: 09-13-1999 stevebl Created
  16. //
  17. //---------------------------------------------------------------------------
  18. #include "RSOPQuery.h"
  19. //
  20. // RSOP gpo list data structure
  21. //
  22. typedef struct tagGPOLISTITEM {
  23. LPTSTR lpGPOName;
  24. LPTSTR lpDSPath;
  25. LPTSTR lpSOM;
  26. LPTSTR lpUnescapedSOM;
  27. LPTSTR lpFiltering;
  28. LPBYTE pSD;
  29. DWORD dwVersion;
  30. BOOL bApplied;
  31. struct tagGPOLISTITEM * pNext;
  32. } GPOLISTITEM, *LPGPOLISTITEM;
  33. //
  34. // RSOP CSE data structure
  35. //
  36. typedef struct tagCSEITEM {
  37. LPTSTR lpName;
  38. LPTSTR lpGUID;
  39. DWORD dwStatus;
  40. ULONG ulLoggingStatus;
  41. SYSTEMTIME BeginTime;
  42. SYSTEMTIME EndTime;
  43. BOOL bUser;
  44. LPSOURCEENTRY lpEventSources;
  45. struct tagCSEITEM *pNext;
  46. } CSEITEM, *LPCSEITEM;
  47. //
  48. // CRSOPGPOLists class
  49. //
  50. class CRSOPGPOLists
  51. {
  52. public:
  53. CRSOPGPOLists()
  54. {
  55. m_pUserGPOList = NULL;
  56. m_pComputerGPOList = NULL;
  57. }
  58. ~CRSOPGPOLists()
  59. {
  60. if ( m_pUserGPOList != NULL )
  61. {
  62. FreeGPOListData( m_pUserGPOList );
  63. m_pUserGPOList = NULL;
  64. }
  65. if ( m_pComputerGPOList != NULL )
  66. {
  67. FreeGPOListData( m_pComputerGPOList );
  68. m_pComputerGPOList = NULL;
  69. }
  70. }
  71. void Build( LPTSTR szWMINameSpace );
  72. LPGPOLISTITEM GetUserList()
  73. { return m_pUserGPOList; }
  74. LPGPOLISTITEM GetComputerList()
  75. { return m_pComputerGPOList; }
  76. private:
  77. static void FreeGPOListData(LPGPOLISTITEM lpList);
  78. static void BuildGPOList (LPGPOLISTITEM * lpList, LPTSTR lpNamespace);
  79. static BOOL AddGPOListNode(LPTSTR lpGPOName, LPTSTR lpDSPath, LPTSTR lpSOM, LPTSTR lpFiltering,
  80. DWORD dwVersion, BOOL bFiltering, LPBYTE pSD, DWORD dwSDSize,
  81. LPGPOLISTITEM *lpList);
  82. private:
  83. LPGPOLISTITEM m_pUserGPOList;
  84. LPGPOLISTITEM m_pComputerGPOList;
  85. };
  86. //
  87. // CRSOPCSELists class
  88. //
  89. class CRSOPCSELists
  90. {
  91. public:
  92. CRSOPCSELists( const BOOL& bViewIsArchivedData )
  93. : m_bViewIsArchivedData( bViewIsArchivedData )
  94. {
  95. m_bNoQuery = FALSE;
  96. m_szTargetMachine = NULL;
  97. m_pUserCSEList = NULL;
  98. m_pComputerCSEList = NULL;
  99. m_bUserCSEError = FALSE;
  100. m_bComputerCSEError = FALSE;
  101. m_bUserGPCoreError = FALSE;
  102. m_bComputerGPCoreError = FALSE;
  103. m_bUserGPCoreWarning = FALSE;
  104. m_bComputerGPCoreWarning = FALSE;
  105. m_pEvents = new CEvents;
  106. }
  107. ~CRSOPCSELists()
  108. {
  109. if ( m_pEvents != NULL )
  110. {
  111. delete m_pEvents;
  112. m_pEvents = NULL;
  113. }
  114. if ( m_pUserCSEList != NULL )
  115. {
  116. FreeCSEData( m_pUserCSEList );
  117. m_pUserCSEList = NULL;
  118. }
  119. if ( m_pComputerCSEList != NULL )
  120. {
  121. FreeCSEData( m_pComputerCSEList );
  122. m_pComputerCSEList = NULL;
  123. }
  124. }
  125. void Build( LPRSOP_QUERY pQuery, LPTSTR szWMINameSpace, BOOL bGetEventLogErrors );
  126. public:
  127. LPCSEITEM GetUserList()
  128. { return m_pUserCSEList; }
  129. LPCSEITEM GetComputerList()
  130. { return m_pComputerCSEList; }
  131. BOOL GetUserCSEError()
  132. { return m_bUserCSEError; }
  133. BOOL GetComputerCSEError()
  134. { return m_bComputerCSEError; }
  135. BOOL GetUserGPCoreError()
  136. { return m_bUserGPCoreError; }
  137. BOOL GetComputerGPCoreError()
  138. { return m_bComputerGPCoreError; }
  139. BOOL GetUserGPCoreWarning()
  140. { return m_bUserGPCoreWarning; }
  141. BOOL GetComputerGPCoreWarning()
  142. { return m_bComputerGPCoreWarning; }
  143. CEvents* GetEvents()
  144. { return m_pEvents; }
  145. private:
  146. void BuildCSEList( LPRSOP_QUERY pQuery, LPCSEITEM * lpList, LPTSTR lpNamespace, BOOL bUser, BOOL *bCSEError, BOOL *bGPCoreError );
  147. void FreeCSEData( LPCSEITEM lpList );
  148. static BOOL AddCSENode( LPTSTR lpName, LPTSTR lpGUID, DWORD dwStatus,
  149. ULONG ulLoggingStatus, SYSTEMTIME *pBeginTime, SYSTEMTIME *pEndTime, BOOL bUser,
  150. LPCSEITEM *lpList, BOOL *bCSEError, BOOL *bGPCoreError, LPSOURCEENTRY lpSources );
  151. void GetEventLogSources( IWbemServices * pNamespace,
  152. LPTSTR lpCSEGUID, LPTSTR lpComputerName,
  153. SYSTEMTIME *BeginTime, SYSTEMTIME *EndTime,
  154. LPSOURCEENTRY *lpSources );
  155. void QueryRSoPPolicySettingStatusInstances( LPTSTR lpNamespace );
  156. private:
  157. const BOOL& m_bViewIsArchivedData;
  158. BOOL m_bNoQuery;
  159. LPTSTR m_szTargetMachine;
  160. // CSE data
  161. LPCSEITEM m_pUserCSEList;
  162. LPCSEITEM m_pComputerCSEList;
  163. BOOL m_bUserCSEError;
  164. BOOL m_bComputerCSEError;
  165. BOOL m_bUserGPCoreError;
  166. BOOL m_bComputerGPCoreError;
  167. BOOL m_bUserGPCoreWarning;
  168. BOOL m_bComputerGPCoreWarning;
  169. // Event log data
  170. CEvents* m_pEvents;
  171. };
  172. //
  173. // CRSOPComponentData class
  174. //
  175. class CRSOPComponentData:
  176. public IComponentData,
  177. public IExtendPropertySheet2,
  178. public IExtendContextMenu,
  179. public IPersistStreamInit,
  180. public ISnapinHelp
  181. {
  182. protected:
  183. BOOL m_bPostXPBuild;
  184. ULONG m_cRef;
  185. HWND m_hwndFrame;
  186. BOOL m_bOverride; // RM: Overrides the loading of a .MSC file and uses commandline parameters instead (integration with DSA)
  187. BOOL m_bRefocusInit;
  188. BOOL m_bArchiveData;
  189. BOOL m_bViewIsArchivedData;
  190. TCHAR m_szArchivedDataGuid[50];
  191. LPCONSOLENAMESPACE2 m_pScope;
  192. LPCONSOLE m_pConsole;
  193. HSCOPEITEM m_hRoot;
  194. HSCOPEITEM m_hMachine;
  195. HSCOPEITEM m_hUser;
  196. BOOL m_bRootExpanded;
  197. HMODULE m_hRichEdit;
  198. DWORD m_dwLoadFlags;
  199. // RSOP query and results
  200. BOOL m_bInitialized;
  201. LPTSTR m_szDisplayName;
  202. LPRSOP_QUERY m_pRSOPQuery;
  203. LPRSOP_QUERY_RESULTS m_pRSOPQueryResults;
  204. // Extended error lists
  205. CRSOPGPOLists m_GPOLists;
  206. CRSOPCSELists m_CSELists;
  207. BOOL m_bGetExtendedErrorInfo;
  208. IStream * m_pStm;
  209. BOOL m_bNamespaceSpecified; // boolean flag to indicate tha the namespace was
  210. // specified. special actions need to be taken to
  211. // prevent the namespace from getting deleted.
  212. public:
  213. //
  214. // Constructors/destructor
  215. //
  216. CRSOPComponentData();
  217. ~CRSOPComponentData();
  218. public:
  219. //
  220. // IUnknown methods
  221. //
  222. STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  223. STDMETHODIMP_(ULONG) AddRef();
  224. STDMETHODIMP_(ULONG) Release();
  225. public:
  226. //
  227. // Implemented IComponentData methods
  228. //
  229. STDMETHODIMP Initialize(LPUNKNOWN pUnknown);
  230. STDMETHODIMP CreateComponent(LPCOMPONENT* ppComponent);
  231. STDMETHODIMP QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  232. STDMETHODIMP Destroy(void);
  233. STDMETHODIMP Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  234. STDMETHODIMP GetDisplayInfo(LPSCOPEDATAITEM pItem);
  235. STDMETHODIMP CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  236. private:
  237. //
  238. // IComponentData helper methods
  239. //
  240. HRESULT SetRootNode();
  241. HRESULT EnumerateScopePane ( HSCOPEITEM hParent );
  242. public:
  243. //
  244. // Implemented IExtendPropertySheet2 methods
  245. //
  246. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  247. LONG_PTR handle, LPDATAOBJECT lpDataObject);
  248. STDMETHODIMP QueryPagesFor(LPDATAOBJECT lpDataObject);
  249. STDMETHODIMP GetWatermarks(LPDATAOBJECT lpIDataObject, HBITMAP* lphWatermark,
  250. HBITMAP* lphHeader, HPALETTE* lphPalette, BOOL* pbStretch);
  251. private:
  252. //
  253. // IExtendPropertySheet2 helper methods
  254. //
  255. HRESULT IsSnapInManager (LPDATAOBJECT lpDataObject);
  256. HRESULT IsNode (LPDATAOBJECT lpDataObject, MMC_COOKIE cookie);
  257. public:
  258. //
  259. // Implemented IExtendContextMenu methods
  260. //
  261. STDMETHODIMP AddMenuItems(LPDATAOBJECT piDataObject, LPCONTEXTMENUCALLBACK pCallback,
  262. LONG *pInsertionAllowed);
  263. STDMETHODIMP Command(LONG lCommandID, LPDATAOBJECT piDataObject);
  264. public:
  265. //
  266. // Implemented IPersistStreamInit interface members
  267. //
  268. STDMETHODIMP GetClassID(CLSID *pClassID);
  269. STDMETHODIMP IsDirty(VOID);
  270. STDMETHODIMP Load(IStream *pStm);
  271. STDMETHODIMP Save(IStream *pStm, BOOL fClearDirty);
  272. STDMETHODIMP GetSizeMax(ULARGE_INTEGER *pcbSize);
  273. STDMETHODIMP InitNew(VOID);
  274. private:
  275. //
  276. // IPersistStreamInit helper methods
  277. //
  278. STDMETHODIMP CopyFileToMSC (LPTSTR lpFileName, IStream *pStm);
  279. STDMETHODIMP CreateNameSpace (LPTSTR lpNameSpace, LPTSTR lpParentNameSpace);
  280. STDMETHODIMP CopyMSCToFile (IStream *pStm, LPTSTR *lpMofFileName);
  281. STDMETHODIMP BuildDisplayName (void);
  282. HRESULT LoadStringList( IStream* pStm, DWORD* pCount, LPTSTR** paszStringList );
  283. HRESULT SaveStringList( IStream* pStm, DWORD count, LPTSTR* aszStringList );
  284. private:
  285. //
  286. // RSOP initialization helper methods
  287. //
  288. HRESULT InitializeRSOPFromMSC(DWORD dwFlags);
  289. HRESULT DeleteArchivedRSOPNamespace();
  290. public:
  291. //
  292. // Helpers for IRSOPInformation (Used by CRSOPDataObject)
  293. //
  294. STDMETHODIMP GetNamespace(DWORD dwSection, LPOLESTR pszNamespace, INT ccMaxLength);
  295. STDMETHODIMP GetFlags(DWORD * pdwFlags);
  296. STDMETHODIMP GetEventLogEntryText(LPOLESTR pszEventSource, LPOLESTR pszEventLogName,
  297. LPOLESTR pszEventTime, DWORD dwEventID, LPOLESTR *ppszText);
  298. public:
  299. //
  300. // Implemented ISnapinHelp interface members
  301. //
  302. STDMETHODIMP GetHelpTopic(LPOLESTR *lpCompiledHelpFile);
  303. public:
  304. //
  305. // Member attribute access functions
  306. //
  307. BOOL IsPostXPBuild() { return m_bPostXPBuild; }
  308. HSCOPEITEM GetMachineScope() { return m_hMachine; }
  309. HSCOPEITEM GetUserScope() { return m_hUser; }
  310. bool IsNamespaceInitialized() const { return m_bInitialized != 0; };
  311. bool HasDisplayName() const { return (m_szDisplayName != NULL); };
  312. LPCTSTR GetDisplayName() const { return m_szDisplayName; };
  313. BOOL ComputerGPCoreErrorExists() { return m_CSELists.GetComputerGPCoreError(); }
  314. BOOL ComputerGPCoreWarningExists() { return m_CSELists.GetComputerGPCoreWarning(); }
  315. BOOL ComputerCSEErrorExists() { return m_CSELists.GetComputerCSEError(); }
  316. BOOL UserGPCoreErrorExists() { return m_CSELists.GetUserGPCoreError(); }
  317. BOOL UserGPCoreWarningExists() { return m_CSELists.GetUserGPCoreWarning(); }
  318. BOOL UserCSEErrorExists() { return m_CSELists.GetUserCSEError(); }
  319. private:
  320. //
  321. // Property page methods
  322. //
  323. HRESULT SetupFonts();
  324. HFONT m_BigBoldFont;
  325. HFONT m_BoldFont;
  326. private:
  327. //
  328. // Dialog handlers
  329. //
  330. static INT_PTR CALLBACK RSOPGPOListMachineProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  331. static INT_PTR CALLBACK RSOPGPOListUserProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  332. static INT_PTR CALLBACK RSOPErrorsMachineProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  333. static INT_PTR CALLBACK RSOPErrorsUserProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  334. static INT_PTR CALLBACK QueryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  335. private:
  336. //
  337. // Dialog event handlers
  338. //
  339. void OnEdit(HWND hDlg);
  340. void OnSecurity(HWND hDlg);
  341. void OnRefreshDisplay(HWND hDlg);
  342. void OnContextMenu(HWND hDlg, LPARAM lParam);
  343. void OnSaveAs (HWND hDlg);
  344. private:
  345. //
  346. // Dialog helper methods
  347. //
  348. void InitializeErrorsDialog(HWND hDlg, LPCSEITEM lpList);
  349. void RefreshErrorInfo (HWND hDlg);
  350. static HRESULT WINAPI ReadSecurityDescriptor (LPCWSTR lpGPOPath, SECURITY_INFORMATION si, PSECURITY_DESCRIPTOR *pSD, LPARAM lpContext);
  351. static HRESULT WINAPI WriteSecurityDescriptor (LPCWSTR lpGPOPath, SECURITY_INFORMATION si, PSECURITY_DESCRIPTOR pSD, LPARAM lpContext);
  352. private:
  353. //
  354. // Graphical GPO list usage methods
  355. //
  356. void FillGPOList(HWND hDlg, DWORD dwListID, LPGPOLISTITEM lpList,
  357. BOOL bSOM, BOOL bFiltering, BOOL bVersion, BOOL bInitial);
  358. void PrepGPOList(HWND hList, BOOL bSOM, BOOL bFiltering,
  359. BOOL bVersion, DWORD dwCount);
  360. private:
  361. //
  362. // Dialog methods for loading RSOP data from archive
  363. //
  364. static INT_PTR CALLBACK InitArchivedRsopDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  365. STDMETHODIMP InitializeRSOPFromArchivedData(IStream *pStm);
  366. private:
  367. //
  368. // Context menu event handler
  369. //
  370. HRESULT InitializeRSOP( BOOL bShowWizard );
  371. HRESULT EvaluateParameters(LPWSTR szNamespacePref,
  372. LPWSTR szTarget);
  373. private:
  374. //
  375. // Persistence help methods
  376. //
  377. void SetDirty(VOID) { m_bDirty = TRUE; }
  378. void ClearDirty(VOID) { m_bDirty = FALSE; }
  379. BOOL ThisIsDirty(VOID) { return m_bDirty; }
  380. BOOL m_bDirty;
  381. };
  382. //
  383. // class factory
  384. //
  385. class CRSOPComponentDataCF : public IClassFactory
  386. {
  387. protected:
  388. ULONG m_cRef;
  389. public:
  390. CRSOPComponentDataCF();
  391. ~CRSOPComponentDataCF();
  392. // IUnknown methods
  393. STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  394. STDMETHODIMP_(ULONG) AddRef();
  395. STDMETHODIMP_(ULONG) Release();
  396. // IClassFactory methods
  397. STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *);
  398. STDMETHODIMP LockServer(BOOL);
  399. };
  400. //
  401. // AboutGPE class factory
  402. //
  403. class CRSOPCMenuCF : public IClassFactory
  404. {
  405. protected:
  406. LONG m_cRef;
  407. public:
  408. CRSOPCMenuCF();
  409. ~CRSOPCMenuCF();
  410. // IUnknown methods
  411. STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  412. STDMETHODIMP_(ULONG) AddRef();
  413. STDMETHODIMP_(ULONG) Release();
  414. // IClassFactory methods
  415. STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *);
  416. STDMETHODIMP LockServer(BOOL);
  417. };
  418. #define RSOP_LAUNCH_PLANNING 1
  419. #define RSOP_LAUNCH_LOGGING 2
  420. //
  421. // Group Policy Hint types
  422. //
  423. typedef enum _RSOP_POLICY_HINT_TYPE {
  424. RSOPHintUnknown = 0, // No link information available
  425. RSOPHintMachine, // a machine
  426. RSOPHintUser, // a user
  427. RSOPHintSite, // a site
  428. RSOPHintDomain, // a domain
  429. RSOPHintOrganizationalUnit, // a organizational unit
  430. } RSOP_POLICY_HINT_TYPE, *PRSOP_POLICY_HINT_TYPE;
  431. class CRSOPCMenu : public IExtendContextMenu
  432. {
  433. protected:
  434. LONG m_cRef;
  435. LPWSTR m_lpDSObject;
  436. LPWSTR m_szDomain;
  437. LPWSTR m_szDN;
  438. RSOP_POLICY_HINT_TYPE m_rsopHint;
  439. static unsigned int m_cfDSObjectName;
  440. public:
  441. CRSOPCMenu();
  442. ~CRSOPCMenu();
  443. // IUnknown methods
  444. STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  445. STDMETHODIMP_(ULONG) AddRef();
  446. STDMETHODIMP_(ULONG) Release();
  447. // IExtencContextMenu methods
  448. STDMETHODIMP AddMenuItems(LPDATAOBJECT piDataObject,
  449. LPCONTEXTMENUCALLBACK piCallback,
  450. long * pInsertionAllowed);
  451. STDMETHODIMP Command(long lCommandID, LPDATAOBJECT piDataObject);
  452. };
  453. //
  454. // Save console defines
  455. //
  456. #define RSOP_PERSIST_DATA_VERSION 5 // version number in msc file
  457. #define MSC_RSOP_FLAG_DIAGNOSTIC 0x00000001 // Diagnostic mode vs planning mode
  458. #define MSC_RSOP_FLAG_ARCHIVEDATA 0x00000002 // RSoP data is archived also
  459. #define MSC_RSOP_FLAG_SLOWLINK 0x00000004 // Slow link simulation in planning mode
  460. #define MSC_RSOP_FLAG_NOUSER 0x00000008 // Do not display user data
  461. #define MSC_RSOP_FLAG_NOCOMPUTER 0x00000010 // Do not display computer data
  462. #define MSC_RSOP_FLAG_LOOPBACK_REPLACE 0x00000020 // Simulate loopback replace mode.
  463. #define MSC_RSOP_FLAG_LOOPBACK_MERGE 0x00000040 // Simulate loopback merge mode.
  464. #define MSC_RSOP_FLAG_USERDENIED 0x00000080 // User denied access
  465. #define MSC_RSOP_FLAG_COMPUTERDENIED 0x00000100 // Computer denied access
  466. #define MSC_RSOP_FLAG_COMPUTERWQLFILTERSTRUE 0x00000200
  467. #define MSC_RSOP_FLAG_USERWQLFILTERSTRUE 0x00000400
  468. #define MSC_RSOP_FLAG_NOGETEXTENDEDERRORINFO 0x00000800
  469. #define MSC_RSOP_FLAG_NO_DATA 0xf0000000 // No RSoP data was saved - only empty snapin
  470. //
  471. // RSOP Command line switches
  472. //
  473. #define RSOP_CMD_LINE_START TEXT("/Rsop") // base to all group policy command line switches
  474. #define RSOP_MODE TEXT("/RsopMode:") // Rsop Mode Planning/Logging 0 is logging, 1 is planning
  475. #define RSOP_USER_OU_PREF TEXT("/RsopUserOu:") // Rsop User OU preference
  476. #define RSOP_COMP_OU_PREF TEXT("/RsopCompOu:") // Rsop Comp OU Preference
  477. #define RSOP_USER_NAME TEXT("/RsopUser:") // Rsop User Name
  478. #define RSOP_COMP_NAME TEXT("/RsopComp:") // Rsop Comp Name
  479. #define RSOP_SITENAME TEXT("/RsopSite:") // Rsop Site Name
  480. #define RSOP_DCNAME_PREF TEXT("/RsopDc:") // DC Name that the tool should connect to
  481. #define RSOP_NAMESPACE TEXT("/RsopNamespace:") // namespace that the tool should use
  482. #define RSOP_TARGETCOMP TEXT("/RsopTargetComp:") // machine on which the rsop was originally run
  483. // for displaying in the UI and to get eventlog data
  484. //
  485. // Various flags to decide which prop sheets to show
  486. //
  487. #define RSOP_NOMSC 1
  488. #define RSOPMSC_OVERRIDE 2
  489. #define RSOPMSC_NOOVERRIDE 4