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.

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