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.

384 lines
9.6 KiB

  1. //***************************************************************************
  2. //
  3. // IISPROV.CPP
  4. //
  5. // Module: WMI IIS provider code
  6. //
  7. // Purpose: Defines the CIISInstProvider class. An object of this class is
  8. // created by the class factory for each connection.
  9. //
  10. // Copyright (c)1998 Microsoft Corporation, All Rights Reserved
  11. //
  12. //***************************************************************************
  13. #include <objbase.h>
  14. #include "iisprov.h"
  15. //***************************************************************************
  16. //
  17. // CIISInstProvider::CreateInstanceEnumAsync
  18. //
  19. // Purpose: Asynchronously enumerates the instances.
  20. //
  21. //***************************************************************************
  22. HRESULT CIISInstProvider::DoCreateInstanceEnumAsync(
  23. const BSTR a_ClassName,
  24. long a_lFlags,
  25. IWbemContext* a_pCtx,
  26. IWbemObjectSink FAR* a_pHandler
  27. )
  28. {
  29. HRESULT t_hr = WBEM_S_NO_ERROR;
  30. IWbemClassObject FAR* t_pes = NULL;
  31. // Do a check of arguments and make sure we have pointer to Namespace
  32. if(a_pHandler == NULL || m_pNamespace == NULL)
  33. return WBEM_E_INVALID_PARAMETER;
  34. try
  35. {
  36. CUtils obj;
  37. obj.EnumObjectAsync(a_ClassName, m_pNamespace, a_pHandler);
  38. }
  39. catch (CIIsProvException e)
  40. {
  41. t_pes = SetExtendedStatus(e.m_psz);
  42. t_hr = e.m_hr;
  43. }
  44. catch (HRESULT hr)
  45. {
  46. t_hr = hr;
  47. }
  48. catch (...)
  49. {
  50. t_hr = WBEM_E_FAILED;
  51. }
  52. // Set status
  53. SCODE t_sc = a_pHandler->SetStatus(WBEM_STATUS_COMPLETE, t_hr, NULL, t_pes);
  54. if(t_pes)
  55. t_pes->Release();
  56. return t_sc;
  57. }
  58. HRESULT CIISInstProvider::DoDeleteInstanceAsync(
  59. const BSTR a_ObjectPath,
  60. long a_lFlags,
  61. IWbemContext* a_pCtx,
  62. IWbemObjectSink* a_pHandler
  63. )
  64. {
  65. CObjectPathParser t_PathParser(e_ParserAcceptRelativeNamespace);
  66. ParsedObjectPath* t_pParsedObject = NULL;
  67. IWbemClassObject* t_pes = NULL;
  68. HRESULT t_hr = WBEM_S_NO_ERROR;
  69. try
  70. {
  71. if(a_ObjectPath == NULL || a_pHandler == NULL || m_pNamespace == NULL)
  72. throw WBEM_E_INVALID_PARAMETER;
  73. if (t_PathParser.Parse(a_ObjectPath, &t_pParsedObject) !=
  74. CObjectPathParser::NoError)
  75. throw WBEM_E_INVALID_PARAMETER;
  76. if (t_pParsedObject == NULL)
  77. throw WBEM_E_FAILED;
  78. CUtils obj;
  79. CMetabase t_metabase;
  80. obj.DeleteObjectAsync(m_pNamespace, t_pParsedObject, t_metabase);
  81. }
  82. catch (CIIsProvException e)
  83. {
  84. t_pes = SetExtendedStatus(e.m_psz);
  85. t_hr = e.m_hr;
  86. }
  87. catch (HRESULT hr)
  88. {
  89. t_hr = hr;
  90. }
  91. catch (...)
  92. {
  93. t_hr = WBEM_E_FAILED;
  94. }
  95. if (t_pParsedObject)
  96. t_PathParser.Free(t_pParsedObject);
  97. // Set status
  98. SCODE t_sc = a_pHandler->SetStatus(WBEM_STATUS_COMPLETE, t_hr, NULL, t_pes);
  99. if(t_pes)
  100. t_pes->Release();
  101. return t_sc;
  102. }
  103. //***************************************************************************
  104. //
  105. // CIISInstProvider::ExecMethodAsync
  106. //
  107. // Synopsis
  108. //
  109. //***************************************************************************
  110. HRESULT CIISInstProvider::DoExecMethodAsync(
  111. const BSTR a_strObjectPath,
  112. const BSTR a_strMethodName,
  113. long a_lFlags,
  114. IWbemContext* a_pCtx,
  115. IWbemClassObject* a_pInParams,
  116. IWbemObjectSink* a_pHandler
  117. )
  118. {
  119. HRESULT t_hr = WBEM_S_NO_ERROR;
  120. IWbemClassObject* t_pes = NULL;
  121. // Do a check of arguments and make sure we have pointer to Namespace
  122. if( a_pHandler == NULL ||
  123. m_pNamespace == NULL ||
  124. a_strMethodName == NULL ||
  125. a_strObjectPath == NULL )
  126. return WBEM_E_INVALID_PARAMETER;
  127. try
  128. {
  129. CUtils obj;
  130. obj.ExecMethodAsync(
  131. a_strObjectPath,
  132. a_strMethodName,
  133. a_pCtx,
  134. a_pInParams,
  135. a_pHandler,
  136. m_pNamespace
  137. );
  138. }
  139. catch (CIIsProvException e)
  140. {
  141. t_pes = SetExtendedStatus(e.m_psz);
  142. t_hr = e.m_hr;
  143. }
  144. catch (HRESULT hr)
  145. {
  146. t_hr = hr;
  147. }
  148. catch (...)
  149. {
  150. t_hr = WBEM_E_FAILED;
  151. }
  152. // Set status
  153. SCODE t_sc = a_pHandler->SetStatus(WBEM_STATUS_COMPLETE, t_hr, NULL, t_pes);
  154. if(t_pes)
  155. t_pes->Release();
  156. return t_sc;
  157. }
  158. //***************************************************************************
  159. //
  160. // CIISInstProvider::GetObjectByPath
  161. // CIISInstProvider::GetObjectByPathAsync
  162. //
  163. // Purpose: Creates an instance given a particular path value.
  164. //
  165. //***************************************************************************
  166. HRESULT CIISInstProvider::DoGetObjectAsync(
  167. const BSTR a_ObjectPath,
  168. long a_lFlags,
  169. IWbemContext* a_pCtx,
  170. IWbemObjectSink* a_pHandler
  171. )
  172. {
  173. CObjectPathParser t_PathParser(e_ParserAcceptRelativeNamespace);
  174. ParsedObjectPath* t_pParsedObject = NULL;
  175. IWbemClassObject* t_pObj = NULL;
  176. IWbemClassObject* t_pes = NULL;
  177. HRESULT t_hr = WBEM_S_NO_ERROR;
  178. try
  179. {
  180. if(a_ObjectPath == NULL || a_pHandler == NULL || m_pNamespace == NULL)
  181. throw WBEM_E_INVALID_PARAMETER;
  182. if (t_PathParser.Parse(a_ObjectPath, &t_pParsedObject) !=
  183. CObjectPathParser::NoError)
  184. throw WBEM_E_INVALID_PARAMETER;
  185. if (t_pParsedObject == NULL)
  186. throw WBEM_E_FAILED;
  187. CUtils obj;
  188. CMetabase t_metabase;
  189. t_hr = obj.GetObjectAsync(m_pNamespace, &t_pObj, t_pParsedObject, t_metabase);
  190. if(SUCCEEDED(t_hr) && t_pObj)
  191. {
  192. t_hr = a_pHandler->Indicate(1,&t_pObj);
  193. t_pObj->Release();
  194. }
  195. }
  196. catch (CIIsProvException e)
  197. {
  198. t_pes = SetExtendedStatus(e.m_psz);
  199. t_hr = e.m_hr;
  200. }
  201. catch (HRESULT hr)
  202. {
  203. t_hr = hr;
  204. }
  205. catch (...)
  206. {
  207. t_hr = WBEM_E_FAILED;
  208. }
  209. if (t_pParsedObject)
  210. t_PathParser.Free(t_pParsedObject);
  211. // Set status
  212. SCODE t_sc = a_pHandler->SetStatus(WBEM_STATUS_COMPLETE, t_hr, NULL, t_pes);
  213. if(t_pes)
  214. t_pes->Release();
  215. return t_sc;
  216. }
  217. HRESULT CIISInstProvider::DoPutInstanceAsync(
  218. IWbemClassObject* a_pObj,
  219. long a_lFlags,
  220. IWbemContext* a_pCtx,
  221. IWbemObjectSink* a_pHandler
  222. )
  223. {
  224. HRESULT t_hr = ERROR_SUCCESS;
  225. CObjectPathParser t_PathParser(e_ParserAcceptRelativeNamespace);
  226. ParsedObjectPath* t_pParsedObject = NULL;
  227. IWbemClassObject* t_pObjOld = NULL;
  228. IWbemClassObject* t_pes = NULL;
  229. CUtils obj;
  230. CMetabase t_metabase;
  231. try
  232. {
  233. if (a_pObj == NULL || a_pCtx == NULL || a_pHandler == NULL)
  234. throw WBEM_E_INVALID_PARAMETER;
  235. _bstr_t t_bstr = L"__RelPath";
  236. _variant_t t_vt;
  237. t_hr = a_pObj->Get(t_bstr, 0, &t_vt, NULL, NULL);
  238. THROW_ON_ERROR(t_hr);
  239. if (t_vt.vt != VT_BSTR)
  240. throw WBEM_E_INVALID_OBJECT;
  241. if (t_PathParser.Parse(t_vt.bstrVal, &t_pParsedObject) != CObjectPathParser::NoError)
  242. throw WBEM_E_INVALID_PARAMETER;
  243. if (t_pParsedObject == NULL)
  244. throw WBEM_E_FAILED;
  245. t_hr = obj.GetObjectAsync(m_pNamespace, &t_pObjOld, t_pParsedObject, t_metabase);
  246. }
  247. catch (CIIsProvException e)
  248. {
  249. t_pes = SetExtendedStatus(e.m_psz);
  250. t_hr = e.m_hr;
  251. }
  252. catch (HRESULT hr)
  253. {
  254. t_hr = hr;
  255. }
  256. catch (...)
  257. {
  258. t_hr = WBEM_E_FAILED;
  259. }
  260. // a second try catch? messy.
  261. // will cleanup when exception handling is removed
  262. try
  263. {
  264. if(SUCCEEDED(t_hr) ||
  265. HRESULT_CODE(t_hr) == ERROR_PATH_NOT_FOUND)
  266. {
  267. if(HRESULT_CODE(t_hr) == ERROR_PATH_NOT_FOUND) {
  268. t_hr = 0;
  269. }
  270. obj.PutObjectAsync(a_pObj, t_pObjOld, t_pParsedObject, a_lFlags);
  271. }
  272. }
  273. catch (CIIsProvException e)
  274. {
  275. t_pes = SetExtendedStatus(e.m_psz);
  276. t_hr = e.m_hr;
  277. }
  278. catch (HRESULT hr)
  279. {
  280. t_hr = hr;
  281. }
  282. catch (...)
  283. {
  284. t_hr = WBEM_E_FAILED;
  285. }
  286. //
  287. if (t_pObjOld)
  288. t_pObjOld->Release();
  289. if (t_pParsedObject)
  290. t_PathParser.Free(t_pParsedObject);
  291. // Set status
  292. SCODE t_sc = a_pHandler->SetStatus(WBEM_STATUS_COMPLETE, t_hr, NULL, t_pes);
  293. if(t_pes)
  294. t_pes->Release();
  295. return t_sc;
  296. }
  297. IWbemClassObject* CIISInstProvider::SetExtendedStatus(WCHAR* a_psz)
  298. {
  299. HRESULT t_hr;
  300. IWbemClassObject* t_pclass;
  301. IWbemClassObject* t_pes;
  302. _bstr_t t_bstr = L"__ExtendedStatus";
  303. t_hr = m_pNamespace->GetObject(
  304. t_bstr,
  305. 0,
  306. NULL,
  307. &t_pclass,
  308. NULL
  309. );
  310. if (t_hr != ERROR_SUCCESS)
  311. return NULL;
  312. t_hr = t_pclass->SpawnInstance(0, &t_pes);
  313. t_pclass->Release();
  314. if (t_hr != ERROR_SUCCESS || t_pes)
  315. return NULL;
  316. _variant_t t_vt = a_psz;
  317. if (!t_vt.bstrVal)
  318. return NULL;
  319. t_hr = t_pes->Put(L"Description", 0, &t_vt, 0);
  320. if (t_hr != ERROR_SUCCESS || t_pes)
  321. {
  322. t_pes->Release();
  323. return NULL;
  324. }
  325. return t_pes;
  326. }