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.

1752 lines
40 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // SOBJPATH.CPP
  6. //
  7. // alanbos 15-Aug-96 Created.
  8. //
  9. // Defines the implementation of ISWbemObjectPath
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. //***************************************************************************
  14. //
  15. // CSWbemObjectPath::CSWbemObjectPath
  16. //
  17. // DESCRIPTION:
  18. //
  19. // Constructor.
  20. //
  21. //***************************************************************************
  22. CSWbemObjectPath::CSWbemObjectPath(CSWbemSecurity *pSecurity, BSTR bsLocale) :
  23. m_cRef (0),
  24. m_pSecurity (NULL),
  25. m_pPathCracker (NULL),
  26. m_bsAuthority (NULL),
  27. m_bsLocale (NULL)
  28. {
  29. InterlockedIncrement(&g_cObj);
  30. m_Dispatch.SetObj (this, IID_ISWbemObjectPath,
  31. CLSID_SWbemObjectPath, L"SWbemObjectPath");
  32. m_pPathCracker = new CWbemPathCracker();
  33. if (m_pPathCracker)
  34. m_pPathCracker->AddRef ();
  35. if (pSecurity)
  36. m_bsAuthority = SysAllocString (pSecurity->GetAuthority());
  37. else
  38. m_bsAuthority = NULL;
  39. m_pSecurity = new CWbemObjectPathSecurity (pSecurity);
  40. m_bsLocale = SysAllocString (bsLocale);
  41. }
  42. //***************************************************************************
  43. //
  44. // CSWbemObjectPath::CSWbemObjectPath
  45. //
  46. // DESCRIPTION:
  47. //
  48. // Copy Constructor but yields the parent path
  49. //
  50. //***************************************************************************
  51. CSWbemObjectPath::CSWbemObjectPath(CSWbemObjectPath & objectPath) :
  52. m_cRef (0),
  53. m_pSecurity (NULL),
  54. m_pPathCracker (NULL),
  55. m_bsAuthority (NULL),
  56. m_bsLocale (NULL)
  57. {
  58. InterlockedIncrement(&g_cObj);
  59. m_Dispatch.SetObj (this, IID_ISWbemObjectPath,
  60. CLSID_SWbemObjectPath, L"SWbemObjectPath");
  61. m_pPathCracker = new CWbemPathCracker();
  62. if (m_pPathCracker)
  63. m_pPathCracker->AddRef ();
  64. objectPath.m_pPathCracker->GetParent (*m_pPathCracker);
  65. m_bsAuthority = SysAllocString (objectPath.m_bsAuthority);
  66. m_pSecurity = new CWbemObjectPathSecurity (objectPath.m_pSecurity);
  67. m_bsLocale = SysAllocString (objectPath.m_bsLocale);
  68. }
  69. //***************************************************************************
  70. //
  71. // CSWbemObjectPath::CSWbemObjectPath
  72. //
  73. // DESCRIPTION:
  74. //
  75. // Copy Constructor but yields the parent path
  76. //
  77. //***************************************************************************
  78. CSWbemObjectPath::CSWbemObjectPath(ISWbemObjectPath *pISWbemObjectPath) :
  79. m_cRef (0),
  80. m_pSecurity (NULL),
  81. m_pPathCracker (NULL),
  82. m_bsAuthority (NULL),
  83. m_bsLocale (NULL)
  84. {
  85. InterlockedIncrement(&g_cObj);
  86. m_Dispatch.SetObj (this, IID_ISWbemObjectPath,
  87. CLSID_SWbemObjectPath, L"SWbemObjectPath");
  88. m_pPathCracker = new CWbemPathCracker();
  89. if (m_pPathCracker)
  90. m_pPathCracker->AddRef ();
  91. if (pISWbemObjectPath)
  92. {
  93. CComPtr<ISWbemSecurity> pISWbemSecurity;
  94. if (SUCCEEDED(pISWbemObjectPath->get_Security_ (&pISWbemSecurity)))
  95. m_pSecurity = new CWbemObjectPathSecurity (pISWbemSecurity);
  96. pISWbemObjectPath->get_Authority(&m_bsAuthority);
  97. pISWbemObjectPath->get_Locale(&m_bsLocale);
  98. CComBSTR bsOriginalPath;
  99. if (SUCCEEDED(pISWbemObjectPath->get_Path (&(bsOriginalPath.m_str))))
  100. {
  101. CWbemPathCracker pathCracker (bsOriginalPath);
  102. pathCracker.GetParent (*m_pPathCracker);
  103. }
  104. }
  105. }
  106. //***************************************************************************
  107. //
  108. // CSWbemObjectPath::~CSWbemObjectPath
  109. //
  110. // DESCRIPTION:
  111. //
  112. // Destructor.
  113. //
  114. //***************************************************************************
  115. CSWbemObjectPath::~CSWbemObjectPath(void)
  116. {
  117. RELEASEANDNULL(m_pSecurity)
  118. RELEASEANDNULL(m_pPathCracker)
  119. if (m_bsLocale)
  120. {
  121. SysFreeString (m_bsLocale);
  122. m_bsLocale = NULL;
  123. }
  124. if (m_bsAuthority)
  125. {
  126. SysFreeString (m_bsAuthority);
  127. m_bsAuthority = NULL;
  128. }
  129. InterlockedDecrement(&g_cObj);
  130. }
  131. //***************************************************************************
  132. // HRESULT CSWbemObjectPath::QueryInterface
  133. // long CSWbemObjectPath::AddRef
  134. // long CSWbemObjectPath::Release
  135. //
  136. // DESCRIPTION:
  137. //
  138. // Standard Com IUNKNOWN functions.
  139. //
  140. //***************************************************************************
  141. STDMETHODIMP CSWbemObjectPath::QueryInterface (
  142. IN REFIID riid,
  143. OUT LPVOID *ppv
  144. )
  145. {
  146. *ppv=NULL;
  147. if (IID_IUnknown==riid)
  148. *ppv = reinterpret_cast<IUnknown*>(this);
  149. else if (IID_ISWbemObjectPath==riid)
  150. *ppv = (ISWbemObjectPath *)this;
  151. else if (IID_IDispatch==riid)
  152. *ppv= (IDispatch *)this;
  153. else if (IID_IObjectSafety==riid)
  154. *ppv = (IObjectSafety *)this;
  155. else if (IID_ISupportErrorInfo==riid)
  156. *ppv = (ISupportErrorInfo *)this;
  157. else if (IID_IProvideClassInfo==riid)
  158. *ppv = (IProvideClassInfo *)this;
  159. if (NULL!=*ppv)
  160. {
  161. ((LPUNKNOWN)*ppv)->AddRef();
  162. return NOERROR;
  163. }
  164. return ResultFromScode(E_NOINTERFACE);
  165. }
  166. STDMETHODIMP_(ULONG) CSWbemObjectPath::AddRef(void)
  167. {
  168. InterlockedIncrement(&m_cRef);
  169. return m_cRef;
  170. }
  171. STDMETHODIMP_(ULONG) CSWbemObjectPath::Release(void)
  172. {
  173. LONG cRef = InterlockedDecrement(&m_cRef);
  174. if (0L!=cRef)
  175. {
  176. _ASSERT(cRef > 0);
  177. return cRef;
  178. }
  179. delete this;
  180. return 0;
  181. }
  182. //***************************************************************************
  183. // HRESULT CSWbemObjectPath::InterfaceSupportsErrorInfo
  184. //
  185. // DESCRIPTION:
  186. //
  187. // Standard Com ISupportErrorInfo functions.
  188. //
  189. //***************************************************************************
  190. STDMETHODIMP CSWbemObjectPath::InterfaceSupportsErrorInfo (IN REFIID riid)
  191. {
  192. return (IID_ISWbemObjectPath == riid) ? S_OK : S_FALSE;
  193. }
  194. //***************************************************************************
  195. //
  196. // SCODE CSWbemObjectPath::get_Path
  197. //
  198. // DESCRIPTION:
  199. //
  200. // Get the path as a string
  201. //
  202. // PARAMETERS:
  203. // value pointer to BSTR value returned
  204. //
  205. // RETURN VALUES:
  206. //
  207. // WBEM_S_NO_ERROR success
  208. // WBEM_E_INVALID_PARAMETER bad input parameters
  209. // WBEM_E_FAILED otherwise
  210. //
  211. //***************************************************************************
  212. STDMETHODIMP CSWbemObjectPath::get_Path(
  213. /* [retval][out] */ BSTR __RPC_FAR *value)
  214. {
  215. HRESULT hr = WBEM_E_FAILED ;
  216. ResetLastErrors ();
  217. if (NULL == value)
  218. hr = WBEM_E_INVALID_PARAMETER;
  219. else
  220. {
  221. *value = NULL;
  222. CComBSTR bsPath;
  223. if (m_pPathCracker->GetPathText (bsPath, false, true))
  224. {
  225. *value = bsPath.Detach ();
  226. hr = S_OK;
  227. }
  228. }
  229. if (FAILED(hr))
  230. m_Dispatch.RaiseException (hr);
  231. return hr;
  232. }
  233. //***************************************************************************
  234. //
  235. // SCODE CSWbemObjectPath::put_Path
  236. //
  237. // DESCRIPTION:
  238. //
  239. // Put the path as a string
  240. //
  241. // PARAMETERS:
  242. // none
  243. //
  244. // RETURN VALUES:
  245. //
  246. // WBEM_S_NO_ERROR success
  247. // WBEM_E_INVALID_PARAMETER bad input parameters
  248. // WBEM_E_FAILED otherwise
  249. //
  250. //***************************************************************************
  251. STDMETHODIMP CSWbemObjectPath::put_Path(
  252. /* [in] */ BSTR __RPC_FAR value)
  253. {
  254. HRESULT hr = WBEM_E_FAILED ;
  255. ResetLastErrors ();
  256. if (*m_pPathCracker = value)
  257. hr = WBEM_S_NO_ERROR;
  258. if (FAILED(hr))
  259. m_Dispatch.RaiseException (hr);
  260. return hr;
  261. }
  262. //***************************************************************************
  263. //
  264. // SCODE CSWbemObjectPath::get_RelPath
  265. //
  266. // DESCRIPTION:
  267. //
  268. // Get the relpath as a string
  269. //
  270. // PARAMETERS:
  271. // value pointer to BSTR value returned
  272. //
  273. // RETURN VALUES:
  274. //
  275. // WBEM_S_NO_ERROR success
  276. // WBEM_E_INVALID_PARAMETER bad input parameters
  277. // WBEM_E_FAILED otherwise
  278. //
  279. //***************************************************************************
  280. STDMETHODIMP CSWbemObjectPath::get_RelPath(
  281. /* [retval][out] */ BSTR __RPC_FAR *value)
  282. {
  283. HRESULT hr = WBEM_E_FAILED ;
  284. if (NULL == value)
  285. hr = WBEM_E_INVALID_PARAMETER;
  286. else
  287. {
  288. CComBSTR bsRelPath;
  289. if (m_pPathCracker->GetPathText (bsRelPath, true, false))
  290. {
  291. hr = WBEM_S_NO_ERROR;
  292. *value = bsRelPath.Detach ();
  293. }
  294. }
  295. if (FAILED(hr))
  296. m_Dispatch.RaiseException (hr);
  297. return hr;
  298. }
  299. //***************************************************************************
  300. //
  301. // SCODE CSWbemObjectPath::put_RelPath
  302. //
  303. // DESCRIPTION:
  304. //
  305. // Set the relpath as a string
  306. //
  307. // PARAMETERS:
  308. // value new relpath
  309. //
  310. // RETURN VALUES:
  311. //
  312. // WBEM_S_NO_ERROR success
  313. // WBEM_E_INVALID_PARAMETER bad input parameters
  314. // WBEM_E_FAILED otherwise
  315. //
  316. //***************************************************************************
  317. STDMETHODIMP CSWbemObjectPath::put_RelPath(
  318. /* [in] */ BSTR __RPC_FAR value)
  319. {
  320. HRESULT hr = WBEM_E_FAILED ;
  321. ResetLastErrors ();
  322. // Parse the new path
  323. if (m_pPathCracker->SetRelativePath (value))
  324. hr = WBEM_S_NO_ERROR;
  325. if (FAILED(hr))
  326. m_Dispatch.RaiseException (hr);
  327. return hr;
  328. }
  329. //***************************************************************************
  330. //
  331. // SCODE CSWbemObjectPath::get_DisplayName
  332. //
  333. // DESCRIPTION:
  334. //
  335. // Get the display name as a string
  336. //
  337. // PARAMETERS:
  338. // value pointer to BSTR value returned
  339. //
  340. // RETURN VALUES:
  341. //
  342. // WBEM_S_NO_ERROR success
  343. // WBEM_E_INVALID_PARAMETER bad input parameters
  344. // WBEM_E_FAILED otherwise
  345. //
  346. //***************************************************************************
  347. STDMETHODIMP CSWbemObjectPath::get_DisplayName(
  348. /* [retval][out] */ BSTR __RPC_FAR *value)
  349. {
  350. HRESULT hr = WBEM_E_FAILED ;
  351. if (NULL == value)
  352. hr = WBEM_E_INVALID_PARAMETER;
  353. else if (m_pSecurity && m_pSecurity->m_pPrivilegeSet)
  354. {
  355. CComBSTR bsPath;
  356. if (m_pPathCracker->GetPathText(bsPath, false, true))
  357. {
  358. bool hasLocale = ((NULL != m_bsLocale) && (0 < wcslen (m_bsLocale)));
  359. bool hasAuthority = ((NULL != m_bsAuthority) && (0 < wcslen (m_bsAuthority)));
  360. // Add the scheme name and a terminating NULL
  361. size_t len = 1 + wcslen ( WBEMS_PDN_SCHEME );
  362. // Add the WMI path length to the buffer
  363. len += wcslen (bsPath);
  364. wchar_t *pwcSecurity = CWbemParseDN::GetSecurityString
  365. (m_pSecurity->m_authnSpecified,
  366. m_pSecurity->m_authnLevel,
  367. m_pSecurity->m_impSpecified,
  368. m_pSecurity->m_impLevel,
  369. *(m_pSecurity->m_pPrivilegeSet),
  370. m_bsAuthority);
  371. // Add the security length
  372. if (pwcSecurity)
  373. len += wcslen (pwcSecurity);
  374. wchar_t *pwcLocale = CWbemParseDN::GetLocaleString (m_bsLocale);
  375. // Add the locale length
  376. if (pwcLocale)
  377. len += wcslen (pwcLocale);
  378. // If we have a path, and either a locale or security component, add a "!" path prefix
  379. if ((0 < wcslen (bsPath)) && (pwcSecurity || pwcLocale))
  380. len += wcslen (WBEMS_EXCLAMATION);
  381. /*
  382. * Now build the string
  383. */
  384. wchar_t *pwcDisplayName = new wchar_t [ len ] ;
  385. if (!pwcDisplayName)
  386. hr = WBEM_E_OUT_OF_MEMORY;
  387. else
  388. {
  389. wcscpy ( pwcDisplayName , WBEMS_PDN_SCHEME ) ;
  390. if (pwcSecurity)
  391. wcscat ( pwcDisplayName, pwcSecurity );
  392. if (pwcLocale)
  393. wcscat ( pwcDisplayName, pwcLocale);
  394. if ((0 < wcslen (bsPath)) && (pwcSecurity || pwcLocale))
  395. wcscat ( pwcDisplayName, WBEMS_EXCLAMATION );
  396. if (0 < wcslen (bsPath))
  397. wcscat ( pwcDisplayName, bsPath) ;
  398. *value = SysAllocString ( pwcDisplayName ) ;
  399. hr = WBEM_S_NO_ERROR;
  400. }
  401. if (pwcSecurity)
  402. delete [] pwcSecurity;
  403. if (pwcLocale)
  404. delete [] pwcLocale;
  405. if (pwcDisplayName)
  406. delete [] pwcDisplayName ;
  407. }
  408. }
  409. return hr;
  410. }
  411. //***************************************************************************
  412. //
  413. // SCODE CSWbemObjectPath::put_DisplayName
  414. //
  415. // DESCRIPTION:
  416. //
  417. // Set the display name as a string
  418. //
  419. // PARAMETERS:
  420. // value new BSTR value
  421. //
  422. // RETURN VALUES:
  423. //
  424. // WBEM_S_NO_ERROR success
  425. // WBEM_E_INVALID_PARAMETER bad input parameters
  426. // WBEM_E_FAILED otherwise
  427. //
  428. //***************************************************************************
  429. STDMETHODIMP CSWbemObjectPath::put_DisplayName(
  430. /* [in] */ BSTR __RPC_FAR value)
  431. {
  432. HRESULT hr = WBEM_E_FAILED ;
  433. ResetLastErrors ();
  434. if (value)
  435. {
  436. ULONG chEaten = 0;
  437. bool bIsWmiPath = false;
  438. bool bIsNativePath = false;
  439. if (0 == _wcsnicmp (value , WBEMS_PDN_SCHEME , wcslen (WBEMS_PDN_SCHEME)))
  440. {
  441. chEaten += wcslen (WBEMS_PDN_SCHEME);
  442. bIsWmiPath = true;
  443. }
  444. if (0 < chEaten)
  445. {
  446. bool authnSpecified = false;
  447. bool impSpecified = false;
  448. enum WbemAuthenticationLevelEnum authnLevel;
  449. enum WbemImpersonationLevelEnum impLevel;
  450. CSWbemPrivilegeSet privilegeSet;
  451. CComBSTR bsAuthority, bsLocale;
  452. if (bIsWmiPath)
  453. {
  454. ULONG lTemp = 0;
  455. if (CWbemParseDN::ParseSecurity (&value [chEaten], &lTemp, authnSpecified,
  456. &authnLevel, impSpecified, &impLevel, privilegeSet, bsAuthority.m_str))
  457. chEaten += lTemp;
  458. lTemp = 0;
  459. if (CWbemParseDN::ParseLocale (&value [chEaten], &lTemp, bsLocale.m_str))
  460. chEaten += lTemp;
  461. // Skip over the "!" separator if there is one
  462. if(NULL != value [chEaten])
  463. if (0 == _wcsnicmp (&value [chEaten], WBEMS_EXCLAMATION, wcslen (WBEMS_EXCLAMATION)))
  464. chEaten += wcslen (WBEMS_EXCLAMATION);
  465. }
  466. // Build the new path with what's left
  467. CComBSTR bsPath;
  468. bsPath = value +chEaten;
  469. if (m_pSecurity && m_pSecurity->m_pPrivilegeSet && (*m_pPathCracker = bsPath))
  470. {
  471. m_pSecurity->m_authnSpecified = authnSpecified;
  472. m_pSecurity->m_impSpecified = impSpecified;
  473. m_pSecurity->m_authnLevel = authnLevel;
  474. m_pSecurity->m_impLevel = impLevel;
  475. m_pSecurity->m_pPrivilegeSet->Reset (privilegeSet);
  476. SysFreeString (m_bsAuthority);
  477. m_bsAuthority = SysAllocString (bsAuthority);
  478. SysFreeString (m_bsLocale);
  479. m_bsLocale = SysAllocString (bsLocale);
  480. hr = WBEM_S_NO_ERROR;
  481. }
  482. }
  483. }
  484. if (FAILED(hr))
  485. m_Dispatch.RaiseException (hr);
  486. return hr;
  487. }
  488. //***************************************************************************
  489. //
  490. // SCODE CSWbemObjectPath::get_Server
  491. //
  492. // DESCRIPTION:
  493. //
  494. // Get the server name as a string
  495. //
  496. // PARAMETERS:
  497. // value pointer to BSTR value returned
  498. //
  499. // RETURN VALUES:
  500. //
  501. // WBEM_S_NO_ERROR success
  502. // WBEM_E_INVALID_PARAMETER bad input parameters
  503. // WBEM_E_FAILED otherwise
  504. //
  505. //***************************************************************************
  506. STDMETHODIMP CSWbemObjectPath::get_Server(
  507. /* [retval][out] */ BSTR __RPC_FAR *value)
  508. {
  509. HRESULT hr = WBEM_E_FAILED ;
  510. ResetLastErrors ();
  511. if (NULL == value)
  512. hr = WBEM_E_INVALID_PARAMETER;
  513. else
  514. {
  515. *value = NULL;
  516. CComBSTR bsServer;
  517. if (m_pPathCracker->GetServer (bsServer))
  518. {
  519. *value = bsServer.Detach ();
  520. hr = WBEM_S_NO_ERROR;
  521. }
  522. }
  523. if (FAILED(hr))
  524. m_Dispatch.RaiseException (hr);
  525. return hr;
  526. }
  527. //***************************************************************************
  528. //
  529. // SCODE CSWbemObjectPath::put_Server
  530. //
  531. // DESCRIPTION:
  532. //
  533. // Set the server name as a string
  534. //
  535. // PARAMETERS:
  536. // value new server name
  537. //
  538. // RETURN VALUES:
  539. //
  540. // WBEM_S_NO_ERROR success
  541. // WBEM_E_INVALID_PARAMETER bad input parameters
  542. // WBEM_E_FAILED otherwise
  543. //
  544. //***************************************************************************
  545. STDMETHODIMP CSWbemObjectPath::put_Server(
  546. /* [in] */ BSTR __RPC_FAR value)
  547. {
  548. HRESULT hr = WBEM_E_FAILED ;
  549. ResetLastErrors ();
  550. if (m_pPathCracker->SetServer (value))
  551. hr = WBEM_S_NO_ERROR;
  552. if (FAILED(hr))
  553. m_Dispatch.RaiseException (hr);
  554. return hr;
  555. }
  556. //***************************************************************************
  557. //
  558. // SCODE CSWbemObjectPath::get_Namespace
  559. //
  560. // DESCRIPTION:
  561. //
  562. // Get the server name as a string
  563. //
  564. // PARAMETERS:
  565. // value pointer to BSTR value returned
  566. //
  567. // RETURN VALUES:
  568. //
  569. // WBEM_S_NO_ERROR success
  570. // WBEM_E_INVALID_PARAMETER bad input parameters
  571. // WBEM_E_FAILED otherwise
  572. //
  573. //***************************************************************************
  574. STDMETHODIMP CSWbemObjectPath::get_Namespace(
  575. /* [retval][out] */ BSTR __RPC_FAR *value)
  576. {
  577. HRESULT hr = WBEM_E_FAILED ;
  578. ResetLastErrors ();
  579. if (NULL == value)
  580. hr = WBEM_E_INVALID_PARAMETER;
  581. else
  582. {
  583. CComBSTR bsNamespace;
  584. if (m_pPathCracker->GetNamespacePath(bsNamespace))
  585. {
  586. *value = bsNamespace.Detach ();
  587. hr = WBEM_S_NO_ERROR;
  588. }
  589. }
  590. if (FAILED(hr))
  591. m_Dispatch.RaiseException (hr);
  592. return hr;
  593. }
  594. //***************************************************************************
  595. //
  596. // SCODE CSWbemObjectPath::get_ParentNamespace
  597. //
  598. // DESCRIPTION:
  599. //
  600. // Get the parent namespace as a string
  601. //
  602. // PARAMETERS:
  603. // value pointer to BSTR value returned
  604. //
  605. // RETURN VALUES:
  606. //
  607. // WBEM_S_NO_ERROR success
  608. // WBEM_E_INVALID_PARAMETER bad input parameters
  609. // WBEM_E_FAILED otherwise
  610. //
  611. //***************************************************************************
  612. STDMETHODIMP CSWbemObjectPath::get_ParentNamespace(
  613. /* [retval][out] */ BSTR __RPC_FAR *value)
  614. {
  615. HRESULT hr = WBEM_E_FAILED ;
  616. ResetLastErrors ();
  617. if (NULL == value)
  618. hr = WBEM_E_INVALID_PARAMETER;
  619. else
  620. {
  621. *value = NULL;
  622. // Get the full path and lob the end off
  623. CComBSTR bsNamespacePath;
  624. if (m_pPathCracker->GetNamespacePath (bsNamespacePath, true))
  625. {
  626. *value = bsNamespacePath.Detach ();
  627. hr = WBEM_S_NO_ERROR;
  628. }
  629. }
  630. if (FAILED(hr))
  631. m_Dispatch.RaiseException (hr);
  632. return hr;
  633. }
  634. //***************************************************************************
  635. //
  636. // SCODE CSWbemObjectPath::put_Namespace
  637. //
  638. // DESCRIPTION:
  639. //
  640. // Put the namespace as a string
  641. //
  642. // PARAMETERS:
  643. // value new server name
  644. //
  645. // RETURN VALUES:
  646. //
  647. // WBEM_S_NO_ERROR success
  648. // WBEM_E_INVALID_PARAMETER bad input parameters
  649. // WBEM_E_FAILED otherwise
  650. //
  651. //***************************************************************************
  652. STDMETHODIMP CSWbemObjectPath::put_Namespace(
  653. /* [in] */ BSTR __RPC_FAR value)
  654. {
  655. HRESULT hr = WBEM_E_FAILED ;
  656. ResetLastErrors ();
  657. if (m_pPathCracker->SetNamespacePath (value))
  658. hr = WBEM_S_NO_ERROR;
  659. if (FAILED(hr))
  660. m_Dispatch.RaiseException (hr);
  661. return hr;
  662. }
  663. //***************************************************************************
  664. //
  665. // SCODE CSWbemObjectPath::get_IsClass
  666. //
  667. // DESCRIPTION:
  668. //
  669. // Get whether the path is to a class
  670. //
  671. // PARAMETERS:
  672. // value pointer to BSTR value returned
  673. //
  674. // RETURN VALUES:
  675. //
  676. // WBEM_S_NO_ERROR success
  677. // WBEM_E_INVALID_PARAMETER bad input parameters
  678. // WBEM_E_FAILED otherwise
  679. //
  680. //***************************************************************************
  681. STDMETHODIMP CSWbemObjectPath::get_IsClass(
  682. /* [retval][out] */ VARIANT_BOOL __RPC_FAR *value)
  683. {
  684. HRESULT hr = WBEM_E_FAILED ;
  685. ResetLastErrors ();
  686. if (NULL == value)
  687. hr = WBEM_E_INVALID_PARAMETER;
  688. else
  689. {
  690. *value = m_pPathCracker->IsClass () ? VARIANT_TRUE : VARIANT_FALSE;
  691. hr = WBEM_S_NO_ERROR;
  692. }
  693. if (FAILED(hr))
  694. m_Dispatch.RaiseException (hr);
  695. return hr;
  696. }
  697. //***************************************************************************
  698. //
  699. // SCODE CSWbemObjectPath::SetAsClass
  700. //
  701. // DESCRIPTION:
  702. //
  703. // Set the path as a class path
  704. //
  705. // PARAMETERS:
  706. // none
  707. //
  708. // RETURN VALUES:
  709. //
  710. // WBEM_S_NO_ERROR success
  711. // WBEM_E_INVALID_PARAMETER bad input parameters
  712. // WBEM_E_FAILED otherwise
  713. //
  714. //***************************************************************************
  715. STDMETHODIMP CSWbemObjectPath::SetAsClass()
  716. {
  717. HRESULT hr = WBEM_E_FAILED ;
  718. ResetLastErrors ();
  719. if (m_pPathCracker->SetAsClass ())
  720. hr = WBEM_S_NO_ERROR;
  721. if (FAILED(hr))
  722. m_Dispatch.RaiseException (hr);
  723. return hr;
  724. }
  725. //***************************************************************************
  726. //
  727. // SCODE CSWbemObjectPath::get_IsSingleton
  728. //
  729. // DESCRIPTION:
  730. //
  731. // Get whether the path is to a singleton
  732. //
  733. // PARAMETERS:
  734. // value pointer to BSTR value returned
  735. //
  736. // RETURN VALUES:
  737. //
  738. // WBEM_S_NO_ERROR success
  739. // WBEM_E_INVALID_PARAMETER bad input parameters
  740. // WBEM_E_FAILED otherwise
  741. //
  742. //***************************************************************************
  743. STDMETHODIMP CSWbemObjectPath::get_IsSingleton(
  744. /* [retval][out] */ VARIANT_BOOL __RPC_FAR *value)
  745. {
  746. HRESULT hr = WBEM_E_FAILED ;
  747. ResetLastErrors ();
  748. if (NULL == value)
  749. hr = WBEM_E_INVALID_PARAMETER;
  750. else
  751. {
  752. *value = m_pPathCracker->IsSingleton () ? VARIANT_TRUE : VARIANT_FALSE;
  753. hr = WBEM_S_NO_ERROR;
  754. }
  755. if (FAILED(hr))
  756. m_Dispatch.RaiseException (hr);
  757. return hr;
  758. }
  759. //***************************************************************************
  760. //
  761. // SCODE CSWbemObjectPath::SetAsSingleton
  762. //
  763. // DESCRIPTION:
  764. //
  765. // Set the path as a singleton instance path
  766. //
  767. // PARAMETERS:
  768. // none
  769. //
  770. // RETURN VALUES:
  771. //
  772. // WBEM_S_NO_ERROR success
  773. // WBEM_E_INVALID_PARAMETER bad input parameters
  774. // WBEM_E_FAILED otherwise
  775. //
  776. //***************************************************************************
  777. STDMETHODIMP CSWbemObjectPath::SetAsSingleton()
  778. {
  779. HRESULT hr = WBEM_E_FAILED ;
  780. ResetLastErrors ();
  781. if (m_pPathCracker->SetAsSingleton ())
  782. hr = WBEM_S_NO_ERROR;
  783. if (FAILED(hr))
  784. m_Dispatch.RaiseException (hr);
  785. return hr;
  786. }
  787. //***************************************************************************
  788. //
  789. // SCODE CSWbemObjectPath::get_Class
  790. //
  791. // DESCRIPTION:
  792. //
  793. // Get the class name from the path
  794. //
  795. // PARAMETERS:
  796. // value pointer to BSTR value returned
  797. //
  798. // RETURN VALUES:
  799. //
  800. // WBEM_S_NO_ERROR success
  801. // WBEM_E_INVALID_PARAMETER bad input parameters
  802. // WBEM_E_FAILED otherwise
  803. //
  804. //***************************************************************************
  805. STDMETHODIMP CSWbemObjectPath::get_Class(
  806. /* [retval][out] */ BSTR __RPC_FAR *value)
  807. {
  808. HRESULT hr = WBEM_E_FAILED ;
  809. ResetLastErrors ();
  810. if (NULL == value)
  811. hr = WBEM_E_INVALID_PARAMETER;
  812. else
  813. {
  814. *value = NULL;
  815. CComBSTR bsPath;
  816. if (m_pPathCracker->GetClass (bsPath))
  817. {
  818. *value = bsPath.Detach ();
  819. hr = WBEM_S_NO_ERROR;
  820. }
  821. }
  822. if (FAILED(hr))
  823. m_Dispatch.RaiseException (hr);
  824. return hr;
  825. }
  826. //***************************************************************************
  827. //
  828. // SCODE CSWbemObjectPath::put_Class
  829. //
  830. // DESCRIPTION:
  831. //
  832. // Set the class name in the path
  833. //
  834. // PARAMETERS:
  835. // value new class name
  836. //
  837. // RETURN VALUES:
  838. //
  839. // WBEM_S_NO_ERROR success
  840. // WBEM_E_INVALID_PARAMETER bad input parameters
  841. // WBEM_E_FAILED otherwise
  842. //
  843. //***************************************************************************
  844. STDMETHODIMP CSWbemObjectPath::put_Class(
  845. /* [in] */ BSTR __RPC_FAR value)
  846. {
  847. HRESULT hr = WBEM_E_FAILED ;
  848. ResetLastErrors ();
  849. if (m_pPathCracker->SetClass (value))
  850. hr = WBEM_S_NO_ERROR;
  851. if (FAILED(hr))
  852. m_Dispatch.RaiseException (hr);
  853. return hr;
  854. }
  855. //***************************************************************************
  856. //
  857. // SCODE CSWbemObjectPath::get_Keys
  858. //
  859. // DESCRIPTION:
  860. //
  861. // Get the keys collection from the path
  862. //
  863. // PARAMETERS:
  864. // objKeys pointer to ISWbemNamedValueSet returned
  865. //
  866. // RETURN VALUES:
  867. //
  868. // WBEM_S_NO_ERROR success
  869. // WBEM_E_INVALID_PARAMETER bad input parameters
  870. // WBEM_E_FAILED otherwise
  871. //
  872. //***************************************************************************
  873. STDMETHODIMP CSWbemObjectPath::get_Keys(
  874. /* [out][retval] */ ISWbemNamedValueSet **objKeys)
  875. {
  876. HRESULT hr = WBEM_E_FAILED;
  877. ResetLastErrors ();
  878. if (NULL == objKeys)
  879. hr = WBEM_E_INVALID_PARAMETER;
  880. else if (m_pPathCracker->GetKeys (objKeys))
  881. hr = WBEM_S_NO_ERROR;
  882. if (FAILED(hr))
  883. m_Dispatch.RaiseException (hr);
  884. return hr;
  885. }
  886. //***************************************************************************
  887. //
  888. // SCODE CSWbemObjectPath::get_Security
  889. //
  890. // DESCRIPTION:
  891. //
  892. // Get the security info from the path
  893. //
  894. // PARAMETERS:
  895. // objKeys pointer to ISWbemSecurity returned
  896. //
  897. // RETURN VALUES:
  898. //
  899. // WBEM_S_NO_ERROR success
  900. // WBEM_E_INVALID_PARAMETER bad input parameters
  901. // WBEM_E_FAILED otherwise
  902. //
  903. //***************************************************************************
  904. STDMETHODIMP CSWbemObjectPath::get_Security_(
  905. /* [out][retval] */ ISWbemSecurity **objSecurity)
  906. {
  907. HRESULT hr = WBEM_E_FAILED;
  908. ResetLastErrors ();
  909. if (NULL == objSecurity)
  910. hr = WBEM_E_INVALID_PARAMETER;
  911. else if (m_pSecurity)
  912. {
  913. *objSecurity = m_pSecurity;
  914. m_pSecurity->AddRef();
  915. hr = WBEM_S_NO_ERROR;
  916. }
  917. if (FAILED(hr))
  918. m_Dispatch.RaiseException (hr);
  919. return hr;
  920. }
  921. //***************************************************************************
  922. //
  923. // SCODE CSWbemObjectPath::get_Locale
  924. //
  925. // DESCRIPTION:
  926. //
  927. // Get the locale info from the path
  928. //
  929. // PARAMETERS:
  930. // value pointer to locale returned
  931. //
  932. // RETURN VALUES:
  933. //
  934. // WBEM_S_NO_ERROR success
  935. // WBEM_E_INVALID_PARAMETER bad input parameters
  936. // WBEM_E_FAILED otherwise
  937. //
  938. //***************************************************************************
  939. STDMETHODIMP CSWbemObjectPath::get_Locale(
  940. /* [retval][out] */ BSTR __RPC_FAR *value)
  941. {
  942. HRESULT hr = WBEM_E_FAILED ;
  943. ResetLastErrors ();
  944. if (NULL == value)
  945. hr = WBEM_E_INVALID_PARAMETER;
  946. else
  947. {
  948. *value = SysAllocString ( m_bsLocale ) ;
  949. hr = S_OK ;
  950. }
  951. if (FAILED(hr))
  952. m_Dispatch.RaiseException (hr);
  953. return hr;
  954. }
  955. //***************************************************************************
  956. //
  957. // SCODE CSWbemObjectPath::put_Locale
  958. //
  959. // DESCRIPTION:
  960. //
  961. // Set the locale info into the path
  962. //
  963. // PARAMETERS:
  964. // value new locale value
  965. //
  966. // RETURN VALUES:
  967. //
  968. // WBEM_S_NO_ERROR success
  969. // WBEM_E_INVALID_PARAMETER bad input parameters
  970. // WBEM_E_FAILED otherwise
  971. //
  972. //***************************************************************************
  973. STDMETHODIMP CSWbemObjectPath::put_Locale(
  974. /* [in] */ BSTR __RPC_FAR value)
  975. {
  976. ResetLastErrors ();
  977. SysFreeString (m_bsLocale);
  978. m_bsLocale = SysAllocString (value);
  979. return S_OK ;
  980. }
  981. //***************************************************************************
  982. //
  983. // SCODE CSWbemObjectPath::get_Authority
  984. //
  985. // DESCRIPTION:
  986. //
  987. // Get the authority info from the path
  988. //
  989. // PARAMETERS:
  990. // value pointer to authority returned
  991. //
  992. // RETURN VALUES:
  993. //
  994. // WBEM_S_NO_ERROR success
  995. // WBEM_E_INVALID_PARAMETER bad input parameters
  996. // WBEM_E_FAILED otherwise
  997. //
  998. //***************************************************************************
  999. STDMETHODIMP CSWbemObjectPath::get_Authority(
  1000. /* [retval][out] */ BSTR __RPC_FAR *value)
  1001. {
  1002. HRESULT hr = WBEM_E_FAILED ;
  1003. ResetLastErrors ();
  1004. if (NULL == value)
  1005. hr = WBEM_E_INVALID_PARAMETER;
  1006. else
  1007. {
  1008. *value = SysAllocString ( m_bsAuthority ) ;
  1009. hr = S_OK ;
  1010. }
  1011. if (FAILED(hr))
  1012. m_Dispatch.RaiseException (hr);
  1013. return hr;
  1014. }
  1015. //***************************************************************************
  1016. //
  1017. // SCODE CSWbemObjectPath::put_Authority
  1018. //
  1019. // DESCRIPTION:
  1020. //
  1021. // Set the authority info into the path
  1022. //
  1023. // PARAMETERS:
  1024. // value new authority value
  1025. //
  1026. // RETURN VALUES:
  1027. //
  1028. // WBEM_S_NO_ERROR success
  1029. //
  1030. //***************************************************************************
  1031. STDMETHODIMP CSWbemObjectPath::put_Authority(
  1032. /* [in] */ BSTR __RPC_FAR value)
  1033. {
  1034. ResetLastErrors ();
  1035. SysFreeString (m_bsAuthority);
  1036. m_bsAuthority = SysAllocString (value);
  1037. return WBEM_S_NO_ERROR;
  1038. }
  1039. // CWbemObjectPathSecurity methods
  1040. //***************************************************************************
  1041. //
  1042. // CWbemObjectPathSecurity::CWbemObjectPathSecurity
  1043. //
  1044. // CONSTRUCTOR
  1045. //
  1046. //***************************************************************************
  1047. CSWbemObjectPath::CWbemObjectPathSecurity::CWbemObjectPathSecurity (
  1048. CSWbemSecurity *pSecurity) :
  1049. m_pPrivilegeSet (NULL),
  1050. m_authnSpecified (false),
  1051. m_impSpecified (false),
  1052. m_cRef (1)
  1053. {
  1054. m_Dispatch.SetObj (this, IID_ISWbemSecurity,
  1055. CLSID_SWbemSecurity, L"SWbemSecurity");
  1056. if (pSecurity)
  1057. {
  1058. CSWbemPrivilegeSet *pPrivilegeSet = pSecurity->GetPrivilegeSet ();
  1059. if (pPrivilegeSet)
  1060. {
  1061. m_pPrivilegeSet = new CSWbemPrivilegeSet (*pPrivilegeSet);
  1062. pPrivilegeSet->Release ();
  1063. }
  1064. else
  1065. m_pPrivilegeSet = new CSWbemPrivilegeSet ();
  1066. pSecurity->get_AuthenticationLevel (&m_authnLevel);
  1067. pSecurity->get_ImpersonationLevel (&m_impLevel);
  1068. m_authnSpecified = true;
  1069. m_impSpecified = true;
  1070. }
  1071. else
  1072. {
  1073. m_pPrivilegeSet = new CSWbemPrivilegeSet ();
  1074. m_authnSpecified = false;
  1075. m_impSpecified = false;
  1076. }
  1077. }
  1078. //***************************************************************************
  1079. //
  1080. // CWbemObjectPathSecurity::CWbemObjectPathSecurity
  1081. //
  1082. // CONSTRUCTOR
  1083. //
  1084. //***************************************************************************
  1085. CSWbemObjectPath::CWbemObjectPathSecurity::CWbemObjectPathSecurity (
  1086. ISWbemSecurity *pISWbemSecurity) :
  1087. m_pPrivilegeSet (NULL),
  1088. m_authnSpecified (false),
  1089. m_impSpecified (false),
  1090. m_cRef (1)
  1091. {
  1092. m_Dispatch.SetObj (this, IID_ISWbemSecurity,
  1093. CLSID_SWbemSecurity, L"SWbemSecurity");
  1094. if (pISWbemSecurity)
  1095. {
  1096. CComPtr<ISWbemPrivilegeSet> pISWbemPrivilegeSet;
  1097. pISWbemSecurity->get_Privileges (&pISWbemPrivilegeSet);
  1098. m_pPrivilegeSet = new CSWbemPrivilegeSet (pISWbemPrivilegeSet);
  1099. pISWbemSecurity->get_AuthenticationLevel (&m_authnLevel);
  1100. pISWbemSecurity->get_ImpersonationLevel (&m_impLevel);
  1101. m_authnSpecified = true;
  1102. m_impSpecified = true;
  1103. }
  1104. else
  1105. {
  1106. m_pPrivilegeSet = new CSWbemPrivilegeSet ();
  1107. m_authnSpecified = false;
  1108. m_impSpecified = false;
  1109. }
  1110. }
  1111. //***************************************************************************
  1112. //
  1113. // CWbemObjectPathSecurity::~CWbemObjectPathSecurity
  1114. //
  1115. // DESTRUCTOR
  1116. //
  1117. //***************************************************************************
  1118. CSWbemObjectPath::CWbemObjectPathSecurity::~CWbemObjectPathSecurity ()
  1119. {
  1120. RELEASEANDNULL(m_pPrivilegeSet)
  1121. }
  1122. //***************************************************************************
  1123. // HRESULT CWbemObjectPathSecurity::QueryInterface
  1124. // long CWbemObjectPathSecurity::AddRef
  1125. // long CWbemObjectPathSecurity::Release
  1126. //
  1127. // DESCRIPTION:
  1128. //
  1129. // Standard Com IUNKNOWN functions.
  1130. //
  1131. //***************************************************************************
  1132. STDMETHODIMP CSWbemObjectPath::CWbemObjectPathSecurity::QueryInterface (
  1133. IN REFIID riid,
  1134. OUT LPVOID *ppv
  1135. )
  1136. {
  1137. *ppv=NULL;
  1138. if (IID_IUnknown==riid)
  1139. *ppv = reinterpret_cast<IUnknown*>(this);
  1140. else if (IID_ISWbemSecurity==riid)
  1141. *ppv = (ISWbemSecurity *)this;
  1142. else if (IID_IDispatch==riid)
  1143. *ppv= (IDispatch *)this;
  1144. else if (IID_IObjectSafety==riid)
  1145. *ppv = (IObjectSafety *)this;
  1146. else if (IID_ISupportErrorInfo==riid)
  1147. *ppv = (ISupportErrorInfo *)this;
  1148. else if (IID_IProvideClassInfo==riid)
  1149. *ppv = (IProvideClassInfo *)this;
  1150. if (NULL!=*ppv)
  1151. {
  1152. ((LPUNKNOWN)*ppv)->AddRef();
  1153. return NOERROR;
  1154. }
  1155. return ResultFromScode(E_NOINTERFACE);
  1156. }
  1157. STDMETHODIMP_(ULONG) CSWbemObjectPath::CWbemObjectPathSecurity::AddRef(void)
  1158. {
  1159. return InterlockedIncrement(&m_cRef);
  1160. }
  1161. STDMETHODIMP_(ULONG) CSWbemObjectPath::CWbemObjectPathSecurity::Release(void)
  1162. {
  1163. long l = InterlockedDecrement(&m_cRef);
  1164. if (0L!=l)
  1165. {
  1166. _ASSERT(l > 0);
  1167. return l;
  1168. }
  1169. delete this;
  1170. return 0;
  1171. }
  1172. //***************************************************************************
  1173. // HRESULT CSWbemObjectPath::CWbemObjectPathSecurity::InterfaceSupportsErrorInfo
  1174. //
  1175. // DESCRIPTION:
  1176. //
  1177. // Standard Com ISupportErrorInfo functions.
  1178. //
  1179. //***************************************************************************
  1180. STDMETHODIMP CSWbemObjectPath::CWbemObjectPathSecurity::InterfaceSupportsErrorInfo (IN REFIID riid)
  1181. {
  1182. return (IID_ISWbemSecurity == riid) ? S_OK : S_FALSE;
  1183. }
  1184. //***************************************************************************
  1185. //
  1186. // SCODE CWbemObjectPathSecurity::get_AuthenticationLevel
  1187. //
  1188. // DESCRIPTION:
  1189. //
  1190. // Retrieve the authentication level
  1191. //
  1192. // PARAMETERS:
  1193. //
  1194. // pAuthenticationLevel holds the value on return
  1195. //
  1196. // RETURN VALUES:
  1197. //
  1198. // WBEM_S_NO_ERROR success
  1199. // WBEM_E_INVALID_PARAMETER bad input parameters
  1200. // WBEM_E_FAILED otherwise
  1201. //
  1202. //***************************************************************************
  1203. HRESULT CSWbemObjectPath::CWbemObjectPathSecurity::get_AuthenticationLevel (
  1204. WbemAuthenticationLevelEnum *pAuthenticationLevel
  1205. )
  1206. {
  1207. HRESULT hr = WBEM_E_FAILED;
  1208. ResetLastErrors ();
  1209. if (NULL == pAuthenticationLevel)
  1210. hr = WBEM_E_INVALID_PARAMETER;
  1211. else if (m_authnSpecified)
  1212. {
  1213. *pAuthenticationLevel = m_authnLevel;
  1214. hr = WBEM_S_NO_ERROR;
  1215. }
  1216. if (FAILED(hr))
  1217. m_Dispatch.RaiseException (hr);
  1218. return hr;
  1219. }
  1220. //***************************************************************************
  1221. //
  1222. // SCODE CWbemObjectPathSecurity::get_ImpersonationLevel
  1223. //
  1224. // DESCRIPTION:
  1225. //
  1226. // Retrieve the impersonation level
  1227. //
  1228. // PARAMETERS:
  1229. //
  1230. // pImpersonationLevel holds the value on return
  1231. //
  1232. // RETURN VALUES:
  1233. //
  1234. // WBEM_S_NO_ERROR success
  1235. // WBEM_E_INVALID_PARAMETER bad input parameters
  1236. // WBEM_E_FAILED otherwise
  1237. //
  1238. //***************************************************************************
  1239. HRESULT CSWbemObjectPath::CWbemObjectPathSecurity::get_ImpersonationLevel (
  1240. WbemImpersonationLevelEnum *pImpersonationLevel
  1241. )
  1242. {
  1243. HRESULT hr = WBEM_E_FAILED;
  1244. ResetLastErrors ();
  1245. if (NULL == pImpersonationLevel)
  1246. hr = WBEM_E_INVALID_PARAMETER;
  1247. else if (m_impSpecified)
  1248. {
  1249. *pImpersonationLevel = m_impLevel;
  1250. hr = WBEM_S_NO_ERROR;
  1251. }
  1252. if (FAILED(hr))
  1253. m_Dispatch.RaiseException (hr);
  1254. return hr;
  1255. }
  1256. //***************************************************************************
  1257. //
  1258. // SCODE CWbemObjectPathSecurity::get_Privileges
  1259. //
  1260. // DESCRIPTION:
  1261. //
  1262. // Return the Privilege override set
  1263. //
  1264. // WBEM_S_NO_ERROR success
  1265. // WBEM_E_INVALID_PARAMETER bad input parameters
  1266. // WBEM_E_FAILED otherwise
  1267. //
  1268. //***************************************************************************
  1269. HRESULT CSWbemObjectPath::CWbemObjectPathSecurity::get_Privileges (
  1270. ISWbemPrivilegeSet **ppPrivileges
  1271. )
  1272. {
  1273. HRESULT hr = WBEM_E_FAILED;
  1274. ResetLastErrors ();
  1275. if (NULL == ppPrivileges)
  1276. hr = WBEM_E_INVALID_PARAMETER;
  1277. else // Bug ID 566345
  1278. {
  1279. *ppPrivileges = NULL;
  1280. if (m_pPrivilegeSet)
  1281. {
  1282. if (SUCCEEDED (m_pPrivilegeSet->QueryInterface (IID_ISWbemPrivilegeSet,
  1283. (PPVOID) ppPrivileges)))
  1284. hr = WBEM_S_NO_ERROR;
  1285. }
  1286. }
  1287. if (FAILED(hr))
  1288. m_Dispatch.RaiseException (hr);
  1289. return hr;
  1290. }
  1291. //***************************************************************************
  1292. //
  1293. // SCODE CWbemObjectPathSecurity::put_AuthenticationLevel
  1294. //
  1295. // DESCRIPTION:
  1296. //
  1297. // Set the authentication level
  1298. //
  1299. // PARAMETERS:
  1300. //
  1301. // authenticationLevel the new value
  1302. //
  1303. // RETURN VALUES:
  1304. //
  1305. // WBEM_S_NO_ERROR success
  1306. // WBEM_E_INVALID_PARAMETER bad input parameters
  1307. // WBEM_E_FAILED otherwise
  1308. //
  1309. //***************************************************************************
  1310. HRESULT CSWbemObjectPath::CWbemObjectPathSecurity::put_AuthenticationLevel (
  1311. WbemAuthenticationLevelEnum authenticationLevel
  1312. )
  1313. {
  1314. HRESULT hr = WBEM_E_FAILED;
  1315. ResetLastErrors ();
  1316. if ((WBEMS_MIN_AUTHN_LEVEL > authenticationLevel) ||
  1317. (WBEMS_MAX_AUTHN_LEVEL < authenticationLevel))
  1318. hr = WBEM_E_INVALID_PARAMETER;
  1319. else
  1320. {
  1321. m_authnLevel = authenticationLevel;
  1322. m_authnSpecified = true;
  1323. hr = WBEM_S_NO_ERROR;
  1324. }
  1325. if (FAILED(hr))
  1326. m_Dispatch.RaiseException (hr);
  1327. return hr;
  1328. }
  1329. //***************************************************************************
  1330. //
  1331. // SCODE CWbemObjectPathSecurity::put_ImpersonationLevel
  1332. //
  1333. // DESCRIPTION:
  1334. //
  1335. // Set the impersonation level
  1336. //
  1337. // PARAMETERS:
  1338. //
  1339. // impersonationLevel the new value
  1340. //
  1341. // RETURN VALUES:
  1342. //
  1343. // WBEM_S_NO_ERROR success
  1344. // WBEM_E_INVALID_PARAMETER bad input parameters
  1345. // WBEM_E_FAILED otherwise
  1346. //
  1347. //***************************************************************************
  1348. HRESULT CSWbemObjectPath::CWbemObjectPathSecurity::put_ImpersonationLevel (
  1349. WbemImpersonationLevelEnum impersonationLevel
  1350. )
  1351. {
  1352. HRESULT hr = WBEM_E_FAILED;
  1353. ResetLastErrors ();
  1354. if ((WBEMS_MIN_IMP_LEVEL > impersonationLevel) || (WBEMS_MAX_IMP_LEVEL < impersonationLevel))
  1355. hr = WBEM_E_INVALID_PARAMETER;
  1356. else
  1357. {
  1358. m_impLevel = impersonationLevel;
  1359. m_impSpecified = true;
  1360. hr = WBEM_S_NO_ERROR;
  1361. }
  1362. if (FAILED(hr))
  1363. m_Dispatch.RaiseException (hr);
  1364. return hr;
  1365. }
  1366. //***************************************************************************
  1367. //
  1368. // CSWbemObjectPath::GetObjectPath
  1369. //
  1370. // DESCRIPTION:
  1371. //
  1372. // Attempts to extract the __RELPATH system property value from a WBEM object
  1373. // and return it as a BSTR. Note that if this object is not yet persisted
  1374. // the __RELPATH property will be null or invalid.
  1375. //
  1376. // PARAMETERS:
  1377. // pIWbemClassObject the object in question
  1378. // bsPath placeholder for the path
  1379. //
  1380. // RETURN VALUES:
  1381. // true if retrieved, false o/w
  1382. //
  1383. //***************************************************************************
  1384. bool CSWbemObjectPath::GetObjectPath (
  1385. IWbemClassObject *pIWbemClassObject,
  1386. CComBSTR & bsPath
  1387. )
  1388. {
  1389. bool result = false;
  1390. if (pIWbemClassObject)
  1391. {
  1392. CComVariant var;
  1393. if (SUCCEEDED(pIWbemClassObject->Get (WBEMS_SP_RELPATH, 0, &var, NULL, NULL))
  1394. && (VT_BSTR == var.vt)
  1395. && (var.bstrVal)
  1396. && (0 < wcslen (var.bstrVal)))
  1397. {
  1398. bsPath = var.bstrVal;
  1399. result = true;
  1400. }
  1401. }
  1402. return result;
  1403. }
  1404. //***************************************************************************
  1405. //
  1406. // CSWbemObjectPath::GetParentPath
  1407. //
  1408. // DESCRIPTION:
  1409. //
  1410. // Attempts to extract the path of the parent container for the given object.
  1411. //
  1412. // PARAMETERS:
  1413. // pIWbemClassObject the object in question
  1414. // bsParentPath placeholder for the path
  1415. //
  1416. // RETURN VALUES:
  1417. // true if retrieved, false o/w
  1418. //
  1419. //***************************************************************************
  1420. bool CSWbemObjectPath::GetParentPath (
  1421. IWbemClassObject *pIWbemClassObject,
  1422. CComBSTR & bsParentPath
  1423. )
  1424. {
  1425. bool result = false;
  1426. if (pIWbemClassObject)
  1427. {
  1428. CComVariant var;
  1429. if (SUCCEEDED(pIWbemClassObject->Get (WBEMS_SP_PATH, 0, &var, NULL, NULL))
  1430. && (VT_BSTR == var.vt)
  1431. && (var.bstrVal)
  1432. && (0 < wcslen (var.bstrVal)))
  1433. {
  1434. CWbemPathCracker pathCracker (var.bstrVal);
  1435. if (CWbemPathCracker::wbemPathTypeError != pathCracker.GetType ())
  1436. {
  1437. CWbemPathCracker parentPath;
  1438. if (pathCracker.GetParent (parentPath))
  1439. result = parentPath.GetPathText(bsParentPath, false, true, false);
  1440. }
  1441. }
  1442. }
  1443. return result;
  1444. }
  1445. //***************************************************************************
  1446. //
  1447. // CSWbemObjectPath::CompareObjectPaths
  1448. //
  1449. // DESCRIPTION:
  1450. //
  1451. // Given an IWbemClassObject, determine whether it can "fit" the supplied
  1452. // path
  1453. //
  1454. // PARAMETERS:
  1455. // pIWbemClassObject the object in question
  1456. // objectPath cracked path
  1457. //
  1458. // RETURN VALUES:
  1459. // true if retrieved, false o/w
  1460. //
  1461. //***************************************************************************
  1462. bool CSWbemObjectPath::CompareObjectPaths (
  1463. IWbemClassObject *pIWbemClassObject,
  1464. CWbemPathCracker & objectPath
  1465. )
  1466. {
  1467. bool result = false;
  1468. CComVariant var;
  1469. CComBSTR bsPath;
  1470. // Depending on what type of path we're trying to match against
  1471. // we get our path info appropriately
  1472. switch (objectPath.GetType ())
  1473. {
  1474. case CWbemPathCracker::WbemPathType::wbemPathTypeWmi:
  1475. {
  1476. if (SUCCEEDED(pIWbemClassObject->Get (WBEMS_SP_RELPATH, 0, &var, NULL, NULL))
  1477. && (VT_BSTR == var.vt)
  1478. && (var.bstrVal)
  1479. && (0 < wcslen (var.bstrVal)))
  1480. {
  1481. bsPath = var.bstrVal;
  1482. result = (objectPath == bsPath);
  1483. }
  1484. }
  1485. break;
  1486. }
  1487. return result;
  1488. }