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.

338 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. WbemServices.cpp
  5. Abstract:
  6. Implementation of:
  7. CWbemServices
  8. Author:
  9. ???
  10. Revision History:
  11. Mohit Srivastava 10-Nov-2000
  12. --*/
  13. #include "WbemServices.h"
  14. #include <wbemprov.h>
  15. #include <dbgutil.h>
  16. CWbemServices::CWbemServices(
  17. IWbemServices* pNamespace)
  18. :m_pWbemServices(NULL)
  19. {
  20. m_pWbemServices = pNamespace;
  21. if(m_pWbemServices != NULL)
  22. {
  23. m_pWbemServices->AddRef();
  24. }
  25. }
  26. CWbemServices::~CWbemServices()
  27. {
  28. if(m_pWbemServices != NULL)
  29. {
  30. m_pWbemServices->Release();
  31. m_pWbemServices = NULL;
  32. }
  33. }
  34. HRESULT
  35. CWbemServices::CreateClassEnum(
  36. /* [in] */ const BSTR Superclass,
  37. /* [in] */ long lFlags,
  38. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  39. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  40. )
  41. {
  42. DBG_ASSERT(m_pWbemServices != NULL);
  43. if(ppEnum)
  44. {
  45. *ppEnum = NULL;
  46. }
  47. SCODE sc = m_pWbemServices->CreateClassEnum(
  48. Superclass,
  49. lFlags,
  50. pCtx,
  51. ppEnum);
  52. HRESULT cichr = CoImpersonateClient();
  53. if (FAILED(cichr))
  54. {
  55. return cichr;
  56. }
  57. return sc;
  58. }
  59. HRESULT
  60. CWbemServices::CreateInstanceEnum(
  61. /* [in] */ const BSTR Class,
  62. /* [in] */ long lFlags,
  63. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  64. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum)
  65. {
  66. DBG_ASSERT(m_pWbemServices != NULL);
  67. if(ppEnum)
  68. {
  69. *ppEnum = NULL;
  70. }
  71. HRESULT hr = m_pWbemServices->CreateInstanceEnum(
  72. Class,
  73. lFlags,
  74. pCtx,
  75. ppEnum);
  76. HRESULT cichr = CoImpersonateClient();
  77. if (FAILED(cichr))
  78. {
  79. return cichr;
  80. }
  81. return hr;
  82. }
  83. HRESULT
  84. CWbemServices::DeleteClass(
  85. /* [in] */ const BSTR Class,
  86. /* [in] */ long lFlags,
  87. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  88. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult)
  89. {
  90. DBG_ASSERT(m_pWbemServices != NULL);
  91. if(ppCallResult)
  92. {
  93. *ppCallResult = NULL;
  94. }
  95. HRESULT hr = m_pWbemServices->DeleteClass(
  96. Class,
  97. lFlags,
  98. pCtx,
  99. ppCallResult);
  100. HRESULT cichr = CoImpersonateClient();
  101. if (FAILED(cichr))
  102. {
  103. return cichr;
  104. }
  105. return hr;
  106. }
  107. HRESULT
  108. CWbemServices::DeleteInstance(
  109. /* [in] */ const BSTR ObjectPath,
  110. /* [in] */ long lFlags,
  111. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  112. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult)
  113. {
  114. DBG_ASSERT(m_pWbemServices != NULL);
  115. if(ppCallResult)
  116. {
  117. *ppCallResult = NULL;
  118. }
  119. HRESULT hr = m_pWbemServices->DeleteInstance(
  120. ObjectPath,
  121. lFlags,
  122. pCtx,
  123. ppCallResult);
  124. HRESULT cichr = CoImpersonateClient();
  125. if (FAILED(cichr))
  126. {
  127. return cichr;
  128. }
  129. return hr;
  130. }
  131. HRESULT
  132. CWbemServices::ExecMethod(
  133. const BSTR strObjectPath,
  134. const BSTR MethodName,
  135. long lFlags,
  136. IWbemContext* pCtx,
  137. IWbemClassObject* pInParams,
  138. IWbemClassObject** ppOurParams,
  139. IWbemCallResult** ppCallResult)
  140. {
  141. DBG_ASSERT(m_pWbemServices != NULL);
  142. if(ppOurParams)
  143. {
  144. *ppOurParams = NULL;
  145. }
  146. if(ppCallResult)
  147. {
  148. *ppCallResult = NULL;
  149. }
  150. HRESULT hr = m_pWbemServices->ExecMethod(
  151. strObjectPath,
  152. MethodName,
  153. lFlags,
  154. pCtx,
  155. pInParams,
  156. ppOurParams,
  157. ppCallResult) ;
  158. HRESULT cichr = CoImpersonateClient();
  159. if (FAILED(cichr))
  160. {
  161. return cichr;
  162. }
  163. return hr;
  164. }
  165. HRESULT
  166. CWbemServices::ExecNotificationQuery(
  167. /* [in] */ const BSTR QueryLanguage,
  168. /* [in] */ const BSTR Query,
  169. /* [in] */ long lFlags,
  170. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  171. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum)
  172. {
  173. DBG_ASSERT(m_pWbemServices != NULL);
  174. if(ppEnum)
  175. {
  176. *ppEnum = NULL;
  177. }
  178. HRESULT hr = m_pWbemServices->ExecNotificationQuery(
  179. QueryLanguage,
  180. Query,
  181. lFlags,
  182. pCtx,
  183. ppEnum);
  184. HRESULT cichr = CoImpersonateClient();
  185. if (FAILED(cichr))
  186. {
  187. return cichr;
  188. }
  189. return hr;
  190. }
  191. HRESULT
  192. CWbemServices::ExecQuery(
  193. /* [in] */ const BSTR QueryLanguage,
  194. /* [in] */ const BSTR Query,
  195. /* [in] */ long lFlags,
  196. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  197. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum)
  198. {
  199. DBG_ASSERT(m_pWbemServices != NULL);
  200. if(ppEnum)
  201. {
  202. *ppEnum = NULL;
  203. }
  204. HRESULT hr = m_pWbemServices->ExecQuery(
  205. QueryLanguage,
  206. Query,
  207. lFlags,
  208. pCtx,
  209. ppEnum);
  210. HRESULT cichr = CoImpersonateClient();
  211. if (FAILED(cichr))
  212. {
  213. return cichr;
  214. }
  215. return hr;
  216. }
  217. HRESULT
  218. CWbemServices::GetObject(
  219. /* [in] */ const BSTR ObjectPath,
  220. /* [in] */ long lFlags,
  221. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  222. /* [unique][in][out] */ IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject,
  223. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult)
  224. {
  225. DBG_ASSERT(m_pWbemServices != NULL);
  226. if(ppObject)
  227. {
  228. *ppObject = NULL;
  229. }
  230. if(ppCallResult)
  231. {
  232. *ppCallResult = NULL;
  233. }
  234. HRESULT hr = m_pWbemServices->GetObject(
  235. ObjectPath,
  236. lFlags,
  237. pCtx,
  238. ppObject,
  239. ppCallResult);
  240. HRESULT cichr = CoImpersonateClient();
  241. if (FAILED(cichr))
  242. {
  243. return cichr;
  244. }
  245. return hr;
  246. }
  247. HRESULT
  248. CWbemServices::PutClass(
  249. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  250. /* [in] */ long lFlags,
  251. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  252. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult)
  253. {
  254. DBG_ASSERT(m_pWbemServices != NULL);
  255. if(ppCallResult)
  256. {
  257. *ppCallResult = NULL;
  258. }
  259. HRESULT hr = m_pWbemServices->PutClass(
  260. pObject,
  261. lFlags,
  262. pCtx,
  263. ppCallResult);
  264. HRESULT cichr = CoImpersonateClient();
  265. if (FAILED(cichr))
  266. {
  267. return cichr;
  268. }
  269. return hr;
  270. }
  271. HRESULT
  272. CWbemServices::PutInstance(
  273. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  274. /* [in] */ long lFlags,
  275. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  276. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult)
  277. {
  278. DBG_ASSERT(m_pWbemServices != NULL);
  279. if(ppCallResult)
  280. {
  281. *ppCallResult = NULL;
  282. }
  283. HRESULT hr = m_pWbemServices->PutInstance(
  284. pInst,
  285. lFlags,
  286. pCtx,
  287. ppCallResult);
  288. HRESULT cichr = CoImpersonateClient();
  289. if (FAILED(cichr))
  290. {
  291. return cichr;
  292. }
  293. return hr;
  294. }