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.

644 lines
19 KiB

  1. //***************************************************************************
  2. //
  3. // sceprov.h
  4. //
  5. // Module: SCE WMI provider code
  6. //
  7. // Purpose: Genral purpose include file.
  8. //
  9. // Copyright (c) 1999-2001 Microsoft Corporation
  10. //
  11. //***************************************************************************
  12. #if _MSC_VER >= 1000
  13. #pragma once
  14. #endif // _MSC_VER >= 1000
  15. #ifndef _SceProv_H_
  16. #define _SceProv_H_
  17. #include "precomp.h"
  18. #include <wbemidl.h>
  19. #include <wbemprov.h>
  20. #include <eh.h>
  21. #include "wmiutils.h"
  22. //
  23. //You may derive a class from CComModule and use it if you want to override
  24. //something, but do not change the name of _Module
  25. //
  26. extern CComModule _Module;
  27. //
  28. // make these global objects available to those who include this header file
  29. //
  30. extern CComBSTR g_bstrTranxID;
  31. extern CComBSTR g_bstrDefLogFilePath;
  32. #include <atlcom.h>
  33. #include "resource.h"
  34. typedef LPVOID * PPVOID;
  35. //
  36. // integer value reserved for null
  37. //
  38. #define SCE_NULL_INTEGER (DWORD)-2
  39. //
  40. // struct that encapulate the profile handle
  41. //
  42. typedef struct _tag_SCEP_HANDLE
  43. {
  44. LPVOID hProfile; // SCE_HANDLE
  45. PWSTR SectionName; // Section name.
  46. } SCEP_HANDLE, *LPSCEP_HANDLE;
  47. //
  48. // action type enum
  49. //
  50. typedef enum tagACTIONTYPE
  51. {
  52. ACTIONTYPE_ENUM = 0,
  53. ACTIONTYPE_GET = 1,
  54. ACTIONTYPE_QUERY = 2,
  55. ACTIONTYPE_DELETE = 3
  56. } ACTIONTYPE;
  57. //
  58. // method type enum
  59. //
  60. typedef enum tagMETHODTYPE
  61. {
  62. METHODTYPE_IMPORT = 0,
  63. METHODTYPE_EXPORT = 1,
  64. METHODTYPE_APPLY = 2
  65. } METHODTYPE;
  66. //
  67. // store type enum
  68. //
  69. typedef enum tagSCESTORETYPE
  70. {
  71. SCE_STORE_TYPE_INVALID = 0,
  72. SCE_STORE_TYPE_TEMPLATE = 1,
  73. SCE_STORE_TYPE_CONFIG_DB = 2, // currently not supported
  74. SCE_STORE_TYPE_STREAM = 0x00010000, // currently not supported
  75. } SCE_STORE_TYPE;
  76. //
  77. // some constants
  78. //
  79. #define SCE_OBJECT_TYPE_FILE 0
  80. #define SCE_OBJECT_TYPE_KEY 1
  81. #define SCE_AUDIT_EVENT_SUCCESS (0x00000001L)
  82. #define SCE_AUDIT_EVENT_FAILURE (0x00000002L)
  83. #define SCEWMI_TEMPLATE_CLASS L"Sce_Template"
  84. #define SCEWMI_PASSWORD_CLASS L"Sce_PasswordPolicy"
  85. #define SCEWMI_LOCKOUT_CLASS L"Sce_AccountLockoutPolicy"
  86. #define SCEWMI_OPERATION_CLASS L"Sce_Operation"
  87. #define SCEWMI_DATABASE_CLASS L"Sce_Database"
  88. #define SCEWMI_KERBEROS_CLASS L"Sce_KerberosPolicy"
  89. #define SCEWMI_ATTACHMENT_CLASS L"Sce_Pod"
  90. #define SCEWMI_AUDIT_CLASS L"Sce_AuditPolicy"
  91. #define SCEWMI_EVENTLOG_CLASS L"Sce_EventLog"
  92. #define SCEWMI_REGVALUE_CLASS L"Sce_RegistryValue"
  93. #define SCEWMI_OPTION_CLASS L"Sce_SecurityOptions"
  94. #define SCEWMI_FILEOBJECT_CLASS L"Sce_FileObject"
  95. #define SCEWMI_KEYOBJECT_CLASS L"Sce_KeyObject"
  96. #define SCEWMI_SERVICE_CLASS L"Sce_SystemService"
  97. #define SCEWMI_RIGHT_CLASS L"Sce_UserPrivilegeRight"
  98. #define SCEWMI_GROUP_CLASS L"Sce_RestrictedGroup"
  99. #define SCEWMI_KNOWN_REG_CLASS L"Sce_KnownRegistryValues"
  100. #define SCEWMI_KNOWN_PRIV_CLASS L"Sce_SupportedPrivileges"
  101. #define SCEWMI_POD_CLASS L"Sce_Pod"
  102. #define SCEWMI_PODDATA_CLASS L"Sce_PodData"
  103. #define SCEWMI_LOG_CLASS L"Sce_ConfigurationLogRecord"
  104. #define SCEWMI_EMBED_BASE_CLASS L"Sce_EmbedFO"
  105. #define SCEWMI_LINK_BASE_CLASS L"Sce_LinkFO"
  106. #define SCEWMI_SEQUENCE L"Sce_Sequence"
  107. #define SCEWMI_LOGOPTIONS_CLASS L"Sce_LogOptions"
  108. #define SCEWMI_CLASSORDER_CLASS L"Sce_ClassOrder"
  109. #define SCEWMI_TRANSACTION_ID_CLASS L"Sce_TransactionID"
  110. #define SCEWMI_TRANSACTION_TOKEN_CLASS L"Sce_TransactionToken"
  111. //
  112. // extension class type enum
  113. //
  114. typedef enum tagExtClassType
  115. {
  116. EXT_CLASS_TYPE_INVALID,
  117. EXT_CLASS_TYPE_EMBED,
  118. EXT_CLASS_TYPE_LINK // not supported at this point
  119. } EnumExtClassType;
  120. //====================================================================================
  121. /*
  122. Class description
  123. Naming:
  124. CForeignClassInfo stands for Foreign Class Information.
  125. Base class:
  126. None
  127. Purpose of class:
  128. (1) This class encapulates information regarding a foreign class
  129. Design:
  130. (1) foreign provider's namespace.
  131. (2) foreign class's name.
  132. (3) how we are seeing this class (whether embedding or linking).
  133. Currently, we only support embedding.
  134. (4) Our embedding class's key property names. This is needed for easy comparison.
  135. there is a need to know if a particular instance already exists. Knowing this
  136. is not a very easy work. Theoretically, we know an instance when we know its
  137. key. WMI encapulates key notation in terms of path (a string). However, WMI
  138. doesn't return a canonical form of the path. I've observed that when using
  139. boolean property has part of the key, WMI sometimes returns the path using
  140. boolPropertyName=1, while it returns boolPropertyName=TRUE at other times.
  141. This forces us to compare instances using its key property values.
  142. Currently, the key property names are populated inside
  143. CExtClasses::PopulateKeyPropertyNames
  144. Use:
  145. This class is pretty much a wrapper to ease memory management. Since it's members will be
  146. used extensively for dealing with embedded classes, we make all them public.
  147. */
  148. class CForeignClassInfo
  149. {
  150. public:
  151. CForeignClassInfo()
  152. : bstrNamespace(NULL),
  153. bstrClassName(NULL),
  154. dwClassType(EXT_CLASS_TYPE_INVALID),
  155. m_pVecKeyPropNames(NULL)
  156. {
  157. }
  158. ~CForeignClassInfo();
  159. void CleanNames();
  160. BSTR bstrNamespace;
  161. BSTR bstrClassName;
  162. EnumExtClassType dwClassType;
  163. std::vector<BSTR>* m_pVecKeyPropNames;
  164. };
  165. //====================================================================================
  166. //
  167. // trivial wrapper just to ease the memory management and initialization
  168. //
  169. class CPropValuePair
  170. {
  171. public:
  172. CPropValuePair::CPropValuePair() : pszKey(NULL)
  173. {
  174. ::VariantInit(&varVal);
  175. }
  176. CPropValuePair::~CPropValuePair()
  177. {
  178. delete [] pszKey;
  179. ::VariantClear(&varVal);
  180. }
  181. LPWSTR pszKey;
  182. VARIANT varVal;
  183. };
  184. //====================================================================================
  185. //
  186. // this trivial wrapper class is to make it easy for an unique global instance. No other purpose
  187. //
  188. class CCriticalSection
  189. {
  190. public:
  191. CCriticalSection();
  192. ~CCriticalSection();
  193. void Enter();
  194. void Leave();
  195. private:
  196. CRITICAL_SECTION m_cs;
  197. };
  198. //====================================================================================
  199. //
  200. // Our unique instance of critical section wrapper.
  201. // make it visible to those who include this header
  202. //
  203. extern CCriticalSection g_CS;
  204. const DWORD SCE_LOG_Error_Mask = 0x0000FFFF;
  205. const DWORD SCE_LOG_Verbose_Mask = 0xFFFF0000;
  206. //====================================================================================
  207. /*
  208. This struct determines how logging is done. Currently, logging comes in two
  209. separate aspects:
  210. (1) types of errors (success) to log (SCE_LOG_Error_Mask), and
  211. (2) detail level of logging (SCE_LOG_Verbose_Mask)
  212. We use bit patterns to control these two aspects
  213. */
  214. typedef enum tag_SCE_LOG_OPTION
  215. {
  216. Sce_log_None = 0x00000000, // log nothing
  217. Sce_log_Error = 0x00000001, // log errors
  218. Sce_log_Success = 0x00000002, // log success
  219. Sce_log_All = Sce_log_Error | Sce_log_Success,
  220. Sce_log_Verbose = 0x00010000, // log verbose
  221. Sce_Log_Parameters = 0x00100000, // log parameters (in and out)
  222. };
  223. typedef DWORD SCE_LOG_OPTION;
  224. //====================================================================================
  225. //
  226. // this class determines how we should log errors
  227. //
  228. class CLogOptions
  229. {
  230. public:
  231. CLogOptions() : m_dwOption(Sce_log_Error){}
  232. void GetLogOptionsFromWbemObject(IWbemServices* pNamespace);
  233. SCE_LOG_OPTION GetLogOption()const
  234. {
  235. return m_dwOption;
  236. }
  237. private:
  238. SCE_LOG_OPTION m_dwOption;
  239. };
  240. //
  241. // unique global instance to the log options
  242. // must protect its access for thread safety
  243. //
  244. extern CLogOptions g_LogOption;
  245. //====================================================================================
  246. //
  247. // case insensitive comparison for our map functor
  248. //
  249. template< class T>
  250. struct strLessThan : public std::binary_function< T, T, bool >
  251. {
  252. bool operator()( const T& X, const T& Y ) const
  253. {
  254. return ( _wcsicmp( X, Y ) < 0 );
  255. }
  256. };
  257. //====================================================================================
  258. class CHeap_Exception
  259. {
  260. public:
  261. enum HEAP_ERROR
  262. {
  263. E_ALLOCATION_ERROR = 0 ,
  264. E_FREE_ERROR
  265. };
  266. private:
  267. HEAP_ERROR m_Error;
  268. public:
  269. CHeap_Exception ( HEAP_ERROR e ) : m_Error ( e ) {}
  270. ~CHeap_Exception () {}
  271. HEAP_ERROR GetError() { return m_Error ; }
  272. } ;
  273. //====================================================================================
  274. /*
  275. Class description
  276. Naming:
  277. CSceWmiProv stands for SCE Provider for WMI.
  278. Base class:
  279. (1) CComObjectRootEx for threading model and IUnknown.
  280. (2) CComCoClass for class factory support.
  281. (3) IWbemServices and IWbemProviderInit for being a WMI provider.
  282. Purpose of class:
  283. (1) This class is what makes our dll a WMI provider.
  284. (2) Cache m_srpNamespace.
  285. Design:
  286. (1) We rely on ATL for support of a Multi-Threaded Apartment server.
  287. (2) We rely on ATL for class factory support.
  288. (3) We rely on ATL for IUnknown support (using BEGIN_COM_MAP).
  289. (4) We rely on ATL for script registration (.rgs) for our dll.
  290. (5) We don't implement most of the IWbemServices functionalities.
  291. See all those WBEM_E_NOT_SUPPORTED return values.
  292. Use:
  293. This class is pretty much a wrapper to ease memory management. Since it's members will be
  294. used extensively for dealing with embedded classes, we make all them public.
  295. Notes:
  296. (1) See winnt.h for many of the typedef's like STDMETHODCALLTYPE
  297. (2) This class is not intended for any further derivation. That is why we don't even bother
  298. to have a virtual destructor.
  299. (3) For security reasons, all WMI calls (IWbemServices or IWbemProviderInit) should be impersonated.
  300. */
  301. class CSceWmiProv
  302. : public CComObjectRootEx<CComMultiThreadModel>,
  303. public CComCoClass<CSceWmiProv, &CLSID_SceProv>,
  304. public IWbemServices,
  305. public IWbemProviderInit
  306. {
  307. public:
  308. //
  309. // determines which interfaces are exposed
  310. //
  311. BEGIN_COM_MAP(CSceWmiProv)
  312. COM_INTERFACE_ENTRY(IWbemServices)
  313. COM_INTERFACE_ENTRY(IWbemProviderInit)
  314. END_COM_MAP()
  315. //
  316. // registry script support
  317. //
  318. DECLARE_REGISTRY_RESOURCEID(IDR_SceProv)
  319. //
  320. // methods of IWbemProviderInit
  321. //
  322. HRESULT STDMETHODCALLTYPE Initialize(
  323. IN LPWSTR pszUser,
  324. IN LONG lFlags,
  325. IN LPWSTR pszNamespace,
  326. IN LPWSTR pszLocale,
  327. IN IWbemServices *pNamespace,
  328. IN IWbemContext *pCtx,
  329. IN IWbemProviderInitSink *pInitSink
  330. );
  331. //
  332. // methods of IWbemServices
  333. //
  334. //
  335. // the following methods are supported by our provider
  336. //
  337. HRESULT STDMETHODCALLTYPE GetObjectAsync(
  338. IN const BSTR ObjectPath,
  339. IN long lFlags,
  340. IN IWbemContext __RPC_FAR *pCtx,
  341. IN IWbemObjectSink __RPC_FAR *pResponseHandler
  342. );
  343. HRESULT STDMETHODCALLTYPE DeleteInstanceAsync(
  344. IN const BSTR ObjectPath,
  345. IN long lFlags,
  346. IN IWbemContext __RPC_FAR *pCtx,
  347. IN IWbemObjectSink __RPC_FAR *pResponseHandler
  348. );
  349. HRESULT STDMETHODCALLTYPE PutInstanceAsync(
  350. IN IWbemClassObject __RPC_FAR *pInst,
  351. IN long lFlags,
  352. IN IWbemContext __RPC_FAR *pCtx,
  353. IN IWbemObjectSink __RPC_FAR *pResponseHandler
  354. );
  355. HRESULT STDMETHODCALLTYPE CreateInstanceEnumAsync(
  356. IN const BSTR Class,
  357. IN long lFlags,
  358. IN IWbemContext __RPC_FAR *pCtx,
  359. IN IWbemObjectSink __RPC_FAR *pResponseHandler
  360. );
  361. HRESULT STDMETHODCALLTYPE ExecQueryAsync(
  362. IN const BSTR QueryLanguage,
  363. IN const BSTR Query,
  364. IN long lFlags,
  365. IN IWbemContext __RPC_FAR *pCtx,
  366. IN IWbemObjectSink __RPC_FAR *pResponseHandler
  367. );
  368. HRESULT STDMETHODCALLTYPE ExecMethodAsync(
  369. IN const BSTR,
  370. IN const BSTR,
  371. IN long lFlags,
  372. IN IWbemContext __RPC_FAR * pCtx,
  373. IN IWbemClassObject __RPC_FAR * pInParams,
  374. IN IWbemObjectSink __RPC_FAR * pResponse
  375. );
  376. //
  377. // the following methods are NOT supported by our provider
  378. //
  379. HRESULT STDMETHODCALLTYPE OpenNamespace(
  380. IN const BSTR Namespace,
  381. IN long lFlags,
  382. IN IWbemContext __RPC_FAR *pCtx,
  383. IN OUT IWbemServices __RPC_FAR *__RPC_FAR *ppWorkingNamespace,
  384. IN OUT IWbemCallResult __RPC_FAR *__RPC_FAR *ppResult) {return WBEM_E_NOT_SUPPORTED;};
  385. HRESULT STDMETHODCALLTYPE CancelAsyncCall(
  386. IN IWbemObjectSink __RPC_FAR *pSink) {return WBEM_E_NOT_SUPPORTED;};
  387. HRESULT STDMETHODCALLTYPE QueryObjectSink(
  388. IN long lFlags,
  389. OUT IWbemObjectSink __RPC_FAR *__RPC_FAR *ppResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  390. HRESULT STDMETHODCALLTYPE GetObject(
  391. IN const BSTR ObjectPath,
  392. IN long lFlags,
  393. IN IWbemContext __RPC_FAR *pCtx,
  394. IN OUT IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject,
  395. IN OUT IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  396. HRESULT STDMETHODCALLTYPE PutClass(
  397. IN IWbemClassObject __RPC_FAR *pObject,
  398. IN long lFlags,
  399. IN IWbemContext __RPC_FAR *pCtx,
  400. IN OUT IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  401. HRESULT STDMETHODCALLTYPE PutClassAsync(
  402. IN IWbemClassObject __RPC_FAR *pObject,
  403. IN long lFlags,
  404. IN IWbemContext __RPC_FAR *pCtx,
  405. IN IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  406. HRESULT STDMETHODCALLTYPE DeleteClass(
  407. IN const BSTR Class,
  408. IN long lFlags,
  409. IN IWbemContext __RPC_FAR *pCtx,
  410. IN OUT IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  411. HRESULT STDMETHODCALLTYPE DeleteClassAsync(
  412. IN const BSTR Class,
  413. IN long lFlags,
  414. IN IWbemContext __RPC_FAR *pCtx,
  415. IN IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  416. HRESULT STDMETHODCALLTYPE CreateClassEnum(
  417. IN const BSTR Superclass,
  418. IN long lFlags,
  419. IN IWbemContext __RPC_FAR *pCtx,
  420. OUT IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  421. HRESULT STDMETHODCALLTYPE CreateClassEnumAsync(
  422. IN const BSTR Superclass,
  423. IN long lFlags,
  424. IN IWbemContext __RPC_FAR *pCtx,
  425. IN IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  426. HRESULT STDMETHODCALLTYPE PutInstance(
  427. IN IWbemClassObject __RPC_FAR *pInst,
  428. IN long lFlags,
  429. IN IWbemContext __RPC_FAR *pCtx,
  430. IN OUT IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  431. HRESULT STDMETHODCALLTYPE DeleteInstance(
  432. IN const BSTR ObjectPath,
  433. IN long lFlags,
  434. IN IWbemContext __RPC_FAR *pCtx,
  435. IN OUT IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  436. HRESULT STDMETHODCALLTYPE CreateInstanceEnum(
  437. IN const BSTR Class,
  438. IN long lFlags,
  439. IN IWbemContext __RPC_FAR *pCtx,
  440. OUT IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  441. HRESULT STDMETHODCALLTYPE ExecQuery(
  442. IN const BSTR QueryLanguage,
  443. IN const BSTR Query,
  444. IN long lFlags,
  445. IN IWbemContext __RPC_FAR *pCtx,
  446. OUT IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  447. HRESULT STDMETHODCALLTYPE ExecNotificationQuery(
  448. IN const BSTR QueryLanguage,
  449. IN const BSTR Query,
  450. IN long lFlags,
  451. IN IWbemContext __RPC_FAR *pCtx,
  452. OUT IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  453. HRESULT STDMETHODCALLTYPE ExecNotificationQueryAsync(
  454. IN const BSTR QueryLanguage,
  455. IN const BSTR Query,
  456. IN long lFlags,
  457. IN IWbemContext __RPC_FAR *pCtx,
  458. IN IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  459. HRESULT STDMETHODCALLTYPE ExecMethod(
  460. IN const BSTR,
  461. IN const BSTR,
  462. IN long lFlags,
  463. IN IWbemContext*,
  464. IN IWbemClassObject*,
  465. OUT IWbemClassObject**,
  466. OUT IWbemCallResult**) {return WBEM_E_NOT_SUPPORTED;}
  467. private:
  468. CComPtr<IWbemServices> m_srpNamespace;
  469. static CHeap_Exception m_he;
  470. };
  471. typedef CSceWmiProv *PCSceWmiProv;
  472. //
  473. // some global functions. See their definition for details.
  474. //
  475. HRESULT CheckImpersonationLevel();
  476. HRESULT CheckAndExpandPath(LPCWSTR pszIn, BSTR *pszOut, BOOL *pbSdb);
  477. HRESULT MakeSingleBackSlashPath(LPCWSTR pszIn, WCHAR wc, BSTR *pszrOut);
  478. HRESULT ConvertToDoubleBackSlashPath(LPCWSTR strIn, WCHAR wc, BSTR *pszOut);
  479. HRESULT GetWbemPathParser(IWbemPath** ppPathParser);
  480. HRESULT GetWbemQuery(IWbemQuery** ppQuery);
  481. HRESULT CreateDefLogFile(BSTR* pbstrDefLogFilePath);
  482. #endif