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.

449 lines
12 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. // stdafx.h : include file for standard system include files,
  9. // or project specific include files that are used frequently,
  10. // but are changed infrequently
  11. #ifndef STDAFX_H
  12. #define STDAFX_H
  13. #pragma warning(push,3)
  14. #include <afxwin.h>
  15. #include <afxdisp.h>
  16. #include <afxcmn.h>
  17. #include <atlbase.h>
  18. #include <afxdlgs.h>
  19. #include <afxole.h>
  20. #include <shlobj.h>
  21. #include <tchar.h>
  22. #include "resource.h"
  23. //#include <xstring>
  24. #include <list>
  25. #include <vector>
  26. #include <algorithm>
  27. #include <functional>
  28. #include <string>
  29. #include <dsgetdc.h>
  30. #include <sceattch.h>
  31. #include <io.h>
  32. #include <basetsd.h>
  33. #include <lm.h>
  34. #include <shlwapi.h>
  35. #include <shlwapip.h>
  36. using namespace std;
  37. //You may derive a class from CComModule and use it if you want to override
  38. //something, but do not change the name of _Module
  39. extern CComModule _Module;
  40. #include <atlcom.h>
  41. #pragma comment(lib, "mmc")
  42. #include <mmc.h>
  43. #include "afxtempl.h"
  44. /* Bug 424909, Yanggao, 6/29/2001
  45. * Define/include the stuff we need for WTL::CImageList. We need prototypes
  46. * for IsolationAwareImageList_Read and IsolationAwareImageList_Write here
  47. * because commctrl.h only declares them if __IStream_INTERFACE_DEFINED__
  48. * is defined. __IStream_INTERFACE_DEFINED__ is defined by objidl.h, which
  49. * we can't include before including afx.h because it ends up including
  50. * windows.h, which afx.h expects to include itself. Ugh.
  51. */
  52. HIMAGELIST WINAPI IsolationAwareImageList_Read(LPSTREAM pstm);
  53. BOOL WINAPI IsolationAwareImageList_Write(HIMAGELIST himl,LPSTREAM pstm);
  54. #define _WTL_NO_AUTOMATIC_NAMESPACE
  55. #include <atlapp.h>
  56. #include <atlwin.h>
  57. #include <atlctrls.h>
  58. extern"C" {
  59. #include <wtypes.h>
  60. #include <ntsecapi.h>
  61. #include <secedit.h>
  62. #include "edittemp.h"
  63. #include <scesvc.h>
  64. #include <compuuid.h> // UUIDS for computer management
  65. #include "hlpids.h"
  66. #include "hlparray.h"
  67. #include <stdlib.h>
  68. #include <wbemidl.h>
  69. #include <aclapi.h>
  70. #include <activeds.h>
  71. #include <sddl.h>
  72. #include <winldap.h>
  73. #include <afxmt.h>
  74. }
  75. #include <comdef.h>
  76. #include <accctrl.h>
  77. #include <dssec.h>
  78. #include <gpedit.h>
  79. #include <objsel.h>
  80. #include <aclui.h>
  81. // for theme-enabling
  82. #include <shfusion.h>
  83. #include "debug.h"
  84. #pragma warning(pop)
  85. const long UNINITIALIZED = -1;
  86. // This should be in secedit.h, but isn't
  87. // is now! const SCE_FOREVER_VALUE = -1;
  88. // Security Area types
  89. enum FOLDER_TYPES
  90. {
  91. STATIC = 0x8000,
  92. ROOT,
  93. ANALYSIS,
  94. CONFIGURATION,
  95. LOCATIONS,
  96. PROFILE,
  97. LOCALPOL,
  98. AREA_POLICY,
  99. POLICY_ACCOUNT,
  100. POLICY_LOCAL,
  101. POLICY_EVENTLOG,
  102. POLICY_PASSWORD,
  103. POLICY_KERBEROS,
  104. POLICY_LOCKOUT,
  105. POLICY_AUDIT,
  106. POLICY_OTHER,
  107. POLICY_LOG,
  108. AREA_PRIVILEGE,
  109. AREA_GROUPS,
  110. AREA_SERVICE,
  111. AREA_DS, //Raid 463177, Yang Gao, This is not used in XP. But it is for compatibility with W2K.
  112. AREA_REGISTRY,
  113. AREA_FILESTORE,
  114. AREA_POLICY_ANALYSIS,
  115. POLICY_ACCOUNT_ANALYSIS,
  116. POLICY_LOCAL_ANALYSIS,
  117. POLICY_EVENTLOG_ANALYSIS,
  118. POLICY_PASSWORD_ANALYSIS,
  119. POLICY_KERBEROS_ANALYSIS,
  120. POLICY_LOCKOUT_ANALYSIS,
  121. POLICY_AUDIT_ANALYSIS,
  122. POLICY_OTHER_ANALYSIS,
  123. POLICY_LOG_ANALYSIS,
  124. AREA_PRIVILEGE_ANALYSIS,
  125. AREA_GROUPS_ANALYSIS,
  126. AREA_SERVICE_ANALYSIS ,
  127. AREA_DS_ANALYSIS, //Raid 463177, Yang Gao, This is not used in XP. But it is for compatibility with W2K.
  128. AREA_REGISTRY_ANALYSIS,
  129. AREA_FILESTORE_ANALYSIS ,
  130. REG_OBJECTS,
  131. FILE_OBJECTS,
  132. DS_OBJECTS, //Raid 463177, Yang Gao, This is not used in XP. But it is for compatibility with W2K.
  133. AREA_LOCALPOL,
  134. LOCALPOL_ACCOUNT,
  135. LOCALPOL_LOCAL,
  136. LOCALPOL_EVENTLOG,
  137. LOCALPOL_PASSWORD,
  138. LOCALPOL_KERBEROS,
  139. LOCALPOL_LOCKOUT,
  140. LOCALPOL_AUDIT,
  141. LOCALPOL_OTHER,
  142. LOCALPOL_LOG,
  143. LOCALPOL_PRIVILEGE,
  144. LOCALPOL_LAST,
  145. AREA_LAST,
  146. NONE = 0xFFFF
  147. };
  148. enum RESULT_TYPES
  149. {
  150. ITEM_FIRST_POLICY = 0x8000,
  151. ITEM_BOOL,
  152. ITEM_DW,
  153. ITEM_SZ,
  154. ITEM_RET,
  155. ITEM_BON,
  156. ITEM_B2ON,
  157. ITEM_REGCHOICE,
  158. ITEM_REGFLAGS,
  159. ITEM_REGVALUE,
  160. ITEM_PROF_BOOL,
  161. ITEM_PROF_DW,
  162. ITEM_PROF_SZ,
  163. ITEM_PROF_RET,
  164. ITEM_PROF_BON,
  165. ITEM_PROF_B2ON,
  166. ITEM_PROF_REGCHOICE,
  167. ITEM_PROF_REGFLAGS,
  168. ITEM_PROF_REGVALUE,
  169. ITEM_LOCALPOL_BOOL,
  170. ITEM_LOCALPOL_DW,
  171. ITEM_LOCALPOL_SZ,
  172. ITEM_LOCALPOL_RET,
  173. ITEM_LOCALPOL_BON,
  174. ITEM_LOCALPOL_B2ON,
  175. ITEM_LOCALPOL_REGCHOICE,
  176. ITEM_LOCALPOL_REGFLAGS,
  177. ITEM_LOCALPOL_REGVALUE,
  178. ITEM_LAST_POLICY,
  179. ITEM_LOCALPOL_PRIVS,
  180. ITEM_PROF_PRIVS,
  181. ITEM_PRIVS,
  182. ITEM_GROUP,
  183. ITEM_GROUP_MEMBERS,
  184. ITEM_GROUP_MEMBEROF,
  185. ITEM_GROUPSTATUS,
  186. ITEM_PROF_GROUP,
  187. ITEM_PROF_GROUPSTATUS,
  188. ITEM_REGSD,
  189. ITEM_PROF_REGSD,
  190. ITEM_FILESD,
  191. ITEM_PROF_FILESD,
  192. ITEM_PROF_SERV,
  193. ITEM_ANAL_SERV,
  194. ITEM_OTHER = 0xFFFF
  195. };
  196. enum EVENT_TYPES
  197. {
  198. EVENT_TYPE_SYSTEM = 0,
  199. EVENT_TYPE_SECURITY = 1,
  200. EVENT_TYPE_APP = 2,
  201. };
  202. enum POLICY_SETTINGS {
  203. AUDIT_SUCCESS = 1,
  204. AUDIT_FAILURE = 2,
  205. };
  206. enum RETENTION {
  207. SCE_RETAIN_AS_NEEDED = 0,
  208. SCE_RETAIN_BY_DAYS = 1,
  209. SCE_RETAIN_MANUALLY = 2,
  210. };
  211. enum GWD_TYPES {
  212. GWD_CONFIGURE_LOG = 1,
  213. GWD_ANALYSIS_LOG,
  214. GWD_OPEN_DATABASE,
  215. GWD_IMPORT_TEMPLATE,
  216. GWD_EXPORT_TEMPLATE
  217. };
  218. // Note - This is the offset in my image list that represents the folder
  219. #define IMOFFSET_MISMATCH 1
  220. #define IMOFFSET_GOOD 2
  221. #define IMOFFSET_NOT_ANALYZED 3
  222. #define IMOFFSET_ERROR 4
  223. const CONFIG_LOCAL_IDX = 0;
  224. const MISMATCH_LOCAL_IDX = 1;
  225. const MATCH_LOCAL_IDX = 2;
  226. const CONFIG_ACCOUNT_IDX = 5;
  227. const MISMATCH_ACCOUNT_IDX = 6;
  228. const MATCH_ACCOUNT_IDX = 7;
  229. const CONFIG_FILE_IDX = 10;
  230. const MISMATCH_FILE_IDX = 11;
  231. const MATCH_FILE_IDX = 12;
  232. const FOLDER_IMAGE_IDX = 15;
  233. const MISMATCH_FOLDER_IDX = 16;
  234. const MATCH_FOLDER_IDX = 17;
  235. const CONFIG_GROUP_IDX = 20;
  236. const MISMATCH_GROUP_IDX = 21;
  237. const MATCH_GROUP_IDX = 22;
  238. const CONFIG_REG_IDX = 25;
  239. const MISMATCH_REG_IDX = 26;
  240. const MATCH_REG_IDX = 27;
  241. const CONFIG_SERVICE_IDX = 30;
  242. const MISMATCH_SERVICE_IDX = 31;
  243. const MATCH_SERVICE_IDX = 32;
  244. const CONFIG_POLICY_IDX = 35;
  245. const MISMATCH_POLICY_IDX = 36;
  246. const MATCH_POLICY_IDX = 37;
  247. const BLANK_IMAGE_IDX = 45;
  248. const SCE_OK_IDX = 46;
  249. const SCE_CRITICAL_IDX = 47;
  250. const SCE_IMAGE_IDX = 50;
  251. const CONFIG_FOLDER_IDX = 51;
  252. const TEMPLATES_IDX = 52;
  253. const LAST_IC_IMAGE_IDX = 53;
  254. const OPEN_FOLDER_IMAGE_IDX = 54;
  255. const LOCALSEC_POLICY_IDX = CONFIG_ACCOUNT_IDX;
  256. const LOCALSEC_LOCAL_IDX = CONFIG_LOCAL_IDX;
  257. /////////////////////////////////////////////////////////////////////////////
  258. // Helper functions
  259. template<class TYPE>
  260. inline void SAFE_RELEASE(TYPE*& pObj)
  261. {
  262. if (pObj != NULL)
  263. {
  264. pObj->Release();
  265. pObj = NULL;
  266. }
  267. else
  268. {
  269. TRACE(_T("Release called on NULL interface ptr\n"));
  270. }
  271. }
  272. // security settings (extension of GPE)
  273. extern const CLSID CLSID_Snapin; // In-Proc server GUID
  274. extern const GUID cNodeType; // Main NodeType GUID on numeric format
  275. extern const wchar_t* cszNodeType; // Main NodeType GUID on string format
  276. // security settings (extension of RSOP)
  277. extern const CLSID CLSID_RSOPSnapin; // In-Proc server GUID
  278. extern const GUID cRSOPNodeType; // Main NodeType GUID on numeric format
  279. extern const wchar_t* cszRSOPNodeType; // Main NodeType GUID on string format
  280. // SCE (standalone)
  281. extern const CLSID CLSID_SCESnapin; // In-Proc server GUID
  282. extern const GUID cSCENodeType; // Main NodeType GUID on numeric format
  283. extern const wchar_t* cszSCENodeType; // Main NodeType GUID on string format
  284. // SAV (standalone)
  285. extern const CLSID CLSID_SAVSnapin; // In-Proc server GUID
  286. extern const GUID cSAVNodeType; // Main NodeType GUID on numeric format
  287. extern const wchar_t* cszSAVNodeType; // Main NodeType GUID on string format
  288. // Local security (standalone)
  289. extern const CLSID CLSID_LSSnapin; // In-Proc server GUID
  290. extern const GUID cLSNodeType; // Main NodeType GUID on numeric format
  291. extern const wchar_t* cszLSNodeType; // Main NodeType GUID on string format
  292. extern const CLSID CLSID_SCEAbout;
  293. extern const CLSID CLSID_SCMAbout;
  294. extern const CLSID CLSID_SSAbout;
  295. extern const CLSID CLSID_LSAbout;
  296. extern const CLSID CLSID_RSOPAbout;
  297. // New Clipboard format that has the Type and Cookie
  298. extern const wchar_t* SNAPIN_INTERNAL;
  299. EXTERN_C const TCHAR SNAPINS_KEY[];
  300. EXTERN_C const TCHAR NODE_TYPES_KEY[];
  301. EXTERN_C const TCHAR g_szExtensions[];
  302. EXTERN_C const TCHAR g_szNameSpace[];
  303. struct INTERNAL
  304. {
  305. INTERNAL()
  306. {
  307. m_type = CCT_UNINITIALIZED;
  308. m_cookie = -1;
  309. m_foldertype = NONE;
  310. };
  311. virtual ~INTERNAL()
  312. {
  313. }
  314. DATA_OBJECT_TYPES m_type; // What context is the data object.
  315. MMC_COOKIE m_cookie; // What object the cookie represents
  316. FOLDER_TYPES m_foldertype;
  317. CLSID m_clsid; // Class ID of who created this data object
  318. INTERNAL & operator=(const INTERNAL& rhs)
  319. {
  320. if (&rhs == this)
  321. return *this;
  322. m_type = rhs.m_type;
  323. m_cookie = rhs.m_cookie;
  324. m_foldertype = rhs.m_foldertype;
  325. //This is a safe usage.
  326. memcpy(&m_clsid, &rhs.m_clsid, sizeof(CLSID));
  327. return *this;
  328. }
  329. BOOL operator==(const INTERNAL& rhs)
  330. {
  331. return rhs.m_cookie == m_cookie;
  332. }
  333. };
  334. typedef struct {
  335. LPTSTR TemplateName;
  336. LPTSTR ServiceName;
  337. } SCESVCP_HANDLE, *PSCESVCP_HANDLE;
  338. typedef struct RegChoiceList{
  339. LPTSTR szName;
  340. DWORD dwValue;
  341. struct RegChoiceList *pNext;
  342. } REGCHOICE, *PREGCHOICE, REGFLAGS, *PREGFLAGS;
  343. // Debug instance counter
  344. #ifdef _DEBUG
  345. inline void DbgInstanceRemaining(char * pszClassName, int cInstRem)
  346. {
  347. CString buf;
  348. //This is not a safe usage. Avoid using wsprintf. Raid #555867. Yanggao.
  349. buf.Format("%s has %d instances left over.", pszClassName, cInstRem);
  350. ::MessageBoxA(NULL, buf, "Memory Leak!!!", MB_OK);
  351. }
  352. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls) extern int s_cInst_##cls = 0;
  353. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls) ++(s_cInst_##cls);
  354. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls) --(s_cInst_##cls);
  355. #define DEBUG_VERIFY_INSTANCE_COUNT(cls) \
  356. extern int s_cInst_##cls; \
  357. if (s_cInst_##cls) DbgInstanceRemaining(#cls, s_cInst_##cls);
  358. #else
  359. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls)
  360. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls)
  361. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls)
  362. #define DEBUG_VERIFY_INSTANCE_COUNT(cls)
  363. #endif
  364. // For theme-enabling
  365. #ifndef ARRAYSIZE
  366. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  367. #endif
  368. #define SCE_MODE_DOMAIN_COMPUTER_ERROR 9999999
  369. #ifdef UNICODE
  370. #define PROPSHEETPAGE_V3 PROPSHEETPAGEW_V3
  371. #else
  372. #define PROPSHEETPAGE_V3 PROPSHEETPAGEA_V3
  373. #endif
  374. HPROPSHEETPAGE MyCreatePropertySheetPage(AFX_OLDPROPSHEETPAGE* psp);
  375. class CThemeContextActivator
  376. {
  377. public:
  378. CThemeContextActivator() : m_ulActivationCookie(0)
  379. { SHActivateContext (&m_ulActivationCookie); }
  380. ~CThemeContextActivator()
  381. { SHDeactivateContext (m_ulActivationCookie); }
  382. private:
  383. ULONG_PTR m_ulActivationCookie;
  384. };
  385. #endif // STDAFX_H