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.

258 lines
6.2 KiB

  1. // ProvInfo.h
  2. #pragma once
  3. #include <list>
  4. #include <map>
  5. #include <wstlallc.h>
  6. #include "NCDefs.h" // For IPostBuffer
  7. #include "buffer.h"
  8. #include "EventInfo.h"
  9. #include "QueryHelp.h" // For CBstrList
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CClientInfo
  12. class CNCProvider;
  13. class CProvInfo;
  14. class CEventInfoMap;
  15. _COM_SMARTPTR_TYPEDEF(IWbemEventSink, __uuidof(IWbemEventSink));
  16. _COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices));
  17. class CSinkInfo;
  18. class CClientInfo : public IPostBuffer
  19. {
  20. public:
  21. CEventInfoMap m_mapEvents;
  22. CNCProvider *m_pProvider;
  23. CClientInfo() :
  24. m_iRef(1)
  25. {
  26. }
  27. ULONG AddRef()
  28. {
  29. return InterlockedIncrement(&m_iRef);
  30. }
  31. ULONG Release()
  32. {
  33. LONG lRet = InterlockedDecrement(&m_iRef);
  34. if (!lRet)
  35. delete this;
  36. return lRet;
  37. }
  38. virtual HRESULT SendClientMessage(LPVOID pData, DWORD dwSize,
  39. BOOL bGetReply = FALSE) = 0;
  40. virtual ~CClientInfo();
  41. virtual BOOL ProcessClientInfo(CBuffer *pBuffer) = 0;
  42. virtual HRESULT PostBuffer(LPBYTE pData, DWORD dwSize);
  43. protected:
  44. LONG m_iRef;
  45. CSinkInfo *GetSinkInfo(DWORD dwID);
  46. };
  47. class CPipeClient;
  48. struct OLAP_AND_CLIENT
  49. {
  50. OVERLAPPED overlap;
  51. CPipeClient *pInfo;
  52. };
  53. class CPipeClient : public CClientInfo
  54. {
  55. public:
  56. // We have to do this because the completion routine won't let us pass
  57. // custom data along with the OVERLAPPED struct. We can't pass 'this'
  58. // because this first points to the junk found in CClientInfo. So, we
  59. // have to pass m_info, which is OVERLAPPED + this.
  60. OLAP_AND_CLIENT
  61. m_info;
  62. CBuffer m_bufferRecv;
  63. HANDLE m_hPipe,
  64. m_heventMsgReceived;
  65. HRESULT m_hrClientReply;
  66. CPipeClient(CNCProvider *pProvider, HANDLE hPipe);
  67. ~CPipeClient();
  68. HRESULT SendClientMessage(LPVOID pData, DWORD dwSize,
  69. BOOL bGetReply = FALSE);
  70. BOOL ProcessClientInfo(CBuffer *pBuffer);
  71. };
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CProvInfo
  74. typedef std::list<CClientInfo*, wbem_allocator<CClientInfo*> > CClientInfoList;
  75. typedef CClientInfoList::iterator CClientInfoListIterator;
  76. typedef std::map<_bstr_t, int, std::less<_bstr_t>, wbem_allocator<int> > CBstrToInt;
  77. typedef CBstrToInt::iterator CBstrToIntIterator;
  78. typedef std::map<int, int, std::less<int>, wbem_allocator<int> > CIntToIntMap;
  79. typedef CIntToIntMap::iterator CIntToIntMapIterator;
  80. class CSinkInfo :
  81. public IWbemEventProviderQuerySink
  82. {
  83. public:
  84. CSinkInfo(DWORD dwSinkID) :
  85. m_dwID(dwSinkID),
  86. m_lRef(1)
  87. {
  88. InitializeCriticalSection(&m_cs);
  89. }
  90. virtual ~CSinkInfo()
  91. {
  92. DeleteCriticalSection(&m_cs);
  93. }
  94. void SetNamespace(IWbemServices *pNamespace)
  95. {
  96. m_pNamespace = pNamespace;
  97. }
  98. IWbemServices *GetNamespace() { return m_pNamespace; }
  99. void SetSink(IWbemEventSink *pSink)
  100. {
  101. m_pSink = pSink;
  102. }
  103. IWbemEventSink *GetSink() { return m_pSink; }
  104. // IUnknown
  105. public:
  106. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID refid, PVOID *ppThis)
  107. {
  108. if (refid == IID_IUnknown || refid == IID_IWbemEventProviderQuerySink)
  109. {
  110. *ppThis = this;
  111. AddRef();
  112. return S_OK;
  113. }
  114. else
  115. return E_NOINTERFACE;
  116. }
  117. ULONG STDMETHODCALLTYPE AddRef()
  118. {
  119. return InterlockedIncrement(&m_lRef);
  120. }
  121. ULONG STDMETHODCALLTYPE Release()
  122. {
  123. LONG lRet = InterlockedDecrement(&m_lRef);
  124. if (!lRet)
  125. delete this;
  126. return lRet;
  127. }
  128. // IWbemEventProviderQuerySink
  129. public:
  130. HRESULT STDMETHODCALLTYPE NewQuery(
  131. /* [in] */ DWORD dwId,
  132. /* [in] */ WBEM_WSTR wszQueryLanguage,
  133. /* [in] */ WBEM_WSTR wszQuery);
  134. HRESULT STDMETHODCALLTYPE CancelQuery(
  135. /* [in] */ unsigned long dwId);
  136. // Implementation
  137. protected:
  138. typedef std::map<DWORD, CBstrList, std::less<DWORD>, wbem_allocator<CBstrList> > CQueryToClassMap;
  139. typedef CQueryToClassMap::iterator CQueryToClassMapIterator;
  140. IWbemServicesPtr m_pNamespace;
  141. IWbemEventSinkPtr m_pSink;
  142. CBstrToInt m_mapEnabledClasses;
  143. CQueryToClassMap m_mapQueries;
  144. DWORD m_dwID;
  145. LONG m_lRef;
  146. CRITICAL_SECTION m_cs;
  147. void Lock() { EnterCriticalSection(&m_cs); }
  148. void Unlock() { LeaveCriticalSection(&m_cs); }
  149. int AddClassRef(LPCWSTR szClass);
  150. int RemoveClassRef(LPCWSTR szClass);
  151. BOOL BuildClassDescendentList(
  152. LPCWSTR szClass,
  153. CBstrList &listClasses);
  154. virtual DWORD GetClientCount() = 0;
  155. virtual HRESULT SendMessageToClients(LPBYTE pData, DWORD dwSize, BOOL bGetReply) = 0;
  156. };
  157. class CRestrictedSink : public CSinkInfo
  158. {
  159. public:
  160. CRestrictedSink(DWORD dwID, CClientInfo *pInfo);
  161. protected:
  162. CClientInfo *m_pInfo;
  163. virtual DWORD GetClientCount() { return 1; }
  164. virtual HRESULT SendMessageToClients(LPBYTE pData, DWORD dwSize, BOOL bGetReply)
  165. {
  166. return m_pInfo->SendClientMessage(pData, dwSize, bGetReply);
  167. }
  168. };
  169. class CProvInfo : public CSinkInfo
  170. {
  171. public:
  172. _bstr_t m_strName,
  173. m_strBaseName,
  174. m_strBaseNamespace;
  175. HRESULT m_hrClientMsgResult;
  176. CProvInfo();
  177. ~CProvInfo();
  178. // Called when the provider finds out its name.
  179. BOOL Init(LPCWSTR szNamespace, LPCWSTR szProvider);
  180. // Functions called as clients connect/disconnect with pipe.
  181. void AddClient(CClientInfo *pInfo);
  182. void RemoveClient(CClientInfo *pInfo);
  183. HRESULT STDMETHODCALLTYPE AccessCheck(
  184. LPCWSTR szLang,
  185. LPCWSTR szQuery,
  186. DWORD dwSidLen,
  187. LPBYTE pSid);
  188. protected:
  189. CClientInfoList m_listClients;
  190. HANDLE m_heventProviderReady;
  191. HRESULT GetProviderDacl(IWbemServices *pNamespace, BYTE** pDacl);
  192. virtual DWORD GetClientCount()
  193. {
  194. return m_listClients.size();
  195. }
  196. virtual HRESULT SendMessageToClients(LPBYTE pData, DWORD dwSize, BOOL bGetReply);
  197. };