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.

525 lines
20 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright � Microsoft Corporation. All rights reserved.
  4. //
  5. // WBEMGLUE.H
  6. //
  7. // Purpose: Implementation of WBEM Glue classes
  8. //
  9. //***************************************************************************
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13. #ifndef _WbemGlue_H_Included
  14. #define _WbemGlue_H_Included
  15. #undef PURE
  16. #define PURE {return (ULONG)E_NOTIMPL;}
  17. typedef LPVOID *PPVOID;
  18. #include <wbemidl.h>
  19. #include <map>
  20. #include <set>
  21. #include <provider.h>
  22. #define DEFAULT_NAMESPACE L"Root\\CimV2"
  23. typedef std::map<CHString, LPVOID> STRING2LPVOID;
  24. typedef std::map<LPCVOID, PLONG> PTR2PLONG;
  25. typedef std::set<LPVOID> PROVIDERPTRS;
  26. class CWbemGlueFactory;
  27. class CWbemGlueImpersonation;
  28. class POLARITY CWbemProviderGlue : public IWbemServices, public IWbemProviderInit
  29. {
  30. friend class CWbemGlueImpersonation;
  31. public:
  32. // Public Static functions
  33. // these are for use by implementors of Framework based providers
  34. static HRESULT WINAPI GetAllInstances( LPCWSTR pszClassName,
  35. TRefPointerCollection<CInstance> *pList,
  36. LPCWSTR pszNamespace,
  37. MethodContext *pMethodContext );
  38. static HRESULT WINAPI GetAllInstancesAsynch( LPCWSTR pszClassName,
  39. Provider *pRequester,
  40. LPProviderInstanceCallback pCallback,
  41. LPCWSTR pszNamespace,
  42. MethodContext *pMethodContext,
  43. void *pUserData );
  44. static HRESULT WINAPI GetAllDerivedInstancesAsynch( LPCWSTR pszBaseClassName,
  45. Provider *pRequester,
  46. LPProviderInstanceCallback pCallback,
  47. LPCWSTR pszNamespace,
  48. MethodContext *pMethodContext,
  49. void *pUserData );
  50. static HRESULT WINAPI GetAllDerivedInstances( LPCWSTR pszBaseClassName,
  51. TRefPointerCollection<CInstance> *pList,
  52. MethodContext *pMethodContext,
  53. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  54. LPCWSTR pszNamespace = NULL);
  55. #else
  56. LPCWSTR pszNamespace);
  57. #endif
  58. static HRESULT WINAPI GetInstanceByPath( LPCWSTR pszObjectPath,
  59. CInstance **ppInstance,
  60. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  61. MethodContext *pMethodContext = NULL );
  62. #else
  63. MethodContext *pMethodContext);
  64. #endif
  65. static HRESULT WINAPI GetInstanceKeysByPath( LPCWSTR pszInstancePath,
  66. CInstance **ppInstance,
  67. MethodContext *pMethodContext);
  68. static HRESULT WINAPI GetInstancePropertiesByPath( LPCWSTR pszInstancePath,
  69. CInstance **ppInstance,
  70. MethodContext *pMethodContext,
  71. CHStringArray &csaProperties);
  72. static HRESULT WINAPI GetInstancesByQuery( LPCWSTR query,
  73. TRefPointerCollection<CInstance> *pList,
  74. MethodContext *pMethodContext,
  75. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  76. LPCWSTR pszNamespace = NULL);
  77. #else
  78. LPCWSTR pszNamespace);
  79. #endif
  80. static HRESULT WINAPI GetInstancesByQueryAsynch( LPCWSTR query,
  81. Provider *pRequester,
  82. LPProviderInstanceCallback pCallback,
  83. LPCWSTR pszNamespace,
  84. MethodContext *pMethodContext,
  85. void *pUserData );
  86. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  87. // This version of GetEmptyInstance is deprecated. Use the next one.
  88. static HRESULT WINAPI GetEmptyInstance( LPCWSTR pszClassName,
  89. CInstance **ppInstance,
  90. LPCWSTR pszNamespace = NULL);
  91. #endif
  92. static HRESULT WINAPI GetEmptyInstance( MethodContext *pMethodContext,
  93. LPCWSTR pszClassName,
  94. CInstance **ppInstance,
  95. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  96. LPCWSTR pszNamespace = NULL);
  97. #else
  98. LPCWSTR pszNamespace);
  99. #endif
  100. // Both of these FillInstance calls are deprecated. Use GetInstanceByPath, or the even
  101. // more performant functions GetInstanceKeysByPath or GetInstancePropertiesByPath.
  102. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  103. static HRESULT WINAPI FillInstance( CInstance *pInstance,
  104. LPCWSTR pszNamespace = NULL );
  105. static HRESULT WINAPI FillInstance( MethodContext *pMethodContext,
  106. CInstance *pInstance );
  107. #endif
  108. // determine whether one class is derived from another
  109. static bool WINAPI IsDerivedFrom( LPCWSTR pszBaseClassName,
  110. LPCWSTR pszDerivedClassName,
  111. MethodContext *pMethodContext,
  112. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  113. LPCWSTR pszNamespace = NULL );
  114. #else
  115. LPCWSTR pszNamespace);
  116. #endif
  117. // logging in and out of framework
  118. // each framework based DLL must log in and out with these functions
  119. // Deprecated in favor of the version that takes a PLONG.
  120. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  121. static BOOL WINAPI FrameworkLoginDLL(LPCWSTR name);
  122. static BOOL WINAPI FrameworkLogoffDLL(LPCWSTR name);
  123. #endif
  124. // You must pass the *same* PLONG to all three of FrameworkLoginDLL,
  125. // FrameworkLogoffDLL, and the CWbemGlueFactory constructor.
  126. static BOOL WINAPI FrameworkLoginDLL(LPCWSTR name, PLONG plRefCount);
  127. static BOOL WINAPI FrameworkLogoffDLL(LPCWSTR name, PLONG plRefCount);
  128. static bool WINAPI SetStatusObject(MethodContext *pContext, LPCWSTR pNamespace,
  129. LPCWSTR pDescription, HRESULT hr,
  130. const SAFEARRAY *pPrivilegesNotHeld = NULL,
  131. const SAFEARRAY *pPrivilegesRequired = NULL);
  132. ////////////////////////////////////////////////////////////////////////////////////
  133. // note: the following public functions are necessary to allow COM communication //
  134. // with CIMOM. Provider Implementors will not need to call these. //
  135. ////////////////////////////////////////////////////////////////////////////////////
  136. #ifndef NO_BASEINTERFACE_FUNCS
  137. /* IUnknown methods */
  138. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR *ppvObj) ;
  139. STDMETHOD_(ULONG, AddRef)(THIS) ;
  140. STDMETHOD_(ULONG, Release)(THIS) ;
  141. #endif
  142. virtual HRESULT STDMETHODCALLTYPE Initialize(
  143. /* [in] */ LPWSTR pszUser,
  144. /* [in] */ LONG lFlags,
  145. /* [in] */ LPWSTR pszNamespace,
  146. /* [in] */ LPWSTR pszLocale,
  147. /* [in] */ IWbemServices __RPC_FAR *pNamespace,
  148. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  149. /* [in] */ IWbemProviderInitSink __RPC_FAR *pInitSink
  150. );
  151. STDMETHOD(CreateInstanceEnumAsync)(THIS_
  152. /* [in] */ const BSTR Class,
  153. /* [in] */ long lFlags,
  154. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  155. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  156. );
  157. STDMETHOD(GetObjectAsync)( THIS_
  158. const BSTR ObjectPath,
  159. long lFlags,
  160. IWbemContext __RPC_FAR *pCtx,
  161. IWbemObjectSink __RPC_FAR *pResponseHandler
  162. );
  163. STDMETHOD(ExecQueryAsync)(THIS_
  164. /* [in] */ const BSTR QueryLanguage,
  165. /* [in] */ const BSTR Query,
  166. /* [in] */ long lFlags,
  167. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  168. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  169. );
  170. STDMETHOD(PutInstanceAsync)( THIS_
  171. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  172. /* [in] */ long lFlags,
  173. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  174. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  175. );
  176. STDMETHOD(DeleteInstanceAsync)(
  177. /* [in] */ const BSTR ObjectPath,
  178. /* [in] */ long lFlags,
  179. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  180. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  181. );
  182. STDMETHOD(ExecMethodAsync)( const BSTR,
  183. const BSTR,
  184. long,
  185. IWbemContext*,
  186. IWbemClassObject*,
  187. IWbemObjectSink*
  188. );
  189. // Unsupported service methods
  190. // ===========================
  191. STDMETHOD(OpenNamespace)(THIS_
  192. const BSTR Namespace,
  193. long lFlags,
  194. IWbemContext __RPC_FAR *pCtx,
  195. IWbemServices __RPC_FAR *__RPC_FAR *ppWorkingNamespace,
  196. IWbemCallResult __RPC_FAR *__RPC_FAR *ppResult
  197. )
  198. { return E_NOTIMPL; }
  199. STDMETHOD(PutClass)(IWbemClassObject __RPC_FAR *pObject,
  200. long lFlags,
  201. IWbemContext __RPC_FAR *pCtx,
  202. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  203. )
  204. {return E_NOTIMPL;}
  205. STDMETHOD(PutClassAsync)(
  206. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  207. /* [in] */ long lFlags,
  208. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  209. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  210. )
  211. {return E_NOTIMPL;}
  212. STDMETHOD(DeleteClass)(
  213. /* [in] */ const BSTR Class,
  214. /* [in] */ long lFlags,
  215. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  216. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  217. )
  218. {return E_NOTIMPL;}
  219. STDMETHOD(DeleteClassAsync)(
  220. /* [in] */ const BSTR Class,
  221. /* [in] */ long lFlags,
  222. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  223. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  224. )
  225. {return E_NOTIMPL;}
  226. STDMETHOD(CreateClassEnum)(
  227. /* [in] */ const BSTR Superclass,
  228. /* [in] */ long lFlags,
  229. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  230. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  231. )
  232. {return E_NOTIMPL;}
  233. STDMETHOD(CreateClassEnumAsync)(
  234. /* [in] */ const BSTR Superclass,
  235. /* [in] */ long lFlags,
  236. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  237. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  238. )
  239. {return E_NOTIMPL;}
  240. STDMETHOD(PutInstance)(
  241. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  242. /* [in] */ long lFlags,
  243. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  244. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  245. )
  246. {return E_NOTIMPL;}
  247. STDMETHOD(DeleteInstance)(
  248. /* [in] */ const BSTR ObjectPath,
  249. /* [in] */ long lFlags,
  250. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  251. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  252. )
  253. {return E_NOTIMPL;}
  254. STDMETHOD(CancelAsyncRequest)(THIS_ long lAsyncRequestHandle
  255. )
  256. {return E_NOTIMPL;}
  257. STDMETHOD(CancelAsyncCall)(IWbemObjectSink __RPC_FAR *pSink
  258. )
  259. {return E_NOTIMPL;}
  260. STDMETHOD(CreateInstanceEnum)(
  261. /* [in] */ const BSTR Class,
  262. /* [in] */ long lFlags,
  263. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  264. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  265. )
  266. {return E_NOTIMPL;}
  267. STDMETHOD(ExecQuery)(
  268. /* [in] */ const BSTR QueryLanguage,
  269. /* [in] */ const BSTR Query,
  270. /* [in] */ long lFlags,
  271. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  272. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  273. )
  274. {return E_NOTIMPL;}
  275. STDMETHOD(QueryObjectSink)(long lFlags,
  276. IWbemObjectSink __RPC_FAR *__RPC_FAR *ppResponseHandler
  277. )
  278. {return E_NOTIMPL;}
  279. STDMETHOD(GetObject)( const BSTR ObjectPath,
  280. long lFlags,
  281. IWbemContext __RPC_FAR *pCtx,
  282. IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject,
  283. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  284. )
  285. {return E_NOTIMPL;}
  286. STDMETHOD(ExecNotificationQuery)(
  287. /* [in] */ const BSTR QueryLanguage,
  288. /* [in] */ const BSTR Query,
  289. /* [in] */ long lFlags,
  290. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  291. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  292. )
  293. {return E_NOTIMPL;}
  294. STDMETHOD(ExecNotificationQueryAsync)(
  295. /* [in] */ const BSTR QueryLanguage,
  296. /* [in] */ const BSTR Query,
  297. /* [in] */ long lFlags,
  298. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  299. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  300. )
  301. {return E_NOTIMPL;}
  302. STDMETHOD(ExecMethod)(const BSTR,
  303. const BSTR,
  304. long,
  305. IWbemContext*,
  306. IWbemClassObject*,
  307. IWbemClassObject**,
  308. IWbemCallResult**
  309. )
  310. {return E_NOTIMPL;}
  311. CWbemProviderGlue();
  312. CWbemProviderGlue(PLONG pCount);
  313. ~CWbemProviderGlue(); // Destructor
  314. // used by the provider base class - you probably will never need to call this directly
  315. static IWbemServices *WINAPI GetNamespaceConnection( LPCWSTR NameSpace );
  316. static IWbemServices *WINAPI GetNamespaceConnection( LPCWSTR NameSpace, MethodContext *pMethodContext );
  317. // each provider class must log in and out with these in their constructors and destructors
  318. // this is done for you in the Provider base class
  319. static void WINAPI FrameworkLogin( LPCWSTR a_pszName,
  320. Provider *a_pProvider,
  321. LPCWSTR a_pszNameSpace );
  322. static void WINAPI FrameworkLogoff( LPCWSTR a_pszName,
  323. LPCWSTR a_pszNameSpace );
  324. static void WINAPI IncrementObjectCount(void);
  325. static LONG WINAPI DecrementObjectCount(void);
  326. static DWORD WINAPI GetOSMajorVersion() { return s_dwMajorVersion; }
  327. static DWORD WINAPI GetPlatform() { return s_dwPlatform; }
  328. static LPCWSTR WINAPI GetCSDVersion() { return s_wstrCSDVersion; }
  329. private:
  330. IWbemServices *WINAPI InternalGetNamespaceConnection( LPCWSTR NameSpace );
  331. static HRESULT WINAPI GetInstanceFromCIMOM( LPCWSTR pszObjectPath,
  332. LPCWSTR pszNameSpace,
  333. MethodContext *pMethodContext,
  334. CInstance **ppInstance );
  335. void FlushAll(void);
  336. static Provider *WINAPI SearchMapForProvider( LPCWSTR a_pszProviderName,
  337. LPCWSTR a_pszNamespace );
  338. static Provider *WINAPI AddProviderToMap( LPCWSTR a_pszProviderName,
  339. LPCWSTR a_strNamespace,
  340. Provider *a_pProvider );
  341. static void WINAPI LockProviderMap( void );
  342. static void WINAPI UnlockProviderMap( void );
  343. static void WINAPI LockFactoryMap( void );
  344. static void WINAPI UnlockFactoryMap( void );
  345. static IWbemClassObject *WINAPI GetStatusObject( MethodContext *pContext,
  346. LPCWSTR pNamespace);
  347. static void WINAPI Init( void );
  348. static void WINAPI UnInit( void );
  349. static void WINAPI GetComputerName( CHString& strComputerName );
  350. static HRESULT WINAPI CheckImpersonationLevel();
  351. HRESULT PreProcessPutInstanceParms(IWbemClassObject __RPC_FAR *pInstIn,
  352. IWbemClassObject __RPC_FAR **pInstOut,
  353. IWbemContext __RPC_FAR *pCtx);
  354. HRESULT NullOutUnsetProperties(IWbemClassObject __RPC_FAR *pInstIn,
  355. IWbemClassObject __RPC_FAR **pInstOut,
  356. const VARIANT& vValue);
  357. void AddFlushPtr(LPVOID pVoid);
  358. long m_lRefCount;
  359. CHString m_strNamespace;
  360. IWbemServices *m_pServices;
  361. static long s_lObjects; // number of objects out there - class factories & WbemGlues
  362. PLONG m_pCount;
  363. PROVIDERPTRS m_FlushPtrs;
  364. CCritSec m_csFlushPtrs;
  365. static STRING2LPVOID s_providersmap;
  366. static CCritSec s_csProviderMap;
  367. static CCritSec m_csStatusObject;
  368. static BOOL s_bInitted;
  369. static DWORD s_dwPlatform;
  370. static DWORD s_dwMajorVersion;
  371. static WCHAR s_wstrCSDVersion[_MAX_PATH];
  372. static IWbemClassObject *m_pStatusObject;
  373. static PTR2PLONG s_factorymap;
  374. static CCritSec s_csFactoryMap;
  375. protected:
  376. friend CWbemGlueFactory;
  377. static LONG IncrementMapCount(const CWbemGlueFactory *pGlue);
  378. static LONG IncrementMapCount(PLONG pCount);
  379. static LONG DecrementMapCount(const CWbemGlueFactory *pGlue);
  380. static LONG DecrementMapCount(PLONG pCount);
  381. static PLONG GetMapCountPtr(const CWbemGlueFactory *pGlue);
  382. static VOID AddToFactoryMap(const CWbemGlueFactory *pGlue, PLONG pdwRefCount);
  383. static VOID RemoveFromFactoryMap(const CWbemGlueFactory *pGlue);
  384. };
  385. inline void CWbemProviderGlue::LockProviderMap( void )
  386. {
  387. EnterCriticalSection( &s_csProviderMap );
  388. }
  389. inline void CWbemProviderGlue::UnlockProviderMap( void )
  390. {
  391. LeaveCriticalSection( &s_csProviderMap );
  392. }
  393. inline void CWbemProviderGlue::LockFactoryMap( void )
  394. {
  395. EnterCriticalSection( &s_csFactoryMap );
  396. }
  397. inline void CWbemProviderGlue::UnlockFactoryMap( void )
  398. {
  399. LeaveCriticalSection( &s_csFactoryMap );
  400. }
  401. class POLARITY CWbemGlueFactory : public IClassFactory
  402. {
  403. protected:
  404. long m_lRefCount;
  405. public:
  406. // Deprecated in favor of the constructor that takes a PLONG. This
  407. // must be the same PLONG that is passed to FrameworkLoginDLL &
  408. // FrameworkLogoffDLL.
  409. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  410. CWbemGlueFactory(void);
  411. #endif
  412. CWbemGlueFactory(PLONG plRefCount);
  413. ~CWbemGlueFactory(void);
  414. //IUnknown members
  415. STDMETHODIMP QueryInterface(REFIID, PPVOID);
  416. STDMETHODIMP_(ULONG) AddRef(void);
  417. STDMETHODIMP_(ULONG) Release(void);
  418. //IClassFactory members
  419. STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, PPVOID);
  420. STDMETHODIMP LockServer(BOOL);
  421. };
  422. typedef CWbemGlueFactory *PCWbemGlueFactory;
  423. #endif