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.

500 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // NtRkComm.h
  7. //
  8. // Implementation File:
  9. // NtRkComm.cpp
  10. //
  11. // Description:
  12. // Definition of the CWbemServices, CImpersonatedProvider and
  13. // CInstanceMgr class.
  14. //
  15. // Author:
  16. // Henry Wang (HenryWa) 24-AUG-1999
  17. //
  18. // Notes:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////
  21. #pragma once
  22. #pragma warning( disable : 4100 )
  23. //////////////////////////////////////////////////////////////////////////////
  24. // Include Files
  25. //////////////////////////////////////////////////////////////////////////////
  26. #include <wbemprov.h>
  27. #include <objbase.h>
  28. typedef LPVOID * PPVOID;
  29. //////////////////////////////////////////////////////////////////////////////
  30. //++
  31. //
  32. // class CWbemServices
  33. //
  34. // Description:
  35. // Wraps for IWbemServices. security impersonation is implemented here
  36. //
  37. //--
  38. //////////////////////////////////////////////////////////////////////////////
  39. class CWbemServices
  40. {
  41. protected:
  42. IWbemServices * m_pWbemServices;
  43. public:
  44. CWbemServices() : m_pWbemServices( NULL ) { };
  45. CWbemServices( IWbemServices * );
  46. virtual ~CWbemServices( void );
  47. HRESULT STDMETHODCALLTYPE GetObject(
  48. BSTR bstrObjectPathIn,
  49. long lFlagsIn,
  50. IWbemContext * pCtxIn,
  51. IWbemClassObject ** ppObjectInout,
  52. IWbemCallResult ** ppCallResultInout
  53. );
  54. HRESULT STDMETHODCALLTYPE PutClass(
  55. IWbemClassObject * pObjectIn,
  56. long lFlagsIn,
  57. IWbemContext * pCtxIn,
  58. IWbemCallResult ** ppCallResultInout
  59. );
  60. HRESULT STDMETHODCALLTYPE DeleteClass(
  61. BSTR bstrClassIn,
  62. long lFlagsIn,
  63. IWbemContext * pCtxIn,
  64. IWbemCallResult ** ppCallResultInout
  65. );
  66. HRESULT STDMETHODCALLTYPE CreateClassEnum(
  67. BSTR bstrSuperclassIn,
  68. long lFlagsIn,
  69. IWbemContext * pCtxIn,
  70. IEnumWbemClassObject ** ppEnumOut
  71. );
  72. HRESULT STDMETHODCALLTYPE PutInstance(
  73. IWbemClassObject * pInstIn,
  74. long lFlagsIn,
  75. IWbemContext * pCtxIn,
  76. IWbemCallResult ** ppCallResultInout
  77. );
  78. HRESULT STDMETHODCALLTYPE DeleteInstance(
  79. BSTR bstrObjectPathIn,
  80. long lFlagsIn,
  81. IWbemContext * pCtxIn,
  82. IWbemCallResult ** ppCallResultInout
  83. );
  84. HRESULT STDMETHODCALLTYPE CreateInstanceEnum(
  85. BSTR bstrClassIn,
  86. long lFlagsIn,
  87. IWbemContext * pCtxIn,
  88. IEnumWbemClassObject ** ppEnumOut
  89. );
  90. HRESULT STDMETHODCALLTYPE ExecQuery(
  91. BSTR bstrQueryLanguageIn,
  92. BSTR bstrQueryIn,
  93. long lFlagsIn,
  94. IWbemContext * pCtxIn,
  95. IEnumWbemClassObject ** ppEnumOut
  96. );
  97. HRESULT STDMETHODCALLTYPE ExecNotificationQuery(
  98. BSTR bstrQueryLanguageIn,
  99. BSTR bstrQueryIn,
  100. long lFlagsIn,
  101. IWbemContext * pCtxIn,
  102. IEnumWbemClassObject ** ppEnumOut
  103. );
  104. HRESULT STDMETHODCALLTYPE ExecMethod(
  105. BSTR bstrObjectPathIn,
  106. BSTR bstrMethodNameIn,
  107. long lFlagsIn,
  108. IWbemContext * pCtxIn,
  109. IWbemClassObject * pInParamsIn,
  110. IWbemClassObject ** ppOurParamsOut,
  111. IWbemCallResult ** ppCallResultOut
  112. );
  113. HRESULT STDMETHODCALLTYPE ExecMethodAsync(
  114. BSTR bstrObjectPathIn,
  115. BSTR bstrMethodNameIn,
  116. long lFlagsIn,
  117. IWbemContext * pCtxIn,
  118. IWbemClassObject * pInParamsIn,
  119. IWbemObjectSink * pHandlerIn
  120. );
  121. IWbemServices ** operator & ()
  122. {
  123. return & m_pWbemServices ;
  124. }
  125. operator IWbemServices * ()
  126. {
  127. return m_pWbemServices;
  128. }
  129. CWbemServices & operator = ( CWbemServices * );
  130. }; //*** class CWbemServices
  131. //////////////////////////////////////////////////////////////////////////////
  132. //++
  133. //
  134. // class CImpersonatedProvider
  135. //
  136. // Description:
  137. // a middle layer between IWbemservices and actual provider. It takes
  138. // care of security impersonation
  139. //
  140. //--
  141. //////////////////////////////////////////////////////////////////////////////
  142. class CImpersonatedProvider
  143. : public IWbemServices
  144. , public IWbemProviderInit
  145. {
  146. protected:
  147. ULONG m_cRef; //Object reference count
  148. CWbemServices * m_pNamespace;
  149. public:
  150. CImpersonatedProvider(
  151. BSTR bstrObjectPathIn = NULL,
  152. BSTR bstrUserIn = NULL,
  153. BSTR bstrPasswordIn = NULL,
  154. IWbemContext * pCtxIn = NULL
  155. );
  156. virtual ~CImpersonatedProvider( void );
  157. //Non-delegating object IUnknown
  158. STDMETHODIMP QueryInterface( REFIID riid, PPVOID ppv );
  159. STDMETHODIMP_( ULONG ) AddRef( void );
  160. STDMETHODIMP_( ULONG ) Release( void );
  161. //IWbemProviderInit
  162. HRESULT STDMETHODCALLTYPE Initialize(
  163. LPWSTR pszUserIn,
  164. LONG lFlagsIn,
  165. LPWSTR pszNamespaceIn,
  166. LPWSTR pszLocaleIn,
  167. IWbemServices * pNamespaceIn,
  168. IWbemContext * pCtxIn,
  169. IWbemProviderInitSink * pInitSinkIn
  170. );
  171. //IWbemServices
  172. HRESULT STDMETHODCALLTYPE OpenNamespace(
  173. const BSTR bstrNamespaceIn,
  174. long lFlagsIn,
  175. IWbemContext * pCtxIn,
  176. IWbemServices ** ppWorkingNamespaceInout,
  177. IWbemCallResult ** ppResultInout
  178. )
  179. {
  180. return WBEM_E_NOT_SUPPORTED;
  181. }
  182. HRESULT STDMETHODCALLTYPE CancelAsyncCall(
  183. IWbemObjectSink * pSinkIn
  184. )
  185. {
  186. return WBEM_E_NOT_SUPPORTED;
  187. }
  188. HRESULT STDMETHODCALLTYPE QueryObjectSink(
  189. long lFlagsIn,
  190. IWbemObjectSink ** ppResponseHandlerOut
  191. )
  192. {
  193. return WBEM_E_NOT_SUPPORTED;
  194. }
  195. HRESULT STDMETHODCALLTYPE GetObject(
  196. const BSTR bstrObjectPathIn,
  197. long lFlagsIn,
  198. IWbemContext * pCtxIn,
  199. IWbemClassObject ** ppObjectInout,
  200. IWbemCallResult ** ppCallResultInout
  201. )
  202. {
  203. return WBEM_E_NOT_SUPPORTED;
  204. }
  205. HRESULT STDMETHODCALLTYPE GetObjectAsync(
  206. const BSTR bstrObjectPathIn,
  207. long lFlagsIn,
  208. IWbemContext * pCtxIn,
  209. IWbemObjectSink * pResponseHandlerIn
  210. );
  211. HRESULT STDMETHODCALLTYPE PutClass(
  212. IWbemClassObject * pObjectIn,
  213. long lFlagsIn,
  214. IWbemContext * pCtxIn,
  215. IWbemCallResult ** ppCallResultInout
  216. )
  217. {
  218. return WBEM_E_NOT_SUPPORTED;
  219. }
  220. HRESULT STDMETHODCALLTYPE PutClassAsync(
  221. IWbemClassObject * pObjectIn,
  222. long lFlagsIn,
  223. IWbemContext * pCtxIn,
  224. IWbemObjectSink * pResponseHandlerIn
  225. )
  226. {
  227. return WBEM_E_NOT_SUPPORTED;
  228. }
  229. HRESULT STDMETHODCALLTYPE DeleteClass(
  230. const BSTR bstrClassIn,
  231. long lFlagsIn,
  232. IWbemContext * pCtxIn,
  233. IWbemCallResult ** ppCallResultInout
  234. )
  235. {
  236. return WBEM_E_NOT_SUPPORTED;
  237. }
  238. HRESULT STDMETHODCALLTYPE DeleteClassAsync(
  239. const BSTR bstrClassIn,
  240. long lFlagsIn,
  241. IWbemContext * pCtxIn,
  242. IWbemObjectSink * pResponseHandlerIn
  243. )
  244. {
  245. return WBEM_E_NOT_SUPPORTED;
  246. }
  247. HRESULT STDMETHODCALLTYPE CreateClassEnum(
  248. const BSTR bstrSuperclassIn,
  249. long lFlagsIn,
  250. IWbemContext * pCtxIn,
  251. IEnumWbemClassObject ** ppEnumOut
  252. )
  253. {
  254. return WBEM_E_NOT_SUPPORTED;
  255. }
  256. HRESULT STDMETHODCALLTYPE CreateClassEnumAsync(
  257. const BSTR bstrSuperclassIn,
  258. long lFlagsIn,
  259. IWbemContext * pCtxIn,
  260. IWbemObjectSink * pResponseHandlerIn
  261. )
  262. {
  263. return WBEM_E_NOT_SUPPORTED;
  264. }
  265. HRESULT STDMETHODCALLTYPE PutInstance(
  266. IWbemClassObject * pInstIn,
  267. long lFlagsIn,
  268. IWbemContext * pCtxIn,
  269. IWbemCallResult ** ppCallResultInout
  270. )
  271. {
  272. return WBEM_E_NOT_SUPPORTED;
  273. }
  274. HRESULT STDMETHODCALLTYPE PutInstanceAsync(
  275. IWbemClassObject * pInstIn,
  276. long lFlagsIn,
  277. IWbemContext * pCtxIn,
  278. IWbemObjectSink * pResponseHandlerIn
  279. );
  280. HRESULT STDMETHODCALLTYPE DeleteInstance(
  281. const BSTR bstrObjectPathIn,
  282. long lFlagsIn,
  283. IWbemContext * pCtxIn,
  284. IWbemCallResult ** ppCallResultInout
  285. )
  286. {
  287. return WBEM_E_NOT_SUPPORTED;
  288. }
  289. HRESULT STDMETHODCALLTYPE DeleteInstanceAsync(
  290. const BSTR bstrObjectPathIn,
  291. long lFlagsIn,
  292. IWbemContext * pCtxIn,
  293. IWbemObjectSink * pResponseHandlerIn
  294. );
  295. HRESULT STDMETHODCALLTYPE CreateInstanceEnum(
  296. const BSTR bstrClassIn,
  297. long lFlagsIn,
  298. IWbemContext * pCtxIn,
  299. IEnumWbemClassObject ** ppEnumOut
  300. )
  301. {
  302. return WBEM_E_NOT_SUPPORTED;
  303. }
  304. HRESULT STDMETHODCALLTYPE CreateInstanceEnumAsync(
  305. const BSTR bstrClassIn,
  306. long lFlagsIn,
  307. IWbemContext * pCtxIn,
  308. IWbemObjectSink * pResponseHandlerIn
  309. );
  310. HRESULT STDMETHODCALLTYPE ExecQuery(
  311. const BSTR bstrQueryLanguageIn,
  312. const BSTR bstrQueryIn,
  313. long lFlagsIn,
  314. IWbemContext * pCtxIn,
  315. IEnumWbemClassObject ** ppEnumOut
  316. )
  317. {
  318. return WBEM_E_NOT_SUPPORTED;
  319. }
  320. HRESULT STDMETHODCALLTYPE ExecQueryAsync(
  321. const BSTR bstrQueryLanguageIn,
  322. const BSTR bstrQueryIn,
  323. long lFlagsIn,
  324. IWbemContext * pCtxIn,
  325. IWbemObjectSink * pResponseHandlerIn
  326. );
  327. HRESULT STDMETHODCALLTYPE ExecNotificationQuery(
  328. const BSTR bstrQueryLanguageIn,
  329. const BSTR bstrQueryIn,
  330. long lFlagsIn,
  331. IWbemContext* pCtxIn,
  332. IEnumWbemClassObject ** ppEnumOut
  333. )
  334. {
  335. return WBEM_E_NOT_SUPPORTED;
  336. }
  337. HRESULT STDMETHODCALLTYPE ExecNotificationQueryAsync(
  338. const BSTR bstrQueryLanguageIn,
  339. const BSTR bstrQueryIn,
  340. long lFlagsIn,
  341. IWbemContext * pCtxIn,
  342. IWbemObjectSink * pResponseHandlerIn
  343. )
  344. {
  345. return WBEM_E_NOT_SUPPORTED;
  346. }
  347. HRESULT STDMETHODCALLTYPE ExecMethod(
  348. const BSTR bstrObjectPathIn,
  349. const BSTR bstrMethodNameIn,
  350. long lFlagsIn,
  351. IWbemContext * pCtxIn,
  352. IWbemClassObject * pInParamsIn,
  353. IWbemClassObject ** ppOurParamsOut,
  354. IWbemCallResult ** ppCallResultOut
  355. )
  356. {
  357. return WBEM_E_NOT_SUPPORTED;
  358. }
  359. HRESULT STDMETHODCALLTYPE ExecMethodAsync(
  360. const BSTR bstrObjectPathIn,
  361. const BSTR bstrMethodNameIn,
  362. long lFlagsIn,
  363. IWbemContext * pCtxIn,
  364. IWbemClassObject * pInParamsIn,
  365. IWbemObjectSink * pResponseHandlerIn
  366. );
  367. protected:
  368. virtual HRESULT STDMETHODCALLTYPE DoCreateInstanceEnumAsync(
  369. BSTR bstrRefStrIn,
  370. long lFlagsIn,
  371. IWbemContext * pCtxIn,
  372. IWbemObjectSink * pHandlerIn
  373. ) = 0;
  374. virtual HRESULT STDMETHODCALLTYPE DoDeleteInstanceAsync(
  375. BSTR bstrObjectPathIn,
  376. long lFlagsIn,
  377. IWbemContext * pCtxIn,
  378. IWbemObjectSink * pHandlerIn
  379. ) = 0;
  380. virtual HRESULT STDMETHODCALLTYPE DoExecMethodAsync(
  381. BSTR bstrObjectPathIn,
  382. BSTR bstrMethodNameIn,
  383. long lFlagsIn,
  384. IWbemContext * pCtxIn,
  385. IWbemClassObject * pInParamsIn,
  386. IWbemObjectSink * pHandlerIn
  387. ) = 0;
  388. virtual HRESULT STDMETHODCALLTYPE DoExecQueryAsync(
  389. BSTR bstrQueryLanguageIn,
  390. BSTR bstrQueryIn,
  391. long lFlagsIn,
  392. IWbemContext * pCtxIn,
  393. IWbemObjectSink * pHandlerIn
  394. ) = 0;
  395. virtual HRESULT STDMETHODCALLTYPE DoGetObjectAsync(
  396. BSTR bstrObjectPathIn,
  397. long lFlagsIn,
  398. IWbemContext * pCtxIn,
  399. IWbemObjectSink FAR * pHandlerIn
  400. ) = 0;
  401. virtual HRESULT STDMETHODCALLTYPE DoPutInstanceAsync(
  402. IWbemClassObject * pInstIn,
  403. long lFlagsIn,
  404. IWbemContext * pCtxIn,
  405. IWbemObjectSink * pHandlerIn
  406. ) = 0;
  407. }; //*** class CImpersonatedProvider
  408. //////////////////////////////////////////////////////////////////////////////
  409. //++
  410. //
  411. // class CWbemInstanceMgr
  412. //
  413. // Description:
  414. // Manage WMI instance, allow block indicate
  415. //
  416. //--
  417. //////////////////////////////////////////////////////////////////////////////
  418. class CWbemInstanceMgr
  419. {
  420. protected:
  421. IWbemObjectSink * m_pSink;
  422. IWbemClassObject ** m_ppInst;
  423. DWORD m_dwThreshHold;
  424. DWORD m_dwIndex;
  425. public:
  426. CWbemInstanceMgr(
  427. IWbemObjectSink * pHandlerIn,
  428. DWORD dwSizeIn = 50
  429. );
  430. virtual ~CWbemInstanceMgr( void );
  431. void Indicate(
  432. IN IWbemClassObject * pInst
  433. );
  434. void SetStatus(
  435. LONG lFlagsIn,
  436. HRESULT hrIn,
  437. BSTR bstrParamIn,
  438. IWbemClassObject * pObjParamIn
  439. );
  440. }; //*** class CWbemInstanceMgr