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.

219 lines
7.7 KiB

  1. //=============================================================================
  2. //
  3. // Copyright (c) 1996-1999, Microsoft Corporation, All rights reserved
  4. //
  5. // ESSSINK.H
  6. //
  7. // This files defines the class that implements IWbemObjectSink for the ESS.
  8. //
  9. // Classes defined:
  10. //
  11. // CEssObjectSink
  12. //
  13. // History:
  14. //
  15. // 11/27/96 a-levn Compiles
  16. //
  17. //=============================================================================
  18. #ifndef __ESSSINK__H_
  19. #define __ESSSINK__H_
  20. #include <wbemidl.h>
  21. #include <wbemint.h>
  22. #include <unk.h>
  23. #include <comutl.h>
  24. #include "parmdefs.h"
  25. #include "essutils.h"
  26. //*****************************************************************************
  27. //
  28. // class CEssObjectSink
  29. //
  30. // This class implements IWbemObjectSink interface for ESS, including the
  31. // automation part. A pointer to this object is given to WinMgmt at startup
  32. // and it serves as the only communication port into the ESS.
  33. //
  34. //*****************************************************************************
  35. class CEss;
  36. class CEssObjectSink : public CUnk
  37. {
  38. private:
  39. CEss* m_pEss;
  40. BOOL m_bShutdown;
  41. CEssSharedLock m_Lock;
  42. _IWmiCoreServices* m_pCoreServices;
  43. IClassFactory *m_pIFactory;
  44. //
  45. // Since we rely on wbem context to contain information about reentrant
  46. // calls, we need to ensure that an external client cannot fool us.
  47. // Since reentrant calls can only be made on behalf of an event provider
  48. // and since event providers are local and trusted, we can detect
  49. // rogue wbem contexts by checking for the presence of a random value
  50. // in the context. Only a local provider and us would ever know this
  51. // secret value and since local providers never share the contexts with
  52. // other non-trusted parties, we can set the secret value in the context
  53. // and verify the secret value on reentrant calls.
  54. //
  55. #define SECRET_SIZE 16
  56. BYTE m_achSecretBytes[SECRET_SIZE];
  57. HRESULT SetSecret( IWbemContext* pContext );
  58. HRESULT VerifySecret( IWbemContext* pContext );
  59. HRESULT PrepareCurrentEssThreadObject( IWbemContext* pContext );
  60. protected:
  61. typedef CImpl<IWbemEventSubsystem_m4, CEssObjectSink> TImplESS;
  62. class XESS : public TImplESS
  63. {
  64. public:
  65. XESS(CEssObjectSink* pObject) : TImplESS(pObject)
  66. {}
  67. STDMETHOD(ProcessInternalEvent)(long lSendType, LPCWSTR str1, LPCWSTR str2,
  68. LPCWSTR str3, DWORD dw1, DWORD dw2, DWORD dwObjectCount,
  69. _IWmiObject** apObjects, IWbemContext* pContext);
  70. STDMETHOD(VerifyInternalEvent)(long lSendType, LPCWSTR str1, LPCWSTR str2,
  71. LPCWSTR str3, DWORD dw1, DWORD dw2, DWORD dwObjectCount,
  72. _IWmiObject** apObjects, IWbemContext* pContext);
  73. STDMETHOD(SetStatus)(long, long, BSTR, IWbemClassObject*)
  74. {return WBEM_S_NO_ERROR;}
  75. STDMETHOD(RegisterNotificationSink)(LPCWSTR wszNamespace,
  76. LPCWSTR wszQueryLanguage, LPCWSTR wszQuery, long lFlags,
  77. IWbemContext* pContext, IWbemObjectSink* pSink);
  78. STDMETHOD(RemoveNotificationSink)(IWbemObjectSink* pSink);
  79. STDMETHOD(GetNamespaceSink)(LPCWSTR wszNamespace,
  80. IWbemObjectSink** ppSink);
  81. STDMETHOD(Initialize)(LPCWSTR wszServer, IWbemLocator* pAdminLocator,
  82. IUnknown* pServices);
  83. STDMETHOD(Shutdown)();
  84. STDMETHOD(LastCallForCore)(LONG lSystemShutDown);
  85. } m_XESS;
  86. friend XESS;
  87. typedef CImpl<_IWmiESS, CEssObjectSink> TImplNewESS;
  88. class XNewESS : public TImplNewESS
  89. {
  90. public:
  91. XNewESS(CEssObjectSink* pObject) : TImplNewESS(pObject)
  92. {}
  93. STDMETHOD(Initialize)(long lFlags, IWbemContext* pCtx,
  94. _IWmiCoreServices* pServices);
  95. STDMETHOD(ExecNotificationQuery)(LPCWSTR wszNamespace,
  96. LPCWSTR wszQueryText, long lFlags,
  97. IWbemContext* pContext, IWbemObjectSink* pSink);
  98. STDMETHOD(CancelAsyncCall)(IWbemObjectSink* pSink);
  99. STDMETHOD(QueryObjectSink)(LPCWSTR wszNamespace,
  100. IWbemObjectSink** ppSink);
  101. } m_XNewESS;
  102. friend XNewESS;
  103. typedef CImpl<IWbemShutdown, CEssObjectSink> TImplShutdown;
  104. class XShutdown : public TImplShutdown
  105. {
  106. public:
  107. XShutdown(CEssObjectSink* pObject) : TImplShutdown(pObject)
  108. {}
  109. STDMETHOD(Shutdown)( long lFlags,
  110. ULONG uMaxMilliseconds,
  111. IWbemContext* pCtx );
  112. } m_XShutdown;
  113. friend XShutdown;
  114. typedef CImpl<_IWmiCoreWriteHook, CEssObjectSink> TImplHook;
  115. class XHook : public TImplHook
  116. {
  117. public:
  118. XHook(CEssObjectSink* pObject) : TImplHook(pObject)
  119. {}
  120. STDMETHOD(PrePut)(long lFlags, long lUserFlags, IWbemContext* pContext,
  121. IWbemPath* pPath, LPCWSTR wszNamespace,
  122. LPCWSTR wszClass, _IWmiObject* pCopy);
  123. STDMETHOD(PostPut)(long lFlags, HRESULT hApiResult,
  124. IWbemContext* pContext,
  125. IWbemPath* pPath, LPCWSTR wszNamespace,
  126. LPCWSTR wszClass, _IWmiObject* pNew,
  127. _IWmiObject* pOld);
  128. STDMETHOD(PreDelete)(long lFlags, long lUserFlags,
  129. IWbemContext* pContext,
  130. IWbemPath* pPath, LPCWSTR wszNamespace,
  131. LPCWSTR wszClass);
  132. STDMETHOD(PostDelete)(long lFlags, HRESULT hApiResult,
  133. IWbemContext* pContext,
  134. IWbemPath* pPath, LPCWSTR wszNamespace,
  135. LPCWSTR wszClass, _IWmiObject* pOld);
  136. } m_XHook;
  137. friend XHook;
  138. public:
  139. CEssObjectSink(CLifeControl* pControl, IUnknown* pOuter = NULL);
  140. ~CEssObjectSink();
  141. void* GetInterface(REFIID riid);
  142. };
  143. class CEssNamespaceSink : public CUnk
  144. {
  145. CEss* m_pEss;
  146. BSTR m_strNamespace;
  147. protected:
  148. typedef CImpl<IWbemObjectSink, CEssNamespaceSink> TImplSink;
  149. class XSink : public TImplSink
  150. {
  151. public:
  152. XSink(CEssNamespaceSink* pObject) : TImplSink(pObject){}
  153. STDMETHOD(Indicate)(long lObjectCount, IWbemClassObject** pObjArray);
  154. STDMETHOD(SetStatus)(long, long, BSTR, IWbemClassObject*)
  155. {return WBEM_S_NO_ERROR;}
  156. } m_XSink;
  157. friend XSink;
  158. public:
  159. CEssNamespaceSink(CEss* pEss, CLifeControl* pControl,
  160. IUnknown* pOuter = NULL);
  161. HRESULT Initialize(LPCWSTR wszNamespace);
  162. ~CEssNamespaceSink();
  163. void* GetInterface(REFIID riid);
  164. };
  165. /****************************************************************************
  166. CEssInternalOperationSink
  167. This sink handles the setting up of a new ess thread object and then
  168. delegates calls to the specified sink. The purpose of this is so that
  169. internal ess operations can be performed asynchronously. For example,
  170. for class change notifications we register a sink that reactivates the
  171. associated filter. In order to actually perform the reactivation, the
  172. calling thread must be set up appropriately.
  173. *****************************************************************************/
  174. class CEssInternalOperationSink
  175. : public CUnkBase< IWbemObjectSink, &IID_IWbemObjectSink >
  176. {
  177. CWbemPtr<IWbemObjectSink> m_pSink;
  178. public:
  179. CEssInternalOperationSink( IWbemObjectSink* pSink ) : m_pSink( pSink ) {}
  180. STDMETHOD(Indicate)( long cObjects, IWbemClassObject** ppObjs );
  181. STDMETHOD(SetStatus)(long, long, BSTR, IWbemClassObject*);
  182. };
  183. #endif