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.

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