Source code of Windows XP (NT5)
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.

2370 lines
63 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. iisprov.cpp
  5. Abstract:
  6. Defines the CIISInstProvider class. An object of this class is
  7. created by the class factory for each connection.
  8. Author:
  9. ???
  10. Revision History:
  11. Mohit Srivastava 18-Dec-00
  12. --*/
  13. #define WMI_HR(hr) \
  14. (FAILED(hr) && HRESULT_FACILITY(hr) != FACILITY_ITF) ? WBEM_E_FAILED : hr
  15. #include "iisprov.h"
  16. #include "appladmin.h"
  17. #include "enum.h"
  18. #include "ipsecurity.h"
  19. #include "adminacl.h"
  20. #include "certmap.h"
  21. #include "iiswmimsg.h"
  22. #include "pusher.h"
  23. #include "instancehelper.h"
  24. #include "webservicemethod.h"
  25. #include "queryhelper.h"
  26. #include "smartpointer.h"
  27. #define PARAMS WMI_METHOD_PARAM_DATA
  28. #define METHODS WMI_METHOD_DATA
  29. #define CLASSES WMI_CLASS_DATA
  30. #define PROPS METABASE_PROPERTY_DATA
  31. extern CDynSchema* g_pDynSch; // Initialized to NULL in schemadynamic.cpp
  32. bool CIISInstProvider::ms_bInitialized = false;
  33. HRESULT CIISInstProvider::DoInitialize(
  34. LPWSTR i_wszUser,
  35. LONG i_lFlags,
  36. LPWSTR i_wszNamespace,
  37. LPWSTR i_wszLocale,
  38. IWbemServices* i_pNamespace,
  39. IWbemContext* i_pCtx,
  40. IWbemProviderInitSink* i_pInitSink)
  41. /*++
  42. Synopsis:
  43. According to stevm from WMI, calls to Initialize are guaranteed to be
  44. synchronized - so long as all providers are in the same namespace.
  45. Arguments: [wszUser] -
  46. [lFlags] -
  47. [wszNamespace] -
  48. [wszLocale] -
  49. [pNamespace] -
  50. [pCtx] -
  51. [pInitSink] -
  52. Return Value:
  53. --*/
  54. {
  55. CPusher pusher;
  56. CSchemaExtensions* pcatalog = NULL;
  57. HRESULT hr = WBEM_S_NO_ERROR; // return value
  58. LONG lStatus = WBEM_S_INITIALIZED; // param to SetStatus
  59. CComPtr<IWbemContext> spCtx = i_pCtx; // must AddRef according to doc
  60. //
  61. // If we hit this, we are leaking memory, because m_pNamespace is
  62. // initilaized in this function only and cleaned up by the destructor only.
  63. //
  64. DBG_ASSERT(m_pNamespace == NULL);
  65. //
  66. // Initialize members
  67. //
  68. m_pNamespace = new CWbemServices(i_pNamespace);
  69. if(m_pNamespace == NULL)
  70. {
  71. hr = WBEM_E_OUT_OF_MEMORY;
  72. i_pInitSink->SetStatus(WBEM_E_FAILED,0);
  73. return hr;
  74. }
  75. //
  76. // If we've already initialized globals, jump to the end.
  77. // Else, we're going to initialize globals.
  78. //
  79. if(ms_bInitialized)
  80. {
  81. goto exit;
  82. }
  83. pcatalog = new CSchemaExtensions();
  84. if(pcatalog == NULL)
  85. {
  86. hr = WBEM_E_OUT_OF_MEMORY;
  87. goto exit;
  88. }
  89. //
  90. // Initialize the g_pDynSch
  91. // Populate pCatalog
  92. //
  93. g_pDynSch = new CDynSchema();
  94. if(g_pDynSch == NULL)
  95. {
  96. hr = WBEM_E_OUT_OF_MEMORY;
  97. goto exit;
  98. }
  99. hr = g_pDynSch->Initialize();
  100. if(FAILED(hr))
  101. {
  102. goto exit;
  103. }
  104. hr = g_pDynSch->RunRules(pcatalog);
  105. if(FAILED(hr))
  106. {
  107. goto exit;
  108. }
  109. //
  110. // Use pCatalog, g_pDynSch to update repository
  111. //
  112. hr = pusher.Initialize(m_pNamespace, i_pCtx);
  113. if(FAILED(hr))
  114. {
  115. goto exit;
  116. }
  117. hr = pusher.Push(
  118. pcatalog,
  119. g_pDynSch->GetHashClasses(),
  120. g_pDynSch->GetHashAssociations());
  121. if(FAILED(hr))
  122. {
  123. goto exit;
  124. }
  125. ms_bInitialized = true;
  126. //
  127. // Destructor makes IST calls, so call before we unload dispenser dll.
  128. //
  129. delete pcatalog;
  130. pcatalog = NULL;
  131. //
  132. // If Init was successful, we will no longer need this dll.
  133. //
  134. UnloadDispenserDll(WSZ_PRODUCT_IIS);
  135. exit:
  136. delete pcatalog;
  137. if(FAILED(hr))
  138. {
  139. DBG_ASSERT(ms_bInitialized == false);
  140. delete g_pDynSch;
  141. g_pDynSch = NULL;
  142. lStatus = WBEM_E_FAILED;
  143. }
  144. //
  145. //Let CIMOM know you are initialized
  146. //
  147. i_pInitSink->SetStatus(lStatus,0);
  148. return hr;
  149. }
  150. HRESULT CIISInstProvider::DoCreateInstanceEnumAsync(
  151. const BSTR i_ClassName,
  152. long i_lFlags,
  153. IWbemContext* i_pCtx,
  154. IWbemObjectSink FAR* i_pHandler
  155. )
  156. /*++
  157. Synopsis:
  158. Asynchronously enumerates the instances.
  159. Arguments:
  160. Return Value:
  161. --*/
  162. {
  163. DBG_ASSERT(m_pNamespace != NULL);
  164. HRESULT hr = WBEM_S_NO_ERROR;
  165. IWbemClassObject FAR* pes = NULL;
  166. //
  167. // Do a check of arguments.
  168. //
  169. if(i_ClassName == NULL || i_pHandler == NULL)
  170. {
  171. return WBEM_E_INVALID_PARAMETER;
  172. }
  173. try
  174. {
  175. WorkerEnumObjectAsync(i_ClassName, i_pHandler);
  176. }
  177. catch (CIIsProvException e)
  178. {
  179. pes = ConstructExtendedStatus(&e);
  180. hr = e.GetHR();
  181. }
  182. catch (HRESULT hrError)
  183. {
  184. hr = hrError;
  185. }
  186. catch (...)
  187. {
  188. hr = WBEM_E_FAILED;
  189. }
  190. //
  191. // Set status
  192. //
  193. if(!pes)
  194. {
  195. pes = ConstructExtendedStatus(hr);
  196. }
  197. SCODE sc = i_pHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, pes);
  198. if(pes)
  199. {
  200. pes->Release();
  201. }
  202. return sc;
  203. }
  204. HRESULT CIISInstProvider::DoDeleteInstanceAsync(
  205. const BSTR i_ObjectPath,
  206. long i_lFlags,
  207. IWbemContext* i_pCtx,
  208. IWbemObjectSink* i_pHandler
  209. )
  210. {
  211. DBG_ASSERT(m_pNamespace != NULL);
  212. CObjectPathParser PathParser(e_ParserAcceptRelativeNamespace);
  213. ParsedObjectPath* pParsedObject = NULL;
  214. IWbemClassObject* pes = NULL;
  215. HRESULT hr = WBEM_S_NO_ERROR;
  216. if(i_ObjectPath == NULL || i_pHandler == NULL)
  217. {
  218. return WBEM_E_INVALID_PARAMETER;
  219. }
  220. try
  221. {
  222. hr = CUtils::ParserErrToHR( PathParser.Parse(i_ObjectPath, &pParsedObject) );
  223. THROW_ON_ERROR(hr);
  224. DBG_ASSERT(pParsedObject);
  225. WorkerDeleteObjectAsync(pParsedObject);
  226. }
  227. catch (CIIsProvException e)
  228. {
  229. pes = ConstructExtendedStatus(&e);
  230. hr = e.GetHR();
  231. }
  232. catch (HRESULT hrError)
  233. {
  234. hr = hrError;
  235. }
  236. catch (...)
  237. {
  238. hr = WBEM_E_FAILED;
  239. }
  240. if (pParsedObject)
  241. {
  242. PathParser.Free(pParsedObject);
  243. }
  244. //
  245. // Set status
  246. //
  247. if(!pes)
  248. {
  249. pes = ConstructExtendedStatus(hr);
  250. }
  251. SCODE sc = i_pHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, pes);
  252. if(pes)
  253. {
  254. pes->Release();
  255. }
  256. return sc;
  257. }
  258. HRESULT CIISInstProvider::DoExecMethodAsync(
  259. const BSTR i_strObjectPath,
  260. const BSTR i_strMethodName,
  261. long i_lFlags,
  262. IWbemContext* i_pCtx,
  263. IWbemClassObject* i_pInParams,
  264. IWbemObjectSink* i_pHandler
  265. )
  266. {
  267. DBG_ASSERT(m_pNamespace != NULL);
  268. HRESULT hr = WBEM_S_NO_ERROR;
  269. IWbemClassObject* pes = NULL;
  270. //
  271. // Do a check of arguments and make sure we have pointer to Namespace
  272. //
  273. if( i_pHandler == NULL ||
  274. i_strMethodName == NULL ||
  275. i_strObjectPath == NULL )
  276. {
  277. return WBEM_E_INVALID_PARAMETER;
  278. }
  279. try
  280. {
  281. WorkerExecMethodAsync(
  282. i_strObjectPath,
  283. i_strMethodName,
  284. i_pCtx,
  285. i_pInParams,
  286. i_pHandler
  287. );
  288. }
  289. catch (_com_error c)
  290. {
  291. hr = c.Error();
  292. }
  293. catch (CIIsProvException e)
  294. {
  295. pes = ConstructExtendedStatus(&e);
  296. hr = e.GetHR();
  297. }
  298. catch (HRESULT hrError)
  299. {
  300. hr = hrError;
  301. }
  302. catch (...)
  303. {
  304. hr = WBEM_E_FAILED;
  305. }
  306. //
  307. // Set status
  308. //
  309. if(!pes)
  310. {
  311. pes = ConstructExtendedStatus(hr);
  312. }
  313. SCODE sc = i_pHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, pes);
  314. if(pes)
  315. {
  316. pes->Release();
  317. }
  318. return sc;
  319. }
  320. HRESULT CIISInstProvider::DoGetObjectAsync(
  321. const BSTR i_ObjectPath,
  322. long i_lFlags,
  323. IWbemContext* i_pCtx,
  324. IWbemObjectSink* i_pHandler
  325. )
  326. /*++
  327. Synopsis:
  328. Creates an instance given a particular path value.
  329. Arguments:
  330. Return Value:
  331. --*/
  332. {
  333. DBG_ASSERT(m_pNamespace != NULL);
  334. IWbemClassObject* pObj = NULL;
  335. IWbemClassObject* pes = NULL;
  336. HRESULT hr = WBEM_S_NO_ERROR;
  337. if(i_ObjectPath == NULL || i_pHandler == NULL)
  338. {
  339. return WBEM_E_INVALID_PARAMETER;
  340. }
  341. try
  342. {
  343. WorkerGetObjectAsync(&pObj, i_ObjectPath, false);
  344. hr = i_pHandler->Indicate(1,&pObj);
  345. pObj->Release();
  346. }
  347. catch (CIIsProvException e)
  348. {
  349. pes = ConstructExtendedStatus(&e);
  350. hr = e.GetHR();
  351. }
  352. catch (HRESULT hrError)
  353. {
  354. hr = hrError;
  355. }
  356. catch (...)
  357. {
  358. hr = WBEM_E_FAILED;
  359. }
  360. //
  361. // Set status
  362. //
  363. if(!pes)
  364. {
  365. pes = ConstructExtendedStatus(hr);
  366. }
  367. SCODE sc = i_pHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, pes);
  368. if(pes)
  369. {
  370. pes->Release();
  371. }
  372. return sc;
  373. }
  374. HRESULT CIISInstProvider::DoPutInstanceAsync(
  375. IWbemClassObject* i_pObj,
  376. long i_lFlags,
  377. IWbemContext* i_pCtx,
  378. IWbemObjectSink* i_pHandler
  379. )
  380. {
  381. DBG_ASSERT(m_pNamespace != NULL);
  382. HRESULT hr = WBEM_S_NO_ERROR;
  383. CObjectPathParser PathParser(e_ParserAcceptRelativeNamespace);
  384. ParsedObjectPath* pParsedObject = NULL;
  385. CComPtr<IWbemClassObject> spObjOld;
  386. CComBSTR sbstrObjPath;
  387. IWbemClassObject* pes = NULL;
  388. if(i_pObj == NULL || i_pCtx == NULL || i_pHandler == NULL)
  389. {
  390. return WBEM_E_INVALID_PARAMETER;
  391. }
  392. try
  393. {
  394. _bstr_t bstr = L"__RelPath";
  395. _variant_t vtObjPath;
  396. hr = i_pObj->Get(bstr, 0, &vtObjPath, NULL, NULL);
  397. THROW_ON_ERROR(hr);
  398. if (vtObjPath.vt != VT_BSTR)
  399. {
  400. bstr = L"__Class";
  401. vtObjPath.Clear();
  402. hr = i_pObj->Get(bstr, 0, &vtObjPath, NULL, NULL);
  403. THROW_ON_ERROR(hr);
  404. //
  405. // This means the user is trying to create an instance but did not
  406. // specify a primary key.
  407. }
  408. if(vtObjPath.vt != VT_BSTR)
  409. {
  410. THROW_ON_ERROR(WBEM_E_INVALID_OBJECT);
  411. }
  412. hr = CUtils::ParserErrToHR( PathParser.Parse(vtObjPath.bstrVal, &pParsedObject) );
  413. THROW_ON_ERROR(hr);
  414. DBG_ASSERT(pParsedObject != NULL);
  415. bool bInstanceExists = false; // existing or new instance
  416. WMI_CLASS* pWmiClass = NULL;
  417. ValidatePutParsedObject(
  418. pParsedObject,
  419. i_pObj,
  420. NULL,
  421. &bInstanceExists,
  422. &pWmiClass);
  423. //
  424. // We auto-generate primary key only for IIsWebServer and IIsFtpServer
  425. //
  426. if( pParsedObject->m_dwNumKeys == 0 &&
  427. (pWmiClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  428. pWmiClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsFtpServer) )
  429. {
  430. //
  431. // Get the ServerComment
  432. //
  433. _variant_t vtServerComment;
  434. hr = i_pObj->Get(PROPS::s_ServerComment.pszPropName,
  435. 0, &vtServerComment, NULL, NULL);
  436. if(hr == WBEM_E_NOT_FOUND || vtServerComment.vt != VT_BSTR)
  437. {
  438. vtServerComment.Clear();
  439. vtServerComment.bstrVal = NULL;
  440. vtServerComment.vt = VT_BSTR;
  441. hr = WBEM_S_NO_ERROR;
  442. }
  443. THROW_ON_ERROR(hr);
  444. //
  445. // Create the site
  446. //
  447. eSC_SUPPORTED_SERVICES eServiceId;
  448. _bstr_t sbstrKeyValue;
  449. DWORD dwSiteId = 0;
  450. WCHAR wszSiteId[11] = {0};
  451. if( pWmiClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsWebServer )
  452. {
  453. eServiceId = SC_W3SVC;
  454. sbstrKeyValue = "w3svc/";
  455. }
  456. else
  457. {
  458. eServiceId = SC_MSFTPSVC;
  459. sbstrKeyValue = "msftpsvc/";
  460. }
  461. CServiceMethod method(eServiceId);
  462. hr = method.Init();
  463. THROW_ON_ERROR(hr);
  464. hr = method.CreateNewSite(vtServerComment.bstrVal, &dwSiteId);
  465. THROW_ON_ERROR(hr);
  466. sbstrKeyValue += _itow(dwSiteId, wszSiteId, 10);
  467. VARIANT vtKeyValue;
  468. vtKeyValue.bstrVal = sbstrKeyValue;
  469. vtKeyValue.vt = VT_BSTR;
  470. THROW_ON_FALSE(pParsedObject->AddKeyRefEx(pWmiClass->pszKeyName, &vtKeyValue));
  471. }
  472. if( pWmiClass->pkt != &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE &&
  473. pWmiClass->pkt != &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL &&
  474. pWmiClass->pkt != &METABASE_KEYTYPE_DATA::s_TYPE_IPSecurity )
  475. {
  476. WorkerGetObjectAsync(&spObjOld, pParsedObject, true);
  477. }
  478. WorkerPutObjectAsync(
  479. i_pObj,
  480. spObjOld,
  481. pParsedObject,
  482. i_lFlags,
  483. bInstanceExists,
  484. &sbstrObjPath);
  485. }
  486. catch (CIIsProvException e)
  487. {
  488. pes = ConstructExtendedStatus(&e);
  489. hr = e.GetHR();
  490. }
  491. catch (HRESULT hrError)
  492. {
  493. hr = hrError;
  494. }
  495. catch (...)
  496. {
  497. hr = WBEM_E_FAILED;
  498. }
  499. if (pParsedObject)
  500. {
  501. PathParser.Free(pParsedObject);
  502. }
  503. //
  504. // Set status
  505. //
  506. if(!pes)
  507. {
  508. pes = ConstructExtendedStatus(hr);
  509. }
  510. SCODE sc = i_pHandler->SetStatus(
  511. WBEM_STATUS_COMPLETE, hr, sbstrObjPath, pes);
  512. if(pes)
  513. {
  514. pes->Release();
  515. }
  516. return sc;
  517. }
  518. HRESULT CIISInstProvider::DoExecQueryAsync(
  519. const BSTR i_bstrQueryLanguage,
  520. const BSTR i_bstrQuery,
  521. long i_lFlags,
  522. IWbemContext* i_pCtx,
  523. IWbemObjectSink* i_pResponseHandler)
  524. {
  525. if( i_bstrQueryLanguage == NULL ||
  526. i_bstrQuery == NULL ||
  527. i_pCtx == NULL ||
  528. i_pResponseHandler == NULL )
  529. {
  530. return WBEM_E_INVALID_PARAMETER;
  531. }
  532. DBG_ASSERT(m_pNamespace != NULL);
  533. HRESULT hr = WBEM_S_NO_ERROR;
  534. IWbemClassObject* pes = NULL;
  535. try
  536. {
  537. CQueryHelper QueryHelper(
  538. i_bstrQueryLanguage,
  539. i_bstrQuery,
  540. m_pNamespace,
  541. i_pResponseHandler);
  542. if(QueryHelper.IsAssoc())
  543. {
  544. QueryHelper.GetAssociations();
  545. }
  546. else
  547. {
  548. QueryHelper.GetInstances();
  549. }
  550. }
  551. catch (CIIsProvException e)
  552. {
  553. pes = ConstructExtendedStatus(&e);
  554. hr = e.GetHR();
  555. }
  556. catch (HRESULT hrError)
  557. {
  558. hr = hrError;
  559. }
  560. catch (...)
  561. {
  562. hr = WBEM_E_FAILED;
  563. }
  564. //
  565. // Set status
  566. //
  567. if(!pes)
  568. {
  569. pes = ConstructExtendedStatus(hr);
  570. }
  571. SCODE sc = i_pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, pes);
  572. if(pes)
  573. {
  574. pes->Release();
  575. }
  576. return sc;
  577. }
  578. IWbemClassObject* CIISInstProvider::ConstructExtendedStatus(
  579. HRESULT i_hr) const
  580. {
  581. IWbemClassObject* pes = NULL;
  582. //
  583. // We only need extended status on failure.
  584. //
  585. if(SUCCEEDED(i_hr))
  586. {
  587. return NULL;
  588. }
  589. CIIsProvException e;
  590. e.SetHR(i_hr);
  591. pes = ConstructExtendedStatus(&e);
  592. return pes;
  593. }
  594. IWbemClassObject* CIISInstProvider::ConstructExtendedStatus(
  595. const CIIsProvException* i_pException) const
  596. {
  597. DBG_ASSERT(m_pNamespace != NULL);
  598. DBG_ASSERT(i_pException != NULL);
  599. HRESULT hr;
  600. CComPtr<IWbemClassObject> spClass;
  601. CComPtr<IWbemClassObject> spES;
  602. IWbemClassObject* pESRet = NULL;
  603. CComBSTR sbstr = L"__ExtendedStatus";
  604. if(sbstr.m_str == NULL)
  605. {
  606. return NULL;
  607. }
  608. //
  609. // Get the __ExtendedStatus class and Spawn and instance
  610. //
  611. hr = m_pNamespace->GetObject(
  612. sbstr,
  613. 0,
  614. NULL,
  615. &spClass,
  616. NULL
  617. );
  618. if(FAILED(hr))
  619. {
  620. return NULL;
  621. }
  622. hr = spClass->SpawnInstance(0, &spES);
  623. if(FAILED(hr))
  624. {
  625. return NULL;
  626. }
  627. //
  628. // Set the description.
  629. //
  630. CComVariant svt;
  631. sbstr.Empty();
  632. sbstr = i_pException->GetErrorText();
  633. svt = sbstr.Detach();
  634. if(svt.vt == VT_BSTR && svt.bstrVal != NULL)
  635. {
  636. hr = spES->Put(L"Description", 0, &svt, 0);
  637. if(FAILED(hr))
  638. {
  639. return NULL;
  640. }
  641. }
  642. //
  643. // Set the status code.
  644. //
  645. svt = i_pException->GetHR();
  646. hr = spES->Put(L"StatusCode", 0, &svt, 0);
  647. if(FAILED(hr))
  648. {
  649. return NULL;
  650. }
  651. //
  652. // Set the parameter info.
  653. //
  654. svt = i_pException->GetParams();
  655. if(svt.vt == VT_BSTR && svt.bstrVal != NULL)
  656. {
  657. hr = spES->Put(L"ParameterInfo", 0, &svt, 0);
  658. if(FAILED(hr))
  659. {
  660. return NULL;
  661. }
  662. }
  663. //
  664. // Set the provider name.
  665. //
  666. svt = g_wszIIsProvider;
  667. if(svt.vt == VT_BSTR && svt.bstrVal != NULL)
  668. {
  669. hr = spES->Put(L"ProviderName", 0, &svt, 0);
  670. if(FAILED(hr))
  671. {
  672. return NULL;
  673. }
  674. }
  675. //
  676. // If everything succeeded...
  677. //
  678. spES.CopyTo(&pESRet);
  679. return pESRet;
  680. }
  681. void CIISInstProvider::WorkerExecMethodAsync(
  682. BSTR i_strObjectPath,
  683. BSTR i_strMethodName,
  684. IWbemContext* i_pCtx,
  685. IWbemClassObject* i_pInParams,
  686. IWbemObjectSink* i_pHandler
  687. )
  688. {
  689. DBG_ASSERT(i_strObjectPath != NULL);
  690. DBG_ASSERT(i_strMethodName != NULL);
  691. DBG_ASSERT(i_pHandler != NULL);
  692. DBG_ASSERT(m_pNamespace != NULL);
  693. WMI_CLASS* pWMIClass;
  694. CObjectPathParser PathParser(e_ParserAcceptRelativeNamespace);
  695. TSmartPointer<ParsedObjectPath> spParsedObjPath;
  696. _bstr_t bstrMbPath;
  697. WMI_METHOD* pmethod;
  698. HRESULT hr = WBEM_S_NO_ERROR;
  699. hr = CUtils::ParserErrToHR( PathParser.Parse(i_strObjectPath, &spParsedObjPath) );
  700. THROW_ON_ERROR(hr);
  701. DBG_ASSERT(spParsedObjPath != NULL);
  702. if (!CUtils::GetClass(spParsedObjPath->m_pClass,&pWMIClass))
  703. {
  704. THROW_ON_ERROR(WBEM_E_INVALID_CLASS);
  705. }
  706. if (!CUtils::GetMethod(i_strMethodName, pWMIClass->ppMethod, &pmethod ))
  707. {
  708. THROW_ON_ERROR(WBEM_E_INVALID_METHOD);
  709. }
  710. CUtils::GetMetabasePath(NULL,spParsedObjPath,pWMIClass,bstrMbPath);
  711. if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsFtpService)
  712. {
  713. WorkerExecFtpServiceMethod(
  714. bstrMbPath,
  715. pWMIClass,
  716. pmethod,
  717. i_pCtx,
  718. i_pInParams,
  719. i_pHandler);
  720. }
  721. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsWebService)
  722. {
  723. WorkerExecWebServiceMethod(
  724. bstrMbPath,
  725. pWMIClass,
  726. pmethod,
  727. i_pCtx,
  728. i_pInParams,
  729. i_pHandler);
  730. }
  731. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsFtpServer ||
  732. pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsWebServer)
  733. {
  734. CMetabase metabase;
  735. HRESULT hr = S_OK;
  736. metabase.PutMethod(bstrMbPath, pmethod->dwMDId);
  737. }
  738. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsWebVirtualDir ||
  739. pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsWebDirectory)
  740. {
  741. WorkerExecWebAppMethod(
  742. bstrMbPath,
  743. pWMIClass->pszClassName,
  744. pmethod,
  745. i_pCtx,
  746. i_pInParams,
  747. i_pHandler,
  748. m_pNamespace
  749. );
  750. }
  751. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsComputer)
  752. {
  753. WorkerExecComputerMethod(
  754. bstrMbPath,
  755. pWMIClass->pszClassName,
  756. pmethod,
  757. i_pCtx,
  758. i_pInParams,
  759. i_pHandler,
  760. m_pNamespace
  761. );
  762. }
  763. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsCertMapper)
  764. {
  765. WorkerExecCertMapperMethod(
  766. bstrMbPath,
  767. pWMIClass->pszClassName,
  768. pmethod,
  769. i_pCtx,
  770. i_pInParams,
  771. i_pHandler,
  772. m_pNamespace
  773. );
  774. }
  775. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsApplicationPool)
  776. {
  777. WorkerExecAppPoolMethod(
  778. bstrMbPath,
  779. pWMIClass->pszClassName,
  780. pmethod,
  781. i_pCtx,
  782. i_pInParams,
  783. i_pHandler,
  784. m_pNamespace
  785. );
  786. }
  787. else
  788. {
  789. THROW_ON_ERROR(WBEM_E_INVALID_METHOD);
  790. }
  791. }
  792. void CIISInstProvider::WorkerDeleteObjectAsync(
  793. ParsedObjectPath* i_pParsedObject
  794. )
  795. {
  796. DBG_ASSERT(m_pNamespace != NULL);
  797. DBG_ASSERT(i_pParsedObject != NULL);
  798. HRESULT hr = WBEM_S_NO_ERROR;
  799. _bstr_t bstrMbPath;
  800. WMI_CLASS* pWMIClass;
  801. METADATA_HANDLE hKey = NULL;
  802. CMetabase metabase;
  803. if (!CUtils::GetClass(i_pParsedObject->m_pClass,&pWMIClass))
  804. {
  805. THROW_ON_ERROR(WBEM_E_INVALID_CLASS);
  806. }
  807. //
  808. // get the meta path of object
  809. //
  810. CUtils::GetMetabasePath(NULL,i_pParsedObject,pWMIClass,bstrMbPath);
  811. //
  812. // if AdminACL
  813. //
  814. if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL )
  815. {
  816. THROW_ON_ERROR(WBEM_E_NOT_SUPPORTED);
  817. }
  818. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_IPSecurity)
  819. {
  820. hKey = metabase.OpenKey(bstrMbPath, true);
  821. metabase.DeleteData(hKey, MD_IP_SEC, BINARY_METADATA);
  822. metabase.CloseKey(hKey);
  823. return;
  824. }
  825. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE)
  826. {
  827. CAdminACL objACL;
  828. hr = objACL.OpenSD(bstrMbPath);
  829. if(SUCCEEDED(hr))
  830. hr = objACL.DeleteObjectAsync(i_pParsedObject);
  831. THROW_ON_ERROR(hr);
  832. return;
  833. }
  834. else if(pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsApplicationPool)
  835. {
  836. CAppPoolMethod objAppPool;
  837. objAppPool.DeleteAppPool(bstrMbPath);
  838. return;
  839. }
  840. if( pWMIClass->pkt->m_pszDisallowDeletionNode &&
  841. _wcsicmp(bstrMbPath, pWMIClass->pkt->m_pszDisallowDeletionNode) == 0 )
  842. {
  843. CIIsProvException e;
  844. e.SetMC(WBEM_E_INVALID_OPERATION, IISWMI_INSTANCE_DELETION_DISALLOWED, NULL);
  845. throw e;
  846. }
  847. DBG_ASSERT(((LPWSTR)(bstrMbPath))[0] == L'/');
  848. DBG_ASSERT(((LPWSTR)(bstrMbPath))[1] != L'\0');
  849. LPWSTR pParent = wcsrchr(bstrMbPath, L'/');
  850. WCHAR wcStore = *pParent;
  851. *pParent = L'\0';
  852. hKey = metabase.OpenKey(bstrMbPath, true);
  853. *pParent = wcStore;
  854. hr = metabase.DeleteKey(hKey, pParent);
  855. THROW_ON_ERROR(hr);
  856. metabase.CloseKey(hKey);
  857. }
  858. void CIISInstProvider::WorkerGetObjectAsync(
  859. IWbemClassObject** o_ppObj,
  860. ParsedObjectPath* i_pParsedObjPath,
  861. bool i_bCreateKeyIfNotExist)
  862. {
  863. WMI_CLASS* pWmiClass = NULL;
  864. WMI_ASSOCIATION* pWmiAssoc = NULL;
  865. CMetabase metabase;
  866. CInstanceHelper InstanceHelper(i_pParsedObjPath, m_pNamespace);
  867. if(!InstanceHelper.IsAssoc())
  868. {
  869. InstanceHelper.GetInstance(
  870. i_bCreateKeyIfNotExist, // in
  871. &metabase, // in/out
  872. o_ppObj); // out
  873. }
  874. else
  875. {
  876. InstanceHelper.GetAssociation(
  877. o_ppObj); // out
  878. }
  879. }
  880. void CIISInstProvider::WorkerGetObjectAsync(
  881. IWbemClassObject** o_ppObj,
  882. BSTR i_bstrObjPath,
  883. bool i_bCreateKeyIfNotExist)
  884. {
  885. WMI_CLASS* pWmiClass = NULL;
  886. WMI_ASSOCIATION* pWmiAssoc = NULL;
  887. CMetabase metabase;
  888. CInstanceHelper InstanceHelper(i_bstrObjPath, m_pNamespace);
  889. if(!InstanceHelper.IsAssoc())
  890. {
  891. InstanceHelper.GetInstance(
  892. i_bCreateKeyIfNotExist, // in
  893. &metabase, // in/out
  894. o_ppObj); // out
  895. }
  896. else
  897. {
  898. InstanceHelper.GetAssociation(
  899. o_ppObj); // out
  900. }
  901. }
  902. void CIISInstProvider::ValidatePutParsedObject(
  903. ParsedObjectPath* i_pParsedObject,
  904. IWbemClassObject* i_pObj,
  905. bool* io_pbInstanceNameSame,
  906. bool* io_pbInstanceExists,
  907. WMI_CLASS** o_ppWmiClass
  908. )
  909. /*++
  910. Synopsis:
  911. Validates stuff before a Put operation.
  912. - Checks to see that the user is not changing the instance's
  913. primary key.
  914. - Verifies the parent metabase node exists.
  915. - Checks the container class list of the parent node in the metabase
  916. to see if it contains the node we are trying to insert.
  917. - Throws on failure. You should not continue with the put operation.
  918. Arguments: [i_pParsedObject] -
  919. --*/
  920. {
  921. DBG_ASSERT(i_pParsedObject != NULL);
  922. DBG_ASSERT(i_pObj != NULL);
  923. DBG_ASSERT(m_pNamespace != NULL);
  924. WMI_CLASS* pWMIClass = NULL;
  925. WMI_ASSOCIATION* pWMIAssoc = NULL;
  926. _bstr_t bstrMbPath;
  927. HRESULT hr = WBEM_S_NO_ERROR;
  928. if(CUtils::GetClass(i_pParsedObject->m_pClass,&pWMIClass))
  929. {
  930. }
  931. else if(CUtils::GetAssociation(i_pParsedObject->m_pClass,&pWMIAssoc))
  932. {
  933. THROW_ON_ERROR(WBEM_E_INVALID_OPERATION);
  934. }
  935. else
  936. {
  937. THROW_ON_ERROR(WBEM_E_INVALID_CLASS)
  938. }
  939. if(o_ppWmiClass)
  940. {
  941. *o_ppWmiClass = pWMIClass;
  942. }
  943. bool bSpecialPut = false;
  944. if( i_pParsedObject->m_dwNumKeys == 0)
  945. {
  946. if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  947. pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsFtpServer )
  948. {
  949. bSpecialPut = true;
  950. }
  951. else
  952. {
  953. THROW_ON_ERROR(WBEM_E_INVALID_OBJECT);
  954. }
  955. }
  956. if(!bSpecialPut)
  957. {
  958. CUtils::GetMetabasePath(NULL, i_pParsedObject, pWMIClass, bstrMbPath);
  959. DBG_ASSERT(((LPWSTR)bstrMbPath) != NULL);
  960. }
  961. //
  962. // Get the instance qualifiers in order to eventually evaluate
  963. // that the user has not tried to change the primary key on
  964. // this instance.
  965. //
  966. const ULONG iQuals = 2;
  967. _variant_t avtQualValues[iQuals];
  968. LPCWSTR awszQualNames[iQuals];
  969. DBG_ASSERT(g_idxInstanceExists < iQuals);
  970. DBG_ASSERT(g_idxInstanceName < iQuals);
  971. awszQualNames[g_idxInstanceExists] = g_wszInstanceExists;
  972. awszQualNames[g_idxInstanceName] = g_wszInstanceName;
  973. hr = CUtils::GetQualifiers(i_pObj, awszQualNames, avtQualValues, iQuals);
  974. THROW_ON_ERROR(hr);
  975. //
  976. // We assume the instance names are the same unless we can explicitly
  977. // detect they are not.
  978. //
  979. bool bInstanceNameSame = true;
  980. if( avtQualValues[g_idxInstanceName].vt == VT_BSTR &&
  981. avtQualValues[g_idxInstanceName].bstrVal != NULL)
  982. {
  983. if(!bSpecialPut)
  984. {
  985. if(_wcsicmp(avtQualValues[g_idxInstanceName].bstrVal, bstrMbPath) != 0)
  986. {
  987. bInstanceNameSame = false;
  988. }
  989. }
  990. else
  991. {
  992. bInstanceNameSame = false;
  993. }
  994. }
  995. bool bInstanceExists = false;
  996. if( avtQualValues[g_idxInstanceExists].vt == VT_BOOL &&
  997. avtQualValues[g_idxInstanceExists].boolVal )
  998. {
  999. bInstanceExists = true;
  1000. }
  1001. if(bInstanceExists && !bInstanceNameSame)
  1002. {
  1003. //
  1004. // Someone has tried to change the primary key.
  1005. //
  1006. CIIsProvException e;
  1007. e.SetMC(WBEM_E_FAILED, IISWMI_CANNOT_CHANGE_PRIMARY_KEY_FIELD, NULL);
  1008. DBGPRINTF((DBG_CONTEXT, "Cannot change primary key field\n"));
  1009. throw e;
  1010. }
  1011. if(io_pbInstanceExists)
  1012. {
  1013. *io_pbInstanceExists = bInstanceExists;
  1014. }
  1015. if(io_pbInstanceNameSame)
  1016. {
  1017. *io_pbInstanceNameSame = bInstanceNameSame;
  1018. }
  1019. //
  1020. // Now verify that if this is a new class, creation is allowed.
  1021. //
  1022. if(!bInstanceExists && !pWMIClass->bCreateAllowed)
  1023. {
  1024. CIIsProvException e;
  1025. e.SetMC(WBEM_E_FAILED, IISWMI_INSTANCE_CREATION_DISALLOWED, NULL);
  1026. DBGPRINTF((DBG_CONTEXT, "Instance creation disallowed\n"));
  1027. throw e;
  1028. }
  1029. if(bSpecialPut)
  1030. {
  1031. return;
  1032. }
  1033. //
  1034. // Now, validate the keytype against the parent's container
  1035. // class list. The return cases below are the few times
  1036. // we actually won't do this validation.
  1037. //
  1038. METADATA_HANDLE hKey = NULL;
  1039. if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE ||
  1040. pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL ||
  1041. pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_IPSecurity)
  1042. {
  1043. return;
  1044. }
  1045. if(((LPWSTR)bstrMbPath) && _wcsicmp(bstrMbPath, L"/LM") == 0)
  1046. {
  1047. return;
  1048. }
  1049. ULONG cch = wcslen(bstrMbPath);
  1050. CComBSTR sbstrMbParentPath(cch);
  1051. if(sbstrMbParentPath.m_str == NULL)
  1052. {
  1053. THROW_ON_ERROR(WBEM_E_OUT_OF_MEMORY);
  1054. }
  1055. hr = CUtils::GetParentMetabasePath(
  1056. bstrMbPath,
  1057. sbstrMbParentPath);
  1058. if(FAILED(hr))
  1059. {
  1060. //
  1061. // There is no parent node in the string specified
  1062. //
  1063. return;
  1064. }
  1065. //
  1066. // Get parent keytype from metabase
  1067. //
  1068. WMI_CLASS* pWMIParentClass = NULL;
  1069. CMetabase metabase;
  1070. _variant_t vt;
  1071. hKey = metabase.OpenKey(sbstrMbParentPath, false);
  1072. metabase.Get(hKey, &METABASE_PROPERTY_DATA::s_KeyType, m_pNamespace, vt, NULL, NULL);
  1073. metabase.CloseKey(hKey);
  1074. if( vt.vt != VT_BSTR)
  1075. {
  1076. CIIsProvException e;
  1077. e.SetMC(
  1078. WBEM_E_INVALID_OBJECT,
  1079. IISWMI_NO_PARENT_KEYTYPE,
  1080. NULL,
  1081. pWMIClass->pkt->m_pszName);
  1082. DBGPRINTF((DBG_CONTEXT, "No parent keytype.\n"));
  1083. throw e;
  1084. }
  1085. //
  1086. // Walk thru the current class's inverse container class list and see
  1087. // if the parent keytype is there.
  1088. //
  1089. if(!CUtils::GetClass(vt.bstrVal, &pWMIParentClass))
  1090. {
  1091. if( _wcsicmp(vt.bstrVal, L"IIs_ROOT") == 0 &&
  1092. pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_IIsComputer )
  1093. {
  1094. return;
  1095. }
  1096. else
  1097. {
  1098. CIIsProvException e;
  1099. e.SetMC(
  1100. WBEM_E_INVALID_OBJECT,
  1101. IISWMI_INVALID_PARENT_KEYTYPE,
  1102. NULL,
  1103. pWMIClass->pkt->m_pszName,
  1104. L"<NULL>");
  1105. DBGPRINTF((DBG_CONTEXT, "Invalid parent keytype.\n"));
  1106. throw e;
  1107. }
  1108. }
  1109. METABASE_KEYTYPE_NODE* pKtNode = pWMIClass->pkt->m_pKtListInverseCCL;
  1110. while(pKtNode != NULL)
  1111. {
  1112. if(pWMIParentClass->pkt == pKtNode->m_pKt)
  1113. {
  1114. break;
  1115. }
  1116. pKtNode = pKtNode->m_pKtNext;
  1117. }
  1118. if(pKtNode == NULL)
  1119. {
  1120. CIIsProvException e;
  1121. e.SetMC(
  1122. WBEM_E_INVALID_OBJECT,
  1123. IISWMI_INVALID_PARENT_KEYTYPE,
  1124. NULL,
  1125. pWMIClass->pkt->m_pszName,
  1126. pWMIParentClass->pkt->m_pszName);
  1127. DBGPRINTF((DBG_CONTEXT, "Invalid parent keytype.\n"));
  1128. throw e;
  1129. }
  1130. }
  1131. void CIISInstProvider::WorkerPutObjectAsync(
  1132. IWbemClassObject* i_pObj,
  1133. IWbemClassObject* i_pObjOld, // can be NULL
  1134. ParsedObjectPath* i_pParsedObject,
  1135. long i_lFlags,
  1136. bool i_bInstanceExists,
  1137. BSTR* o_pbstrObjPath
  1138. )
  1139. {
  1140. DBG_ASSERT(i_pObj != NULL);
  1141. DBG_ASSERT(i_pParsedObject != NULL);
  1142. DBG_ASSERT(m_pNamespace != NULL);
  1143. DBG_ASSERT(o_pbstrObjPath != NULL);
  1144. DBG_ASSERT(*o_pbstrObjPath == NULL);
  1145. *o_pbstrObjPath = NULL;
  1146. CComBSTR sbstrObjPath;
  1147. HRESULT hr = WBEM_S_NO_ERROR;
  1148. METABASE_PROPERTY** ppmbp;
  1149. _bstr_t bstrMbPath;
  1150. WMI_CLASS* pWMIClass;
  1151. METADATA_HANDLE hKey = NULL;
  1152. DWORD dwQuals = 0;
  1153. if (!CUtils::GetClass(i_pParsedObject->m_pClass,&pWMIClass))
  1154. throw (HRESULT)WBEM_E_INVALID_CLASS;
  1155. CUtils::GetMetabasePath(NULL,i_pParsedObject,pWMIClass,bstrMbPath);
  1156. //
  1157. // if AdminACL
  1158. //
  1159. if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL ||
  1160. pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE
  1161. )
  1162. {
  1163. CAdminACL objACL;
  1164. hr = objACL.OpenSD(bstrMbPath);
  1165. if( SUCCEEDED(hr) )
  1166. hr = objACL.PutObjectAsync(i_pObj, i_pParsedObject, pWMIClass);
  1167. THROW_ON_ERROR(hr);
  1168. return;
  1169. }
  1170. //
  1171. // IPSecurity
  1172. //
  1173. if( pWMIClass->pkt == &METABASE_KEYTYPE_DATA::s_TYPE_IPSecurity )
  1174. {
  1175. CIPSecurity objIPSec;
  1176. CMetabase metabase;
  1177. hr = objIPSec.OpenSD(bstrMbPath, metabase);
  1178. if( SUCCEEDED(hr) )
  1179. hr = objIPSec.PutObjectAsync(i_pObj);
  1180. THROW_ON_ERROR(hr);
  1181. return;
  1182. }
  1183. //
  1184. // Walk thru the properties
  1185. //
  1186. CMetabase metabase;
  1187. hKey = metabase.CreateKey(bstrMbPath);
  1188. _variant_t vt;
  1189. _variant_t vtOld;
  1190. _variant_t* pvtOld;
  1191. _bstr_t bstrPropName;
  1192. for (ppmbp=pWMIClass->ppmbp;*ppmbp && hr==WBEM_S_NO_ERROR; ppmbp++)
  1193. {
  1194. bstrPropName = (*ppmbp)->pszPropName;
  1195. hr = i_pObj->Get(bstrPropName, 0, &vt, NULL, NULL);
  1196. //
  1197. // Just ignore properties that are not in the repository.
  1198. //
  1199. if(FAILED(hr))
  1200. {
  1201. hr = WBEM_S_NO_ERROR;
  1202. continue;
  1203. }
  1204. //
  1205. // Get the property qualifiers
  1206. //
  1207. hr = CUtils::GetPropertyQualifiers(i_pObj, bstrPropName, &dwQuals);
  1208. THROW_E_ON_ERROR(hr,*ppmbp);
  1209. pvtOld = NULL;
  1210. if(i_pObjOld != NULL)
  1211. {
  1212. hr = i_pObjOld->Get(bstrPropName, 0, &vtOld, NULL, NULL);
  1213. pvtOld = &vtOld;
  1214. THROW_E_ON_ERROR(hr,*ppmbp);
  1215. }
  1216. THROW_E_ON_ERROR(hr,*ppmbp);
  1217. if (vt.vt == VT_NULL)
  1218. {
  1219. //
  1220. // Only delete non-flag properties.
  1221. //
  1222. if ((*ppmbp)->dwMDMask == 0 && vtOld.vt != VT_NULL)
  1223. {
  1224. if(i_bInstanceExists)
  1225. {
  1226. metabase.DeleteData(hKey, *ppmbp, true);
  1227. }
  1228. else
  1229. {
  1230. metabase.DeleteData(hKey, *ppmbp, false);
  1231. }
  1232. }
  1233. continue;
  1234. }
  1235. metabase.Put(
  1236. hKey,
  1237. *ppmbp,
  1238. m_pNamespace,
  1239. vt,
  1240. pvtOld,
  1241. dwQuals,
  1242. i_bInstanceExists);
  1243. vt.Clear();
  1244. vtOld.Clear();
  1245. }
  1246. if( pWMIClass->pkt != NULL &&
  1247. pWMIClass->pkt->m_pszName != NULL &&
  1248. pWMIClass->pkt != &METABASE_KEYTYPE_DATA::s_IIsObject )
  1249. {
  1250. vt = pWMIClass->pkt->m_pszName;
  1251. metabase.PutString(hKey, &METABASE_PROPERTY_DATA::s_KeyType, vt, NULL);
  1252. }
  1253. metabase.CloseKey(hKey);
  1254. hr = CUtils::ConstructObjectPath(bstrMbPath, pWMIClass, &sbstrObjPath);
  1255. THROW_ON_ERROR(hr);
  1256. //
  1257. // Set out parameters if everything succeeds
  1258. //
  1259. *o_pbstrObjPath = sbstrObjPath.Detach();
  1260. }
  1261. void CIISInstProvider::WorkerEnumObjectAsync(
  1262. BSTR i_bstrClassName,
  1263. IWbemObjectSink FAR* i_pHandler
  1264. )
  1265. {
  1266. WMI_CLASS* pClass;
  1267. WMI_ASSOCIATION* pAssociation = NULL;
  1268. ParsedObjectPath ParsedObject; //deconstructer frees memory
  1269. if (CUtils::GetAssociation(i_bstrClassName,&pAssociation))
  1270. {
  1271. CEnum EnumAssociation;
  1272. EnumAssociation.Init(
  1273. i_pHandler,
  1274. m_pNamespace,
  1275. &ParsedObject,
  1276. pAssociation->pcRight->pszMetabaseKey,
  1277. pAssociation
  1278. );
  1279. EnumAssociation.Recurse(
  1280. NULL,
  1281. &METABASE_KEYTYPE_DATA::s_IIsComputer,
  1282. NULL,
  1283. pAssociation->pcRight->pszKeyName,
  1284. pAssociation->pcRight->pkt
  1285. );
  1286. }
  1287. else if (CUtils::GetClass(i_bstrClassName,&pClass))
  1288. {
  1289. if (!ParsedObject.SetClassName(pClass->pszClassName))
  1290. throw (HRESULT)WBEM_E_FAILED;
  1291. CEnum EnumObject;
  1292. EnumObject.Init(
  1293. i_pHandler,
  1294. m_pNamespace,
  1295. &ParsedObject,
  1296. pClass->pszMetabaseKey,
  1297. NULL
  1298. );
  1299. EnumObject.Recurse(
  1300. NULL,
  1301. &METABASE_KEYTYPE_DATA::s_NO_TYPE,
  1302. NULL,
  1303. pClass->pszKeyName,
  1304. pClass->pkt
  1305. );
  1306. }
  1307. else
  1308. throw (HRESULT)WBEM_E_INVALID_CLASS;
  1309. }
  1310. void CIISInstProvider::WorkerExecWebAppMethod(
  1311. LPCWSTR i_wszMbPath,
  1312. LPCWSTR i_wszClassName,
  1313. WMI_METHOD* i_pMethod,
  1314. IWbemContext* i_pCtx,
  1315. IWbemClassObject* i_pInParams,
  1316. IWbemObjectSink* i_pHandler,
  1317. CWbemServices* i_pNameSpace
  1318. )
  1319. {
  1320. HRESULT hr = WBEM_S_NO_ERROR;
  1321. _variant_t vt; // stores the parameter value
  1322. _variant_t vt2; // stores the parameter value
  1323. _variant_t vt3; // stores the parameter value
  1324. CWebAppMethod obj; // encapsulates all the web app methods
  1325. if(i_pMethod == &METHODS::s_AppCreate)
  1326. {
  1327. if(i_pInParams == NULL)
  1328. {
  1329. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1330. }
  1331. hr = i_pInParams->Get(PARAMS::s_InProcFlag.pszParamName, 0, &vt, NULL, NULL);
  1332. THROW_ON_ERROR(hr);
  1333. hr = i_pInParams->Get(PARAMS::s_AppPoolName.pszParamName, 0, &vt2, NULL, NULL);
  1334. THROW_ON_ERROR(hr);
  1335. hr = i_pInParams->Get(PARAMS::s_bCreate.pszParamName, 0, &vt3, NULL, NULL);
  1336. THROW_ON_ERROR(hr);
  1337. if (vt3.vt != VT_BOOL) {
  1338. hr = obj.AppCreate(i_wszMbPath, vt,
  1339. CUtils::ExtractBstrFromVt(&vt2, PARAMS::s_AppPoolName.pszParamName),
  1340. false);
  1341. }
  1342. else {
  1343. hr = obj.AppCreate(i_wszMbPath, vt,
  1344. CUtils::ExtractBstrFromVt(&vt2, PARAMS::s_AppPoolName.pszParamName),
  1345. vt3);
  1346. }
  1347. }
  1348. else if(i_pMethod == &METHODS::s_AppCreate2)
  1349. {
  1350. if(i_pInParams == NULL)
  1351. {
  1352. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1353. }
  1354. hr = i_pInParams->Get(PARAMS::s_AppMode.pszParamName, 0, &vt, NULL, NULL);
  1355. THROW_ON_ERROR(hr);
  1356. hr = i_pInParams->Get(PARAMS::s_AppPoolName.pszParamName, 0, &vt2, NULL, NULL);
  1357. THROW_ON_ERROR(hr);
  1358. hr = i_pInParams->Get(PARAMS::s_bCreate.pszParamName, 0, &vt3, NULL, NULL);
  1359. THROW_ON_ERROR(hr);
  1360. if (vt3.vt != VT_BOOL) {
  1361. hr = obj.AppCreate(i_wszMbPath, vt,
  1362. CUtils::ExtractBstrFromVt(&vt2, PARAMS::s_AppPoolName.pszParamName),
  1363. false);
  1364. }
  1365. else {
  1366. hr = obj.AppCreate(i_wszMbPath, vt,
  1367. CUtils::ExtractBstrFromVt(&vt2, PARAMS::s_AppPoolName.pszParamName),
  1368. vt3);
  1369. }
  1370. }
  1371. else if(i_pMethod == &METHODS::s_AppDelete)
  1372. {
  1373. if(i_pInParams == NULL)
  1374. {
  1375. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1376. }
  1377. hr = i_pInParams->Get(PARAMS::s_Recursive.pszParamName, 0, &vt, NULL, NULL);
  1378. THROW_ON_ERROR(hr);
  1379. hr = obj.AppDelete(i_wszMbPath, vt);
  1380. }
  1381. else if(i_pMethod == &METHODS::s_AppDisable)
  1382. {
  1383. if(i_pInParams == NULL)
  1384. {
  1385. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1386. }
  1387. hr = i_pInParams->Get(PARAMS::s_Recursive.pszParamName, 0, &vt, NULL, NULL);
  1388. THROW_ON_ERROR(hr);
  1389. hr = obj.AppDisable(i_wszMbPath, vt);
  1390. }
  1391. else if(i_pMethod == &METHODS::s_AppEnable)
  1392. {
  1393. if(i_pInParams == NULL)
  1394. {
  1395. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1396. }
  1397. hr = i_pInParams->Get(PARAMS::s_Recursive.pszParamName, 0, &vt, NULL, NULL);
  1398. THROW_ON_ERROR(hr);
  1399. hr = obj.AppEnable(i_wszMbPath, vt);
  1400. }
  1401. else if(i_pMethod == &METHODS::s_AppUnLoad)
  1402. {
  1403. if(i_pInParams == NULL)
  1404. {
  1405. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1406. }
  1407. hr = i_pInParams->Get(PARAMS::s_Recursive.pszParamName, 0, &vt, NULL, NULL);
  1408. THROW_ON_ERROR(hr);
  1409. hr = obj.AppUnLoad(i_wszMbPath, vt);
  1410. }
  1411. else if(i_pMethod == &METHODS::s_AppGetStatus)
  1412. {
  1413. //
  1414. // call method - AppGetStatus
  1415. //
  1416. DWORD dwStatus;
  1417. hr = obj.AppGetStatus(i_wszMbPath, &dwStatus);
  1418. THROW_ON_ERROR(hr);
  1419. CComPtr<IWbemClassObject> spOutParams = NULL;
  1420. hr = CUtils::CreateEmptyMethodInstance(
  1421. i_pNameSpace,
  1422. i_pCtx,
  1423. i_wszClassName,
  1424. i_pMethod->pszMethodName,
  1425. &spOutParams);
  1426. THROW_ON_ERROR(hr);
  1427. //
  1428. // put it into the output object
  1429. //
  1430. vt.vt = VT_I4;
  1431. vt.lVal = dwStatus;
  1432. hr = spOutParams->Put(L"ReturnValue", 0, &vt, 0);
  1433. THROW_ON_ERROR(hr);
  1434. //
  1435. // Send the output object back to the client via the sink. Then
  1436. // release the pointers and free the strings.
  1437. //
  1438. hr = i_pHandler->Indicate(1, &spOutParams);
  1439. }
  1440. else if(i_pMethod == &METHODS::s_AspAppRestart)
  1441. {
  1442. hr = obj.AspAppRestart(i_wszMbPath);
  1443. }
  1444. else
  1445. {
  1446. hr = WBEM_E_INVALID_METHOD;
  1447. }
  1448. THROW_ON_ERROR(hr);
  1449. }
  1450. void CIISInstProvider::WorkerExecFtpServiceMethod(
  1451. LPCWSTR i_wszMbPath,
  1452. WMI_CLASS* i_pClass,
  1453. WMI_METHOD* i_pMethod,
  1454. IWbemContext* i_pCtx,
  1455. IWbemClassObject* i_pInParams,
  1456. IWbemObjectSink* i_pHandler)
  1457. {
  1458. DBG_ASSERT(i_pClass != NULL);
  1459. DBG_ASSERT(i_pHandler != NULL);
  1460. DBG_ASSERT(m_pNamespace != NULL);
  1461. HRESULT hr = WBEM_S_NO_ERROR;
  1462. if(i_pMethod == &METHODS::s_ServiceCreateNewServer)
  1463. {
  1464. if(i_pInParams == NULL)
  1465. {
  1466. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1467. }
  1468. CServiceMethod ServiceMethod(SC_MSFTPSVC);
  1469. hr = ServiceMethod.Init();
  1470. THROW_ON_ERROR(hr);
  1471. CComPtr<IWbemClassObject> spOutParams;
  1472. hr = ServiceMethod.CreateNewSite(
  1473. m_pNamespace,
  1474. i_wszMbPath,
  1475. i_pCtx,
  1476. i_pClass,
  1477. i_pMethod,
  1478. i_pInParams,
  1479. &spOutParams);
  1480. THROW_ON_ERROR(hr);
  1481. hr = i_pHandler->Indicate(1, &spOutParams);
  1482. THROW_ON_ERROR(hr);
  1483. }
  1484. else
  1485. {
  1486. hr = WBEM_E_INVALID_METHOD;
  1487. }
  1488. THROW_ON_ERROR(hr);
  1489. }
  1490. void CIISInstProvider::WorkerExecWebServiceMethod(
  1491. LPCWSTR i_wszMbPath,
  1492. WMI_CLASS* i_pClass,
  1493. WMI_METHOD* i_pMethod,
  1494. IWbemContext* i_pCtx,
  1495. IWbemClassObject* i_pInParams,
  1496. IWbemObjectSink* i_pHandler
  1497. )
  1498. {
  1499. DBG_ASSERT(i_pHandler != NULL);
  1500. DBG_ASSERT(m_pNamespace != NULL);
  1501. HRESULT hr = WBEM_S_NO_ERROR;
  1502. METADATA_HANDLE hKey = 0;
  1503. if(i_pMethod == &METHODS::s_GetCurrentMode)
  1504. {
  1505. _variant_t vtServerMode;
  1506. CAppPoolMethod obj;
  1507. obj.GetCurrentMode(&vtServerMode);
  1508. //
  1509. // Set out params
  1510. //
  1511. CComPtr<IWbemClassObject> spOutParams;
  1512. hr = CUtils::CreateEmptyMethodInstance(
  1513. m_pNamespace,
  1514. i_pCtx,
  1515. i_pClass->pszClassName,
  1516. i_pMethod->pszMethodName,
  1517. &spOutParams);
  1518. THROW_ON_ERROR(hr);
  1519. hr = spOutParams->Put(PARAMS::s_ServerMode.pszParamName, 0, &vtServerMode, 0);
  1520. THROW_ON_ERROR(hr);
  1521. hr = i_pHandler->Indicate(1, &spOutParams);
  1522. THROW_ON_ERROR(hr);
  1523. }
  1524. else if(i_pMethod == &METHODS::s_ServiceCreateNewServer)
  1525. {
  1526. if(i_pInParams == NULL)
  1527. {
  1528. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1529. }
  1530. CServiceMethod ServiceMethod(SC_W3SVC);
  1531. hr = ServiceMethod.Init();
  1532. THROW_ON_ERROR(hr);
  1533. CComPtr<IWbemClassObject> spOutParams;
  1534. hr = ServiceMethod.CreateNewSite(
  1535. m_pNamespace,
  1536. i_wszMbPath,
  1537. i_pCtx,
  1538. i_pClass,
  1539. i_pMethod,
  1540. i_pInParams,
  1541. &spOutParams);
  1542. THROW_ON_ERROR(hr);
  1543. hr = i_pHandler->Indicate(1, &spOutParams);
  1544. THROW_ON_ERROR(hr);
  1545. }
  1546. else
  1547. {
  1548. hr = WBEM_E_INVALID_METHOD;
  1549. }
  1550. THROW_ON_ERROR(hr);
  1551. }
  1552. void CIISInstProvider::WorkerExecComputerMethod(
  1553. LPCWSTR i_wszMbPath,
  1554. LPCWSTR i_wszClassName,
  1555. WMI_METHOD* i_pMethod,
  1556. IWbemContext* i_pCtx,
  1557. IWbemClassObject* i_pInParams,
  1558. IWbemObjectSink* i_pHandler,
  1559. CWbemServices* i_pNameSpace
  1560. )
  1561. {
  1562. HRESULT hr;
  1563. _variant_t vt1, vt2, vt3, vt4, vt5, vt6;
  1564. CMetabase obj;
  1565. if(i_pMethod == &METHODS::s_SaveData)
  1566. {
  1567. hr = obj.SaveData();
  1568. THROW_ON_ERROR(hr);
  1569. }
  1570. else if(i_pMethod == &METHODS::s_EnumBackups)
  1571. {
  1572. if(i_pInParams == NULL)
  1573. {
  1574. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1575. }
  1576. //
  1577. // get in params
  1578. //
  1579. hr = i_pInParams->Get(PARAMS::s_BackupLocation.pszParamName, 0, &vt1, NULL, NULL);
  1580. THROW_ON_ERROR(hr);
  1581. hr = i_pInParams->Get(PARAMS::s_IndexIn.pszParamName, 0, &vt2, NULL, NULL);
  1582. THROW_ON_ERROR(hr);
  1583. //
  1584. // make in/out params
  1585. //
  1586. WCHAR BackupLocation[MD_BACKUP_MAX_LEN] = {0};
  1587. if(vt1.vt == VT_BSTR && vt1.bstrVal != NULL)
  1588. {
  1589. ULONG cchBackupLocation = wcslen(vt1.bstrVal);
  1590. if(cchBackupLocation < MD_BACKUP_MAX_LEN)
  1591. {
  1592. memcpy(
  1593. BackupLocation,
  1594. vt1.bstrVal,
  1595. sizeof(WCHAR)*(cchBackupLocation+1));
  1596. }
  1597. else
  1598. {
  1599. CIIsProvException e;
  1600. e.SetHR(
  1601. WBEM_E_INVALID_PARAMETER,
  1602. PARAMS::s_BackupLocation.pszParamName);
  1603. throw e;
  1604. }
  1605. }
  1606. //
  1607. // define out params
  1608. //
  1609. DWORD BackupVersionOut;
  1610. FILETIME BackupDateTimeOut;
  1611. //
  1612. // call method - EnumBackups.
  1613. //
  1614. hr = obj.EnumBackups(
  1615. BackupLocation,
  1616. &BackupVersionOut,
  1617. &BackupDateTimeOut,
  1618. CUtils::ExtractLongFromVt(&vt2, PARAMS::s_IndexIn.pszParamName));
  1619. THROW_ON_ERROR(hr);
  1620. CComPtr<IWbemClassObject> spOutParams;
  1621. hr = CUtils::CreateEmptyMethodInstance(
  1622. i_pNameSpace,
  1623. i_pCtx,
  1624. i_wszClassName,
  1625. i_pMethod->pszMethodName,
  1626. &spOutParams);
  1627. THROW_ON_ERROR(hr);
  1628. //
  1629. // put it into the output object
  1630. // out BackupLocation
  1631. //
  1632. vt1 = BackupLocation;
  1633. hr = spOutParams->Put(PARAMS::s_BackupLocation.pszParamName, 0, &vt1, 0);
  1634. THROW_ON_ERROR(hr);
  1635. //
  1636. // out BackupVersionOut
  1637. //
  1638. vt1.vt = VT_I4;
  1639. vt1.lVal = BackupVersionOut;
  1640. hr = spOutParams->Put(PARAMS::s_BackupVersionOut.pszParamName, 0, &vt1, 0);
  1641. THROW_ON_ERROR(hr);
  1642. //
  1643. // out BackupDateTimeOut (UTC time)
  1644. //
  1645. WCHAR datetime[30];
  1646. CUtils::FileTimeToWchar(&BackupDateTimeOut, datetime);
  1647. vt1 = datetime;
  1648. hr = spOutParams->Put(PARAMS::s_BackupDateTimeOut.pszParamName, 0, &vt1, 0);
  1649. THROW_ON_ERROR(hr);
  1650. //
  1651. // Send the output object back to the client via the sink. Then
  1652. // release the pointers and free the strings.
  1653. //
  1654. hr = i_pHandler->Indicate(1, &spOutParams);
  1655. }
  1656. else if(i_pMethod == &METHODS::s_BackupWithPasswd)
  1657. {
  1658. if(i_pInParams == NULL)
  1659. {
  1660. THROW_ON_ERROR(WBEM_E_INVALID_PARAMETER);
  1661. }
  1662. hr = i_pInParams->Get(PARAMS::s_BackupLocation.pszParamName, 0, &vt1, NULL, NULL);
  1663. THROW_ON_ERROR(hr);
  1664. hr = i_pInParams->Get(PARAMS::s_BackupVersion.pszParamName, 0, &vt2, NULL, NULL);
  1665. THROW_ON_ERROR(hr);
  1666. hr = i_pInParams->Get(PARAMS::s_BackupFlags.pszParamName, 0, &vt3, NULL, NULL);
  1667. THROW_ON_ERROR(hr);
  1668. hr = i_pInParams->Get(PARAMS::s_Password.pszParamName, 0, &vt4, NULL, NULL);
  1669. THROW_ON_ERROR(hr);
  1670. hr = obj.BackupWithPasswd(
  1671. CUtils::ExtractBstrFromVt(&vt1, PARAMS::s_BackupLocation.pszParamName),
  1672. CUtils::ExtractLongFromVt(&vt2, PARAMS::s_BackupVersion.pszParamName),
  1673. CUtils::ExtractLongFromVt(&vt3, PARAMS::s_BackupFlags.pszParamName),
  1674. CUtils::ExtractBstrFromVt(&vt4, PARAMS::s_Password.pszParamName));
  1675. }
  1676. else if(i_pMethod == &METHODS::s_DeleteBackup)
  1677. {
  1678. if(i_pInParams == NULL)
  1679. {
  1680. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1681. }
  1682. hr = i_pInParams->Get(PARAMS::s_BackupLocation.pszParamName, 0, &vt1, NULL, NULL);
  1683. THROW_ON_ERROR(hr);
  1684. hr = i_pInParams->Get(PARAMS::s_BackupVersion.pszParamName, 0, &vt2, NULL, NULL);
  1685. THROW_ON_ERROR(hr);
  1686. hr = obj.DeleteBackup(
  1687. CUtils::ExtractBstrFromVt(&vt1, PARAMS::s_BackupLocation.pszParamName),
  1688. CUtils::ExtractLongFromVt(&vt2, PARAMS::s_BackupVersion.pszParamName));
  1689. }
  1690. else if(i_pMethod == &METHODS::s_RestoreWithPasswd)
  1691. {
  1692. if(i_pInParams == NULL)
  1693. {
  1694. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1695. }
  1696. hr = i_pInParams->Get(PARAMS::s_BackupLocation.pszParamName, 0, &vt1, NULL, NULL);
  1697. THROW_ON_ERROR(hr);
  1698. hr = i_pInParams->Get(PARAMS::s_BackupVersion.pszParamName, 0, &vt2, NULL, NULL);
  1699. THROW_ON_ERROR(hr);
  1700. hr = i_pInParams->Get(PARAMS::s_BackupFlags.pszParamName, 0, &vt3, NULL, NULL);
  1701. THROW_ON_ERROR(hr);
  1702. hr = i_pInParams->Get(PARAMS::s_Password.pszParamName, 0, &vt4, NULL, NULL);
  1703. THROW_ON_ERROR(hr);
  1704. hr = obj.RestoreWithPasswd(
  1705. CUtils::ExtractBstrFromVt(&vt1, PARAMS::s_BackupLocation.pszParamName),
  1706. CUtils::ExtractLongFromVt(&vt2, PARAMS::s_BackupVersion.pszParamName),
  1707. CUtils::ExtractLongFromVt(&vt3, PARAMS::s_BackupFlags.pszParamName),
  1708. CUtils::ExtractBstrFromVt(&vt4, PARAMS::s_Password.pszParamName));
  1709. }
  1710. else if(i_pMethod == &METHODS::s_Export)
  1711. {
  1712. if(i_pInParams == NULL)
  1713. {
  1714. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1715. }
  1716. hr = i_pInParams->Get(PARAMS::s_Passwd.pszParamName, 0, &vt1, NULL, NULL);
  1717. THROW_ON_ERROR(hr);
  1718. hr = i_pInParams->Get(PARAMS::s_FileName.pszParamName, 0, &vt2, NULL, NULL);
  1719. THROW_ON_ERROR(hr);
  1720. hr = i_pInParams->Get(PARAMS::s_SourcePath.pszParamName, 0, &vt3, NULL, NULL);
  1721. THROW_ON_ERROR(hr);
  1722. hr = i_pInParams->Get(PARAMS::s_MDFlags.pszParamName, 0, &vt4, NULL, NULL);
  1723. THROW_ON_ERROR(hr);
  1724. hr = obj.Export(
  1725. CUtils::ExtractBstrFromVt(&vt1, PARAMS::s_Passwd.pszParamName),
  1726. CUtils::ExtractBstrFromVt(&vt2, PARAMS::s_FileName.pszParamName),
  1727. CUtils::ExtractBstrFromVt(&vt3, PARAMS::s_SourcePath.pszParamName),
  1728. CUtils::ExtractLongFromVt(&vt4, PARAMS::s_MDFlags.pszParamName));
  1729. }
  1730. else if(i_pMethod == &METHODS::s_Import)
  1731. {
  1732. if(i_pInParams == NULL)
  1733. {
  1734. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1735. }
  1736. hr = i_pInParams->Get(PARAMS::s_Passwd.pszParamName, 0, &vt1, NULL, NULL);
  1737. THROW_ON_ERROR(hr);
  1738. hr = i_pInParams->Get(PARAMS::s_FileName.pszParamName, 0, &vt2, NULL, NULL);
  1739. THROW_ON_ERROR(hr);
  1740. hr = i_pInParams->Get(PARAMS::s_SourcePath.pszParamName, 0, &vt3, NULL, NULL);
  1741. THROW_ON_ERROR(hr);
  1742. hr = i_pInParams->Get(PARAMS::s_DestPath.pszParamName, 0, &vt4, NULL, NULL);
  1743. THROW_ON_ERROR(hr);
  1744. hr = i_pInParams->Get(PARAMS::s_MDFlags.pszParamName, 0, &vt5, NULL, NULL);
  1745. THROW_ON_ERROR(hr);
  1746. hr = obj.Import(
  1747. CUtils::ExtractBstrFromVt(&vt1, PARAMS::s_Passwd.pszParamName),
  1748. CUtils::ExtractBstrFromVt(&vt2, PARAMS::s_FileName.pszParamName),
  1749. CUtils::ExtractBstrFromVt(&vt3, PARAMS::s_SourcePath.pszParamName),
  1750. CUtils::ExtractBstrFromVt(&vt4, PARAMS::s_DestPath.pszParamName),
  1751. CUtils::ExtractLongFromVt(&vt5, PARAMS::s_MDFlags.pszParamName));
  1752. }
  1753. else if(i_pMethod == &METHODS::s_RestoreHistory)
  1754. {
  1755. if(i_pInParams == NULL)
  1756. {
  1757. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1758. }
  1759. hr = i_pInParams->Get(PARAMS::s_MDHistoryLocation.pszParamName, 0, &vt1, NULL, NULL);
  1760. THROW_ON_ERROR(hr);
  1761. hr = i_pInParams->Get(PARAMS::s_MajorVersion.pszParamName, 0, &vt2, NULL, NULL);
  1762. THROW_ON_ERROR(hr);
  1763. hr = i_pInParams->Get(PARAMS::s_MinorVersion.pszParamName, 0, &vt3, NULL, NULL);
  1764. THROW_ON_ERROR(hr);
  1765. hr = i_pInParams->Get(PARAMS::s_MDFlags.pszParamName, 0, &vt4, NULL, NULL);
  1766. THROW_ON_ERROR(hr);
  1767. hr = obj.RestoreHistory(
  1768. CUtils::ExtractBstrFromVt(&vt1, PARAMS::s_MDHistoryLocation.pszParamName),
  1769. CUtils::ExtractLongFromVt(&vt2, PARAMS::s_MajorVersion.pszParamName),
  1770. CUtils::ExtractLongFromVt(&vt3, PARAMS::s_MinorVersion.pszParamName),
  1771. CUtils::ExtractLongFromVt(&vt4, PARAMS::s_MDFlags.pszParamName));
  1772. }
  1773. else if(i_pMethod == &METHODS::s_EnumHistory)
  1774. {
  1775. if(i_pInParams == NULL)
  1776. {
  1777. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1778. }
  1779. //
  1780. // get in params
  1781. //
  1782. hr = i_pInParams->Get(PARAMS::s_MDHistoryLocation.pszParamName, 0, &vt1, NULL, NULL);
  1783. THROW_ON_ERROR(hr);
  1784. hr = i_pInParams->Get(PARAMS::s_EnumIndex.pszParamName, 0, &vt2, NULL, NULL);
  1785. THROW_ON_ERROR(hr);
  1786. //
  1787. // make in/out params
  1788. //
  1789. WCHAR MDHistoryLocation[MD_BACKUP_MAX_LEN] = {0};
  1790. if(vt1.vt == VT_BSTR && vt1.bstrVal != NULL)
  1791. {
  1792. ULONG cchHistoryLocation = wcslen(vt1.bstrVal);
  1793. if(cchHistoryLocation < MD_BACKUP_MAX_LEN)
  1794. {
  1795. memcpy(
  1796. MDHistoryLocation,
  1797. vt1.bstrVal,
  1798. sizeof(WCHAR)*(cchHistoryLocation+1));
  1799. }
  1800. else
  1801. {
  1802. CIIsProvException e;
  1803. e.SetHR(
  1804. WBEM_E_INVALID_PARAMETER,
  1805. PARAMS::s_MDHistoryLocation.pszParamName);
  1806. throw e;
  1807. }
  1808. }
  1809. //
  1810. // define out params
  1811. //
  1812. DWORD HistoryMajorVersionOut;
  1813. DWORD HistoryMinorVersionOut;
  1814. FILETIME HistoryDateTimeOut;
  1815. //
  1816. // call method - EnumHistory.
  1817. //
  1818. hr = obj.EnumHistory(
  1819. MDHistoryLocation,
  1820. &HistoryMajorVersionOut,
  1821. &HistoryMinorVersionOut,
  1822. &HistoryDateTimeOut,
  1823. CUtils::ExtractLongFromVt(&vt2, PARAMS::s_EnumIndex.pszParamName));
  1824. THROW_ON_ERROR(hr);
  1825. CComPtr<IWbemClassObject> spOutParams;
  1826. hr = CUtils::CreateEmptyMethodInstance(
  1827. i_pNameSpace,
  1828. i_pCtx,
  1829. i_wszClassName,
  1830. i_pMethod->pszMethodName,
  1831. &spOutParams);
  1832. THROW_ON_ERROR(hr);
  1833. //
  1834. // put it into the output object
  1835. // out MDHistoryLocation
  1836. //
  1837. vt1 = MDHistoryLocation;
  1838. hr = spOutParams->Put(PARAMS::s_MDHistoryLocation.pszParamName, 0, &vt1, 0);
  1839. THROW_ON_ERROR(hr);
  1840. //
  1841. // out HistoryMajorVersionOut
  1842. //
  1843. vt1.vt = VT_I4;
  1844. vt1.lVal = HistoryMajorVersionOut;
  1845. hr = spOutParams->Put(PARAMS::s_MajorVersion.pszParamName, 0, &vt1, 0);
  1846. THROW_ON_ERROR(hr);
  1847. //
  1848. // out HistoryMinorVersionOut
  1849. //
  1850. vt1.vt = VT_I4;
  1851. vt1.lVal = HistoryMinorVersionOut;
  1852. hr = spOutParams->Put(PARAMS::s_MinorVersion.pszParamName, 0, &vt1, 0);
  1853. THROW_ON_ERROR(hr);
  1854. //
  1855. // out HistoryDateTimeOut (UTC time)
  1856. //
  1857. WCHAR datetime[30];
  1858. CUtils::FileTimeToWchar(&HistoryDateTimeOut, datetime);
  1859. vt1 = datetime;
  1860. hr = spOutParams->Put(PARAMS::s_HistoryTime.pszParamName, 0, &vt1, 0);
  1861. THROW_ON_ERROR(hr);
  1862. //
  1863. // Send the output object back to the client via the sink. Then
  1864. // release the pointers and free the strings.
  1865. //
  1866. hr = i_pHandler->Indicate(1, &spOutParams);
  1867. }
  1868. else
  1869. {
  1870. hr = WBEM_E_INVALID_METHOD;
  1871. }
  1872. THROW_ON_ERROR(hr);
  1873. }
  1874. void CIISInstProvider::WorkerExecAppPoolMethod(
  1875. LPCWSTR i_wszMbPath,
  1876. LPCWSTR i_wszClassName,
  1877. WMI_METHOD* i_pMethod,
  1878. IWbemContext* i_pCtx,
  1879. IWbemClassObject* i_pInParams,
  1880. IWbemObjectSink* i_pHandler,
  1881. CWbemServices* i_pNameSpace
  1882. )
  1883. {
  1884. DBG_ASSERT(i_wszMbPath != NULL);
  1885. DBG_ASSERT(i_pNameSpace != NULL);
  1886. DBG_ASSERT(i_pHandler != NULL);
  1887. HRESULT hr = WBEM_S_NO_ERROR;
  1888. CAppPoolMethod obj;
  1889. if(i_pMethod == &METHODS::s_EnumAppsInPool)
  1890. {
  1891. CComVariant vtApplications;
  1892. obj.EnumAppsInPool(i_wszMbPath, &vtApplications);
  1893. CComPtr<IWbemClassObject> spOutParams;
  1894. hr = CUtils::CreateEmptyMethodInstance(
  1895. i_pNameSpace,
  1896. i_pCtx,
  1897. i_wszClassName,
  1898. i_pMethod->pszMethodName,
  1899. &spOutParams);
  1900. THROW_ON_ERROR(hr);
  1901. hr = spOutParams->Put(PARAMS::s_Applications.pszParamName, 0, &vtApplications, 0);
  1902. THROW_ON_ERROR(hr);
  1903. hr = i_pHandler->Indicate(1, &spOutParams);
  1904. THROW_ON_ERROR(hr);
  1905. }
  1906. else if(i_pMethod == &METHODS::s_RecycleAppPool)
  1907. {
  1908. obj.RecycleAppPool(i_wszMbPath);
  1909. }
  1910. else if(i_pMethod == &METHODS::s_Start)
  1911. {
  1912. obj.Start(i_wszMbPath);
  1913. }
  1914. else if(i_pMethod == &METHODS::s_Stop)
  1915. {
  1916. obj.Stop(i_wszMbPath);
  1917. }
  1918. else
  1919. {
  1920. THROW_ON_ERROR(WBEM_E_INVALID_METHOD);
  1921. }
  1922. }
  1923. void CIISInstProvider::WorkerExecCertMapperMethod(
  1924. LPCWSTR i_wszMbPath,
  1925. LPCWSTR i_wszClassName,
  1926. WMI_METHOD* i_pMethod,
  1927. IWbemContext* i_pCtx,
  1928. IWbemClassObject* i_pInParams,
  1929. IWbemObjectSink* i_pHandler,
  1930. CWbemServices* i_pNameSpace
  1931. )
  1932. {
  1933. HRESULT hr;
  1934. _variant_t vt1, vt2, vt3=L"1", vt4=L"1", vt5=L"1", vt6=L"1", vt7=L"1";
  1935. CCertMapperMethod obj(i_wszMbPath);
  1936. if(i_pMethod == &METHODS::s_CreateMapping)
  1937. {
  1938. if(i_pInParams == NULL)
  1939. {
  1940. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS)
  1941. }
  1942. hr = i_pInParams->Get(PARAMS::s_vCert.pszParamName, 0, &vt1, NULL, NULL);
  1943. THROW_ON_ERROR(hr);
  1944. hr = i_pInParams->Get(PARAMS::s_NtAcct.pszParamName, 0, &vt2, NULL, NULL);
  1945. THROW_ON_ERROR(hr);
  1946. hr = i_pInParams->Get(PARAMS::s_NtPwd.pszParamName, 0, &vt3, NULL, NULL);
  1947. THROW_ON_ERROR(hr);
  1948. hr = i_pInParams->Get(PARAMS::s_strName.pszParamName, 0, &vt4, NULL, NULL);
  1949. THROW_ON_ERROR(hr);
  1950. hr = i_pInParams->Get(PARAMS::s_IEnabled.pszParamName, 0, &vt5, NULL, NULL);
  1951. THROW_ON_ERROR(hr);
  1952. //
  1953. // call method - CreateMapping.
  1954. //
  1955. hr = obj.CreateMapping(vt1, vt2.bstrVal, vt3.bstrVal, vt4.bstrVal, vt5);
  1956. }
  1957. else if(i_pMethod == &METHODS::s_DeleteMapping)
  1958. {
  1959. if(i_pInParams == NULL)
  1960. {
  1961. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1962. }
  1963. hr = i_pInParams->Get(PARAMS::s_IMethod.pszParamName, 0, &vt1, NULL, NULL);
  1964. THROW_ON_ERROR(hr);
  1965. hr = i_pInParams->Get(PARAMS::s_vKey.pszParamName, 0, &vt2, NULL, NULL);
  1966. THROW_ON_ERROR(hr);
  1967. //
  1968. // call method - DeleteMapping.
  1969. //
  1970. hr = obj.DeleteMapping(vt1, vt2);
  1971. }
  1972. else if(i_pMethod == &METHODS::s_GetMapping)
  1973. {
  1974. if(i_pInParams == NULL)
  1975. {
  1976. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  1977. }
  1978. //
  1979. // get in params
  1980. //
  1981. hr = i_pInParams->Get(PARAMS::s_IMethod.pszParamName, 0, &vt1, NULL, NULL);
  1982. THROW_ON_ERROR(hr);
  1983. hr = i_pInParams->Get(PARAMS::s_vKey.pszParamName, 0, &vt2, NULL, NULL);
  1984. THROW_ON_ERROR(hr);
  1985. //
  1986. // call method - GetMapping.
  1987. //
  1988. hr = obj.GetMapping(vt1, vt2, &vt3, &vt4, &vt5, &vt6, &vt7);
  1989. THROW_ON_ERROR(hr);
  1990. CComPtr<IWbemClassObject> spOutParams;
  1991. hr = CUtils::CreateEmptyMethodInstance(
  1992. i_pNameSpace,
  1993. i_pCtx,
  1994. i_wszClassName,
  1995. i_pMethod->pszMethodName,
  1996. &spOutParams);
  1997. THROW_ON_ERROR(hr);
  1998. //
  1999. // put them into the output object
  2000. //
  2001. hr = spOutParams->Put(PARAMS::s_vCert.pszParamName, 0, &vt3, 0);
  2002. THROW_ON_ERROR(hr);
  2003. hr = spOutParams->Put(PARAMS::s_NtAcct.pszParamName, 0, &vt4, 0);
  2004. THROW_ON_ERROR(hr);
  2005. hr = spOutParams->Put(PARAMS::s_NtPwd.pszParamName, 0, &vt5, 0);
  2006. THROW_ON_ERROR(hr);
  2007. hr = spOutParams->Put(PARAMS::s_strName.pszParamName, 0, &vt6, 0);
  2008. THROW_ON_ERROR(hr);
  2009. hr = spOutParams->Put(PARAMS::s_IEnabled.pszParamName, 0, &vt7, 0);
  2010. THROW_ON_ERROR(hr);
  2011. //
  2012. // Send the output object back to the client via the sink. Then
  2013. // release the pointers and free the strings.
  2014. //
  2015. hr = i_pHandler->Indicate(1, &spOutParams);
  2016. }
  2017. else if(i_pMethod == &METHODS::s_SetAcct)
  2018. {
  2019. if(i_pInParams == NULL)
  2020. {
  2021. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  2022. }
  2023. hr = i_pInParams->Get(PARAMS::s_IMethod.pszParamName, 0, &vt1, NULL, NULL);
  2024. THROW_ON_ERROR(hr);
  2025. hr = i_pInParams->Get(PARAMS::s_vKey.pszParamName, 0, &vt2, NULL, NULL);
  2026. THROW_ON_ERROR(hr);
  2027. hr = i_pInParams->Get(PARAMS::s_NtAcct.pszParamName, 0, &vt3, NULL, NULL);
  2028. THROW_ON_ERROR(hr);
  2029. //
  2030. // call method - SetAcct.
  2031. //
  2032. hr = obj.SetAcct(vt1, vt2, vt3.bstrVal);
  2033. }
  2034. else if(i_pMethod == &METHODS::s_SetEnabled)
  2035. {
  2036. if(i_pInParams == NULL)
  2037. {
  2038. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  2039. }
  2040. hr = i_pInParams->Get(PARAMS::s_IMethod.pszParamName, 0, &vt1, NULL, NULL);
  2041. THROW_ON_ERROR(hr);
  2042. hr = i_pInParams->Get(PARAMS::s_vKey.pszParamName, 0, &vt2, NULL, NULL);
  2043. THROW_ON_ERROR(hr);
  2044. hr = i_pInParams->Get(PARAMS::s_IEnabled.pszParamName, 0, &vt3, NULL, NULL);
  2045. THROW_ON_ERROR(hr);
  2046. //
  2047. // call method - SetEnabled.
  2048. //
  2049. hr = obj.SetEnabled(vt1, vt2, vt3);
  2050. }
  2051. else if(i_pMethod == &METHODS::s_SetName)
  2052. {
  2053. if(i_pInParams == NULL)
  2054. {
  2055. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  2056. }
  2057. hr = i_pInParams->Get(PARAMS::s_IMethod.pszParamName, 0, &vt1, NULL, NULL);
  2058. THROW_ON_ERROR(hr);
  2059. hr = i_pInParams->Get(PARAMS::s_vKey.pszParamName, 0, &vt2, NULL, NULL);
  2060. THROW_ON_ERROR(hr);
  2061. hr = i_pInParams->Get(PARAMS::s_strName.pszParamName, 0, &vt3, NULL, NULL);
  2062. THROW_ON_ERROR(hr);
  2063. //
  2064. // call method - SetName.
  2065. //
  2066. hr = obj.SetName(vt1, vt2, vt3.bstrVal);
  2067. }
  2068. else if(i_pMethod == &METHODS::s_SetPwd)
  2069. {
  2070. if(i_pInParams == NULL)
  2071. {
  2072. THROW_ON_ERROR(WBEM_E_INVALID_METHOD_PARAMETERS);
  2073. }
  2074. hr = i_pInParams->Get(PARAMS::s_IMethod.pszParamName, 0, &vt1, NULL, NULL);
  2075. THROW_ON_ERROR(hr);
  2076. hr = i_pInParams->Get(PARAMS::s_vKey.pszParamName, 0, &vt2, NULL, NULL);
  2077. THROW_ON_ERROR(hr);
  2078. hr = i_pInParams->Get(PARAMS::s_NtPwd.pszParamName, 0, &vt3, NULL, NULL);
  2079. THROW_ON_ERROR(hr);
  2080. //
  2081. // call method - SetPwd.
  2082. //
  2083. hr = obj.SetPwd(vt1, vt2, vt3.bstrVal);
  2084. }
  2085. else
  2086. {
  2087. hr = WBEM_E_INVALID_METHOD;
  2088. }
  2089. THROW_ON_ERROR(hr);
  2090. }