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.

773 lines
22 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows 2000 Active Directory Service domain trust verification WMI provider
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 2002
  7. //
  8. // File: TrustPrv.cpp
  9. //
  10. // Contents: Trust Monitor provider WMI interface class implementation
  11. //
  12. // Classes: CTrustPrv
  13. //
  14. // History: 22-Mar-00 EricB created
  15. //
  16. //-----------------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include "dbg.cpp"
  19. PCWSTR CLASSNAME_STRING_PROVIDER = L"Microsoft_TrustProvider";
  20. PCWSTR CLASSNAME_STRING_TRUST = L"Microsoft_DomainTrustStatus";
  21. PCWSTR CLASSNAME_STRING_LOCAL = L"Microsoft_LocalDomainInfo";
  22. PCWSTR CSTR_PROP_TRUST_LIST_LIFETIME = L"TrustListLifetime"; // uint32
  23. PCWSTR CSTR_PROP_TRUST_STATUS_LIFETIME = L"TrustStatusLifetime"; // uint32
  24. PCWSTR CSTR_PROP_TRUST_CHECK_LEVEL = L"TrustCheckLevel"; // uint32
  25. PCWSTR CSTR_PROP_RETURN_ALL_TRUSTS = L"ReturnAll"; // boolean
  26. //WCHAR * const PROVIDER_CLASS_CHANGE_QUERY = L"select * from __InstanceOperationEvent where TargetInstance.__Relpath = \"Microsoft_TrustProvider=@\"";
  27. WCHAR * const PROVIDER_CLASS_CHANGE_QUERY = L"select * from __InstanceOperationEvent where TargetInstance isa \"Microsoft_TrustProvider\"";
  28. WCHAR * const PROVIDER_CLASS_INSTANCE = L"Microsoft_TrustProvider=@";
  29. //+----------------------------------------------------------------------------
  30. //
  31. // class CTrustPrv
  32. //
  33. //-----------------------------------------------------------------------------
  34. CTrustPrv::CTrustPrv(void) :
  35. m_hMutex(NULL),
  36. m_TrustCheckLevel(DEFAULT_TRUST_CHECK_LEVEL),
  37. m_fReturnAllTrusts(TRUE)
  38. {
  39. TRACE(L"CTrustPrv::CTrustPrv(0x%08x)\n", this);
  40. m_liTrustEnumMaxAge.QuadPart = TRUSTMON_DEFAULT_ENUM_AGE;
  41. m_liVerifyMaxAge.QuadPart = TRUSTMON_DEFAULT_VERIFY_AGE;
  42. }
  43. CTrustPrv::~CTrustPrv(void)
  44. {
  45. TRACE(L"CTrustPrv::~CTrustPrv\n\n");
  46. if (m_hMutex)
  47. {
  48. CloseHandle(m_hMutex);
  49. }
  50. }
  51. //+----------------------------------------------------------------------------
  52. //
  53. // Method: CTrustPrv::IWbemProviderInit::Initialize
  54. //
  55. // Synopsis: Initialize the provider object.
  56. //
  57. // Returns: WMI error codes
  58. //
  59. //-----------------------------------------------------------------------------
  60. STDMETHODIMP
  61. CTrustPrv::Initialize(
  62. IN LPWSTR pszUser,
  63. IN LONG lFlags,
  64. IN LPWSTR pszNamespace,
  65. IN LPWSTR pszLocale,
  66. IN IWbemServices *pNamespace,
  67. IN IWbemContext *pCtx,
  68. IN IWbemProviderInitSink *pInitSink)
  69. {
  70. WBEM_VALIDATE_INTF_PTR(pNamespace);
  71. WBEM_VALIDATE_INTF_PTR(pCtx);
  72. WBEM_VALIDATE_INTF_PTR(pInitSink);
  73. TRACE(L"\nCTrustPrv::Initialize\n");
  74. HRESULT hr = WBEM_S_NO_ERROR;
  75. do
  76. {
  77. m_hMutex = CreateMutex(NULL, FALSE, NULL);
  78. BREAK_ON_NULL_(m_hMutex, hr, WBEM_E_OUT_OF_MEMORY);
  79. CComPtr<IWbemClassObject> sipProviderInstance;
  80. IWbemClassObject * pLocalClassDef = NULL;
  81. //
  82. // Get pointers to the class definition objects. If a failure, re-compile
  83. // the MOF file and try once more.
  84. //
  85. for (int i = 0; i <= 1; i++)
  86. {
  87. CComBSTR sbstrObjectName = CLASSNAME_STRING_TRUST;
  88. hr = pNamespace->GetObject(sbstrObjectName,
  89. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  90. pCtx,
  91. &m_sipClassDefTrustStatus,
  92. NULL);
  93. if (FAILED(hr))
  94. {
  95. TRACE(L"GetObject(%s) failed with error 0x%08x\n", sbstrObjectName, hr);
  96. DoMofComp(NULL, NULL, NULL, 0);
  97. continue;
  98. }
  99. sbstrObjectName = CLASSNAME_STRING_LOCAL;
  100. hr = pNamespace->GetObject(sbstrObjectName,
  101. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  102. pCtx,
  103. &pLocalClassDef,
  104. NULL);
  105. if (FAILED(hr))
  106. {
  107. TRACE(L"GetObject(%s) failed with error 0x%08x\n", sbstrObjectName, hr);
  108. DoMofComp(NULL, NULL, NULL, 0);
  109. continue;
  110. }
  111. sbstrObjectName = CLASSNAME_STRING_PROVIDER;
  112. hr = pNamespace->GetObject(sbstrObjectName,
  113. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  114. pCtx,
  115. &m_sipClassDefTrustProvider,
  116. NULL);
  117. if (FAILED(hr))
  118. {
  119. TRACE(L"GetObject(%s) failed with error 0x%08x\n", sbstrObjectName, hr);
  120. DoMofComp(NULL, NULL, NULL, 0);
  121. continue;
  122. }
  123. //
  124. // Get the instance of the provider class to read its properties.
  125. //
  126. sbstrObjectName = PROVIDER_CLASS_INSTANCE;
  127. hr = pNamespace->GetObject(sbstrObjectName,
  128. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  129. pCtx,
  130. &sipProviderInstance,
  131. NULL);
  132. if (FAILED(hr))
  133. {
  134. TRACE(L"GetObject(%s) failed with error 0x%08x\n", sbstrObjectName, hr);
  135. DoMofComp(NULL, NULL, NULL, 0);
  136. }
  137. else
  138. {
  139. i = 2; // success, don't loop again.
  140. }
  141. }
  142. BREAK_ON_FAIL;
  143. //
  144. // Set this provider instance's runtime properties.
  145. //
  146. hr = SetProviderProps(sipProviderInstance);
  147. BREAK_ON_FAIL;
  148. //
  149. // Initialize the domain object.
  150. //
  151. hr = m_DomainInfo.Init(pLocalClassDef);
  152. BREAK_ON_FAIL;
  153. //
  154. // Register to receive change notifications for the provider class
  155. // properties.
  156. //
  157. /* this doesn't work, bug # 432757
  158. CComBSTR bstrLang(L"WQL");
  159. CComBSTR bstrClassQuery(PROVIDER_CLASS_CHANGE_QUERY);
  160. hr = pNamespace->ExecNotificationQueryAsync(bstrLang,
  161. bstrClassQuery,
  162. 0,
  163. NULL,
  164. this);
  165. BREAK_ON_FAIL;
  166. */
  167. //
  168. // Let CIMOM know we are initialized.
  169. // Return value and SetStatus param should be consistent, so ignore
  170. // the return value from SetStatus itself (in retail builds).
  171. //
  172. HRESULT hr2;
  173. hr2 = pInitSink->SetStatus(WBEM_S_INITIALIZED, 0);
  174. ASSERT(!FAILED(hr2));
  175. } while (false);
  176. if (FAILED(hr))
  177. {
  178. TRACE(L"hr = 0x%08x\n", hr);
  179. pInitSink->SetStatus(WBEM_E_FAILED, 0);
  180. }
  181. return hr;
  182. }
  183. //+----------------------------------------------------------------------------
  184. //
  185. // Method: CTrustPrv::IWbemObjectSink::Indicate
  186. //
  187. // Synopsis: Recieves provider object instance change notifications from WMI.
  188. //
  189. //-----------------------------------------------------------------------------
  190. STDMETHODIMP
  191. CTrustPrv::Indicate(LONG lObjectCount,
  192. IWbemClassObject ** rgpObjArray)
  193. {
  194. TRACE(L"\nCTrustPrv::Indicate++++++++++++++++\n");
  195. if (1 > lObjectCount)
  196. {
  197. TRACE(L"\tno objects supplied!\n");
  198. return WBEM_S_NO_ERROR;
  199. }
  200. VARIANT var;
  201. HRESULT hr = (*rgpObjArray)->Get(L"TargetInstance", 0, &var, NULL, NULL);
  202. if (FAILED(hr) || VT_UNKNOWN != var.vt || !var.punkVal)
  203. {
  204. TRACE(L"Error, could not get the target instance, hr = 0x%08x\n", hr);
  205. return hr;
  206. }
  207. hr = SetProviderProps((IWbemClassObject *)var.punkVal);
  208. VariantClear(&var);
  209. return hr;
  210. }
  211. //+----------------------------------------------------------------------------
  212. //
  213. // Method: CTrustPrv::SetProviderProps
  214. //
  215. // Synopsis: Set the provider runtime instance values from the instance of
  216. // the Microsoft_TrustProvider class.
  217. //
  218. //-----------------------------------------------------------------------------
  219. HRESULT
  220. CTrustPrv::SetProviderProps(IWbemClassObject * pClass)
  221. {
  222. WBEM_VALIDATE_INTF_PTR(pClass);
  223. TRACE(L"\nCTrustPrv::SetProviderProps\n");
  224. HRESULT hr = WBEM_S_NO_ERROR;
  225. do
  226. {
  227. VARIANT var;
  228. hr = pClass->Get(CSTR_PROP_TRUST_LIST_LIFETIME, 0, &var, NULL, NULL);
  229. BREAK_ON_FAIL;
  230. SetTrustListLifetime(var.lVal);
  231. VariantClear(&var);
  232. hr = pClass->Get(CSTR_PROP_TRUST_STATUS_LIFETIME, 0, &var, NULL, NULL);
  233. BREAK_ON_FAIL;
  234. SetTrustStatusLifetime(var.lVal);
  235. VariantClear(&var);
  236. hr = pClass->Get(CSTR_PROP_TRUST_CHECK_LEVEL, 0, &var, NULL, NULL);
  237. BREAK_ON_FAIL;
  238. SetTrustCheckLevel(var.lVal);
  239. VariantClear(&var);
  240. hr = pClass->Get(CSTR_PROP_RETURN_ALL_TRUSTS, 0, &var, NULL, NULL);
  241. BREAK_ON_FAIL;
  242. SetReturnAll(var.boolVal);
  243. VariantClear(&var);
  244. } while (false);
  245. return hr;
  246. }
  247. //+----------------------------------------------------------------------------
  248. //
  249. // Function: GetClass
  250. //
  251. // Synopsis: Determines if the first element of the passed in path is one
  252. // of the valid class names.
  253. //
  254. // Returns: TrustMonClass enum value.
  255. //
  256. //-----------------------------------------------------------------------------
  257. TrustMonClass
  258. GetClass(BSTR strClass)
  259. {
  260. if (_wcsnicmp(strClass, CLASSNAME_STRING_PROVIDER, wcslen(CLASSNAME_STRING_PROVIDER)) == 0)
  261. {
  262. TRACE(L"GetClass returning %s\n", CLASSNAME_STRING_PROVIDER);
  263. return CLASS_PROVIDER;
  264. }
  265. else
  266. {
  267. if (_wcsnicmp(strClass, CLASSNAME_STRING_TRUST, wcslen(CLASSNAME_STRING_TRUST)) == 0)
  268. {
  269. TRACE(L"GetClass returning %s\n", CLASSNAME_STRING_TRUST);
  270. return CLASS_TRUST;
  271. }
  272. else
  273. {
  274. if (_wcsnicmp(strClass, CLASSNAME_STRING_LOCAL, wcslen(CLASSNAME_STRING_LOCAL)) == 0)
  275. {
  276. TRACE(L"GetClass returning %s\n", CLASSNAME_STRING_LOCAL);
  277. return CLASS_LOCAL;
  278. }
  279. else
  280. {
  281. TRACE(L"GetClass returning NO_CLASS\n");
  282. return NO_CLASS;
  283. }
  284. }
  285. }
  286. }
  287. //+----------------------------------------------------------------------------
  288. //
  289. // Method: CTrustPrv::IWbemServices::GetObjectAsync
  290. //
  291. // Synopsis: Return the instance named by strObjectPath.
  292. //
  293. // Returns: WMI error codes
  294. //
  295. //-----------------------------------------------------------------------------
  296. STDMETHODIMP
  297. CTrustPrv::GetObjectAsync(
  298. IN const BSTR strObjectPath,
  299. IN long lFlags,
  300. IN IWbemContext * pCtx,
  301. IN IWbemObjectSink * pResponseHandler)
  302. {
  303. HRESULT hr = WBEM_S_NO_ERROR;
  304. CTrustInfo * pTrust;
  305. TRACE(L"\nCTrustsPrv::GetObjectAsync:\n"
  306. L"\tObject param = %s, flags = 0x%08x\n", strObjectPath, lFlags);
  307. do
  308. {
  309. WBEM_VALIDATE_IN_STRING_PTR(strObjectPath);
  310. WBEM_VALIDATE_INTF_PTR(pCtx);
  311. WBEM_VALIDATE_INTF_PTR(pResponseHandler);
  312. //
  313. // Determine which class is being requested.
  314. // A valid class object path has the form: class_name.key_name="key_value"
  315. //
  316. TrustMonClass Class = GetClass(strObjectPath);
  317. if (NO_CLASS == Class)
  318. {
  319. hr = WBEM_E_INVALID_OBJECT_PATH;
  320. BREAK_ON_FAIL;
  321. }
  322. // Isolate the class name from the key name
  323. //
  324. PWSTR pwzInstance;
  325. PWSTR pwzKeyName = wcschr(strObjectPath, L'.');
  326. if (pwzKeyName)
  327. {
  328. // A request without a key name is only valid for a class that
  329. // is defined to have zero or only one dynamic instance (singleton).
  330. //
  331. // Isolate the key name from the class name
  332. //
  333. *pwzKeyName = L'\0'; // overwrite the period with a null
  334. pwzKeyName++; // point to the first char of the key name
  335. }
  336. CClientImpersonation Client;
  337. switch (Class)
  338. {
  339. case CLASS_PROVIDER:
  340. //
  341. // The provider class has no dynamic instances, return a copy of the
  342. // static instance.
  343. //
  344. hr = CreateAndSendProv(pResponseHandler);
  345. BREAK_ON_FAIL;
  346. break;
  347. case CLASS_TRUST:
  348. //
  349. // There can be zero or more trusts. Thus the key name and value must
  350. // be specified.
  351. //
  352. hr = Client.Impersonate();
  353. BREAK_ON_FAIL;
  354. if (!pwzKeyName)
  355. {
  356. hr = WBEM_E_INVALID_OBJECT_PATH;
  357. BREAK_ON_FAIL;
  358. }
  359. pwzInstance = wcschr(pwzKeyName, L'=');
  360. if (!pwzInstance || L'\"' != pwzInstance[1])
  361. {
  362. // No equal sign found or the following char not a quote.
  363. //
  364. hr = WBEM_E_INVALID_OBJECT_PATH;
  365. BREAK_ON_FAIL;
  366. }
  367. *pwzInstance = L'\0'; // isolate the key name.
  368. if (_wcsicmp(pwzKeyName, CSTR_PROP_TRUSTED_DOMAIN) != 0)
  369. {
  370. // Key name not correct.
  371. //
  372. hr = WBEM_E_INVALID_OBJECT_PATH;
  373. BREAK_ON_FAIL;
  374. }
  375. pwzInstance++; // point to the first quote
  376. if (L'\0' == pwzInstance[1] || L'\"' == pwzInstance[1])
  377. {
  378. // No char following the quote or the next char a second quote
  379. //
  380. hr = WBEM_E_INVALID_OBJECT_PATH;
  381. BREAK_ON_FAIL;
  382. }
  383. pwzInstance++; // point to the first char of the instance value;
  384. PWSTR pwzInstEnd;
  385. pwzInstEnd = wcschr(pwzInstance, L'\"');
  386. if (!pwzInstEnd)
  387. {
  388. // No terminating quote.
  389. //
  390. hr = WBEM_E_INVALID_OBJECT_PATH;
  391. BREAK_ON_FAIL;
  392. }
  393. *pwzInstEnd = L'\0'; // replace ending quote with a null
  394. if (m_DomainInfo.IsTrustListStale(m_liTrustEnumMaxAge))
  395. {
  396. hr = m_DomainInfo.EnumerateTrusts();
  397. }
  398. BREAK_ON_FAIL;
  399. pTrust = m_DomainInfo.FindTrust(pwzInstance);
  400. BREAK_ON_NULL_(pTrust, hr, WBEM_E_INVALID_OBJECT_PATH);
  401. //
  402. // Verify the trust.
  403. //
  404. if (pTrust->IsVerificationStale(m_liVerifyMaxAge))
  405. {
  406. pTrust->Verify(GetTrustCheckLevel());
  407. }
  408. Client.Revert();
  409. //
  410. // Create a new instance of the object
  411. //
  412. hr = CreateAndSendTrustInst(*pTrust,
  413. m_sipClassDefTrustStatus,
  414. pResponseHandler);
  415. BREAK_ON_FAIL;
  416. break;
  417. case CLASS_LOCAL:
  418. //
  419. // The local domain info class has only one instance, return that.
  420. //
  421. hr = Client.Impersonate();
  422. BREAK_ON_FAIL;
  423. hr = m_DomainInfo.CreateAndSendInst(pResponseHandler);
  424. Client.Revert();
  425. BREAK_ON_FAIL;
  426. break;
  427. default:
  428. hr = WBEM_E_INVALID_OBJECT_PATH;
  429. BREAK_ON_FAIL;
  430. }
  431. } while(FALSE);
  432. return pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  433. }
  434. //+----------------------------------------------------------------------------
  435. //
  436. // Method: CTrustPrv::IWbemServices::CreateInstanceEnumAsync
  437. //
  438. // Synopsis: Start an asyncronous enumeration of the instances of the class.
  439. //
  440. // Returns: WMI error codes
  441. //
  442. //-----------------------------------------------------------------------------
  443. STDMETHODIMP
  444. CTrustPrv::CreateInstanceEnumAsync(
  445. IN const BSTR strClass,
  446. IN long lFlags,
  447. IN IWbemContext *pCtx,
  448. IN IWbemObjectSink *pResponseHandler)
  449. {
  450. TRACE(L"\nCTrustsPrv::CreateInstanceEnumAsync:\n"
  451. L"\tClass param = %s, flags = 0x%08x\n", strClass, lFlags);
  452. HRESULT hr = WBEM_S_NO_ERROR;
  453. do
  454. {
  455. WBEM_VALIDATE_IN_STRING_PTR(strClass);
  456. WBEM_VALIDATE_INTF_PTR(pCtx);
  457. WBEM_VALIDATE_INTF_PTR(pResponseHandler);
  458. //
  459. // Determine which class is being requested.
  460. // A valid class object path has the form: class_name.key_name="key_value"
  461. //
  462. TrustMonClass Class = GetClass(strClass);
  463. if (NO_CLASS == Class)
  464. {
  465. hr = WBEM_E_INVALID_OBJECT_PATH;
  466. BREAK_ON_FAIL;
  467. }
  468. HANDLE hToken = NULL, hTh = NULL;
  469. DWORD dwErr = NO_ERROR;
  470. CAsyncCallWorker * pWorker = NULL;
  471. CClientImpersonation Client;
  472. switch (Class)
  473. {
  474. case CLASS_PROVIDER:
  475. //
  476. // The provider class has no dynamic instances, return a copy of the
  477. // static instance.
  478. //
  479. hr = CreateAndSendProv(pResponseHandler);
  480. BREAK_ON_FAIL;
  481. hr = pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  482. BREAK_ON_FAIL;
  483. break;
  484. case CLASS_TRUST:
  485. //
  486. // Impersonate the client (the caller) and then obtain the
  487. // impersonation token. Pass that token to the new thread so that
  488. // it can imperonate the client.
  489. //
  490. hr = Client.Impersonate();
  491. BREAK_ON_FAIL;
  492. hTh = GetCurrentThread(); // this pseudo handle doesn't need to be closed.
  493. if (!hTh)
  494. {
  495. dwErr = GetLastError();
  496. TRACE(L"IWbemServices::CreateInstanceEnumAsync: GetCurrentThread failed with error %d\n", dwErr);
  497. BREAK_ON_FAIL(dwErr);
  498. }
  499. else
  500. {
  501. if (!OpenThreadToken(hTh, TOKEN_READ | TOKEN_IMPERSONATE,
  502. TRUE, &hToken))
  503. {
  504. dwErr = GetLastError();
  505. TRACE(L"IWbemServices::CreateInstanceEnumAsync: OpenThreadToken failed with error %d\n", dwErr);
  506. BREAK_ON_FAIL(dwErr);
  507. }
  508. #if defined (DBG)
  509. else
  510. {
  511. TOKEN_USER tu[10] = {0};
  512. DWORD dwLen = sizeof(tu);
  513. if (GetTokenInformation(hToken, TokenUser, tu, dwLen, &dwLen))
  514. {
  515. WCHAR wzName[MAX_PATH+1] = {0}, wzDomain[MAX_PATH+1] = {0};
  516. DWORD dwDom = MAX_PATH;
  517. SID_NAME_USE Use;
  518. dwLen = MAX_PATH;
  519. LookupAccountSid(NULL, tu[0].User.Sid, wzName, &dwLen, wzDomain, &dwDom, &Use);
  520. TRACE(L"IWbemServices::CreateInstanceEnumAsync: TrustMon is impersonating %s\\%s\n",
  521. wzDomain, wzName);
  522. }
  523. else
  524. {
  525. TRACE(L"IWbemServices::CreateInstanceEnumAsync: GetTokenInformation failed with error %d and required buf size %d\n",
  526. GetLastError(), dwLen);
  527. }
  528. }
  529. #endif // DBG
  530. }
  531. Client.Revert();
  532. //
  533. // Spawn the worker thread to enum and return the trust instances.
  534. // Note that the class definition pointer is not add-ref'd here
  535. // because it is add-ref'd separately in the CAsyncCallWorker ctor.
  536. //
  537. pWorker = new CAsyncCallWorker(this,
  538. hToken,
  539. lFlags,
  540. m_sipClassDefTrustStatus,
  541. pResponseHandler);
  542. BREAK_ON_NULL_(pWorker, hr, WBEM_E_OUT_OF_MEMORY);
  543. uintptr_t hThread;
  544. hThread = _beginthread(CAsyncCallWorker::CreateInstEnum, 0, (PVOID)pWorker);
  545. BREAK_ON_NULL_(hThread != -1, hr, WBEM_E_OUT_OF_MEMORY);
  546. break;
  547. case CLASS_LOCAL:
  548. //
  549. // The local domain info class has only one instance, return that.
  550. //
  551. hr = Client.Impersonate();
  552. BREAK_ON_FAIL;
  553. hr = m_DomainInfo.CreateAndSendInst(pResponseHandler);
  554. if (FAILED(hr))
  555. {
  556. BREAK_ON_FAIL;
  557. }
  558. hr = pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  559. Client.Revert();
  560. BREAK_ON_FAIL;
  561. break;
  562. default:
  563. hr = WBEM_E_INVALID_OBJECT_PATH;
  564. BREAK_ON_FAIL;
  565. }
  566. } while(FALSE);
  567. if (FAILED(hr))
  568. {
  569. return pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hr, NULL, NULL);
  570. }
  571. return hr;
  572. }
  573. //+----------------------------------------------------------------------------
  574. //
  575. // Method: CTrustPrv::CreateAndSendProv
  576. //
  577. // Synopsis: Return the provider parameters.
  578. //
  579. //-----------------------------------------------------------------------------
  580. HRESULT
  581. CTrustPrv::CreateAndSendProv(IWbemObjectSink * pResponseHandler)
  582. {
  583. TRACE(L"CTrustsPrv::CreateAndSendProv:\n");
  584. HRESULT hr = WBEM_S_NO_ERROR;
  585. do
  586. {
  587. CComPtr<IWbemClassObject> ipNewInst;
  588. VARIANT var;
  589. VariantInit(&var);
  590. //
  591. // Create a new instance of the WMI class object
  592. //
  593. hr = m_sipClassDefTrustProvider->SpawnInstance(0, &ipNewInst);
  594. BREAK_ON_FAIL;
  595. // Set the TrustListLifetime property value
  596. var.lVal = (long)GetTrustListLifetime();
  597. var.vt = VT_I4;
  598. hr = ipNewInst->Put(CSTR_PROP_TRUST_LIST_LIFETIME, 0, &var, 0);
  599. TRACE(L"\tTrustListLifetime %d\n", var.bstrVal);
  600. BREAK_ON_FAIL;
  601. // Set the TrustStatusLifetime property value
  602. var.lVal = (long)GetTrustStatusLifetime();
  603. hr = ipNewInst->Put(CSTR_PROP_TRUST_STATUS_LIFETIME, 0, &var, 0);
  604. TRACE(L"\tTrustStatusLifetime %d\n", var.bstrVal);
  605. BREAK_ON_FAIL;
  606. // Set the TrustCheckLevel property value
  607. var.lVal = (long)GetTrustCheckLevel();
  608. hr = ipNewInst->Put(CSTR_PROP_TRUST_CHECK_LEVEL, 0, &var, 0);
  609. TRACE(L"\tTrustCheckLevel %d\n", var.bstrVal);
  610. BREAK_ON_FAIL;
  611. // Set the ReturnAll property value
  612. var.boolVal = (GetReturnAll()) ? VARIANT_TRUE : VARIANT_FALSE;
  613. var.vt = VT_BOOL;
  614. hr = ipNewInst->Put(CSTR_PROP_RETURN_ALL_TRUSTS, 0, &var, 0);
  615. TRACE(L"\tReturnAll %d\n", var.bstrVal);
  616. BREAK_ON_FAIL;
  617. //
  618. // Send the object to the caller
  619. //
  620. // [In] param, no need to addref.
  621. IWbemClassObject * pNewInstance = ipNewInst;
  622. hr = pResponseHandler->Indicate(1, &pNewInstance);
  623. BREAK_ON_FAIL;
  624. } while(FALSE);
  625. return hr;
  626. }