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.

300 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. ProviderBase.cpp
  5. Abstract:
  6. Implementation of:
  7. CProviderBase
  8. Author:
  9. ???
  10. Revision History:
  11. Mohit Srivastava 10-Nov-2000
  12. --*/
  13. #include "ProviderBase.h"
  14. #include <dbgutil.h>
  15. extern long g_cObj;
  16. //
  17. // CProviderBase (Implements IWbemServices, IWbemProviderInit, IWbemShutdown)
  18. //
  19. CProviderBase::CProviderBase(
  20. const BSTR ObjectPath,
  21. const BSTR User,
  22. const BSTR Password,
  23. IWbemContext * pCtx)
  24. :m_cRef(0), m_pNamespace(NULL)
  25. {
  26. }
  27. CProviderBase::~CProviderBase()
  28. {
  29. if(m_pNamespace)
  30. delete m_pNamespace;
  31. }
  32. STDMETHODIMP_(ULONG)
  33. CProviderBase::AddRef(void)
  34. {
  35. InterlockedIncrement(&g_cObj);
  36. return InterlockedIncrement((long *)&m_cRef);
  37. }
  38. STDMETHODIMP_(ULONG)
  39. CProviderBase::Release(void)
  40. {
  41. InterlockedDecrement(&g_cObj);
  42. long lNewCount = InterlockedDecrement((long *)&m_cRef);
  43. if (0L == lNewCount)
  44. delete this;
  45. return (lNewCount > 0) ? lNewCount : 0;
  46. }
  47. STDMETHODIMP
  48. CProviderBase::QueryInterface(
  49. REFIID riid,
  50. PPVOID ppv)
  51. {
  52. *ppv=NULL;
  53. //
  54. // Since we have dual inheritance, it is necessary to cast the return type
  55. //
  56. if(riid == IID_IWbemShutdown)
  57. {
  58. *ppv = (IWbemShutdown*)this;
  59. }
  60. if(riid == IID_IWbemServices)
  61. {
  62. *ppv = (IWbemServices*)this;
  63. }
  64. if(IID_IUnknown == riid || riid == IID_IWbemProviderInit)
  65. {
  66. *ppv = (IWbemProviderInit*)this;
  67. }
  68. if (NULL != *ppv)
  69. {
  70. AddRef();
  71. return S_OK;
  72. }
  73. else
  74. {
  75. return E_NOINTERFACE;
  76. }
  77. }
  78. HRESULT
  79. CProviderBase::Shutdown(
  80. LONG uReason,
  81. ULONG uMaxMilliseconds,
  82. IWbemContext *pCtx)
  83. {
  84. HRESULT hr = S_OK;
  85. return hr;
  86. }
  87. HRESULT
  88. CProviderBase::Initialize(
  89. LPWSTR wszUser,
  90. LONG lFlags,
  91. LPWSTR wszNamespace,
  92. LPWSTR wszLocale,
  93. IWbemServices* pNamespace,
  94. IWbemContext* pCtx,
  95. IWbemProviderInitSink* pInitSink)
  96. /*++
  97. Synopsis:
  98. According to stevm from WMI, calls to Initialize are guaranteed to be
  99. synchronized - so long as all providers are in the same namespace.
  100. Arguments: [wszUser] -
  101. [lFlags] -
  102. [wszNamespace] -
  103. [wszLocale] -
  104. [pNamespace] -
  105. [pCtx] -
  106. [pInitSink] -
  107. Return Value:
  108. --*/
  109. {
  110. HRESULT hr = CoImpersonateClient();
  111. if(FAILED(hr))
  112. {
  113. pInitSink->SetStatus(WBEM_E_FAILED, 0);
  114. DBGPRINTF((DBG_CONTEXT, "CoImpersonateClient failed\n"));
  115. return WBEM_E_FAILED;
  116. }
  117. return DoInitialize(
  118. wszUser,
  119. lFlags,
  120. wszNamespace,
  121. wszLocale,
  122. pNamespace,
  123. pCtx,
  124. pInitSink);
  125. }
  126. HRESULT
  127. CProviderBase::CreateInstanceEnumAsync(
  128. /* [in] */ const BSTR Class,
  129. /* [in] */ long lFlags,
  130. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  131. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  132. {
  133. HRESULT hr = CoImpersonateClient();
  134. if(FAILED(hr))
  135. {
  136. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  137. DBGPRINTF((DBG_CONTEXT, "CoImpersonateClient failed\n"));
  138. return WBEM_E_FAILED;
  139. }
  140. return DoCreateInstanceEnumAsync(
  141. Class,
  142. lFlags,
  143. pCtx,
  144. pResponseHandler);
  145. }
  146. HRESULT
  147. CProviderBase::DeleteInstanceAsync(
  148. /* [in] */ const BSTR ObjectPath,
  149. /* [in] */ long lFlags,
  150. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  151. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  152. {
  153. HRESULT hr = CoImpersonateClient();
  154. if(FAILED(hr))
  155. {
  156. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  157. DBGPRINTF((DBG_CONTEXT, "CoImpersonateClient failed\n"));
  158. return WBEM_E_FAILED;
  159. }
  160. return DoDeleteInstanceAsync(
  161. ObjectPath,
  162. lFlags,
  163. pCtx,
  164. pResponseHandler);
  165. }
  166. HRESULT
  167. CProviderBase::ExecMethodAsync(
  168. /* [in] */ const BSTR strObjectPath,
  169. /* [in] */ const BSTR MethodName,
  170. /* [in] */ long lFlags,
  171. /* [in] */ IWbemContext* pCtx,
  172. /* [in] */ IWbemClassObject* pInParams,
  173. /* [in] */ IWbemObjectSink* pResponseHandler)
  174. {
  175. HRESULT hr = CoImpersonateClient();
  176. if(FAILED(hr))
  177. {
  178. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  179. DBGPRINTF((DBG_CONTEXT, "CoImpersonateClient failed\n"));
  180. return WBEM_E_FAILED;
  181. }
  182. return DoExecMethodAsync(
  183. strObjectPath,
  184. MethodName,
  185. lFlags,
  186. pCtx,
  187. pInParams,
  188. pResponseHandler);
  189. }
  190. HRESULT
  191. CProviderBase::ExecQueryAsync(
  192. /* [in] */ const BSTR QueryLanguage,
  193. /* [in] */ const BSTR Query,
  194. /* [in] */ long lFlags,
  195. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  196. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  197. {
  198. HRESULT hr = CoImpersonateClient();
  199. if(FAILED(hr))
  200. {
  201. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  202. DBGPRINTF((DBG_CONTEXT, "CoImpersonateClient failed\n"));
  203. return WBEM_E_FAILED;
  204. }
  205. return DoExecQueryAsync(
  206. QueryLanguage,
  207. Query,
  208. lFlags,
  209. pCtx,
  210. pResponseHandler);
  211. }
  212. HRESULT
  213. CProviderBase::GetObjectAsync(
  214. /* [in] */ const BSTR ObjectPath,
  215. /* [in] */ long lFlags,
  216. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  217. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  218. {
  219. HRESULT hr = CoImpersonateClient();
  220. if(FAILED(hr))
  221. {
  222. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  223. DBGPRINTF((DBG_CONTEXT, "CoImpersonateClient failed\n"));
  224. return WBEM_E_FAILED;
  225. }
  226. return DoGetObjectAsync(
  227. ObjectPath,
  228. lFlags,
  229. pCtx,
  230. pResponseHandler);
  231. }
  232. HRESULT
  233. CProviderBase::PutInstanceAsync(
  234. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  235. /* [in] */ long lFlags,
  236. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  237. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  238. {
  239. HRESULT hr = CoImpersonateClient();
  240. if(FAILED(hr))
  241. {
  242. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  243. DBGPRINTF((DBG_CONTEXT, "CoImpersonateClient failed\n"));
  244. return WBEM_E_FAILED;
  245. }
  246. return DoPutInstanceAsync(
  247. pInst,
  248. lFlags,
  249. pCtx,
  250. pResponseHandler);
  251. }