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.

3322 lines
111 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name: VssClasses.cpp
  6. //
  7. // Description:
  8. // Implementation of VSS WMI Provider classes
  9. //
  10. // Author: Jim Benton (jbenton) 15-Oct-2001
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13. #include "Pch.h"
  14. #include <wbemtime.h>
  15. #include "VssClasses.h"
  16. #ifndef ARRAY_LEN
  17. #define ARRAY_LEN(A) (sizeof(A)/sizeof((A)[0]))
  18. #endif
  19. typedef CVssDLList<GUID> CGUIDList;
  20. typedef CVssDLList<_bstr_t> CBSTRList;
  21. void
  22. GetProviderIDList(
  23. IN IVssCoordinator* pCoord,
  24. OUT CGUIDList* pList
  25. ) throw(HRESULT)
  26. {
  27. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"GetProviderIDList");
  28. CComPtr<IVssEnumObject> spEnumProvider;
  29. _ASSERTE(pList != NULL);
  30. _ASSERTE(pCoord != NULL);
  31. // Clear list of any previous values
  32. pList->ClearAll();
  33. ft.hr = pCoord->Query(
  34. GUID_NULL,
  35. VSS_OBJECT_NONE,
  36. VSS_OBJECT_PROVIDER,
  37. &spEnumProvider);
  38. if (ft.HrFailed())
  39. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Query for Providers failed hr<%#x>", ft.hr);
  40. while (ft.HrSucceeded())
  41. {
  42. VSS_OBJECT_PROP prop;
  43. VSS_PROVIDER_PROP& propProv = prop.Obj.Prov;
  44. ULONG ulFetch = 0;
  45. ft.hr = spEnumProvider->Next(1, &prop, &ulFetch);
  46. if (ft.HrFailed())
  47. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  48. if (ft.hr == S_FALSE)
  49. {
  50. ft.hr = S_OK;
  51. break;
  52. }
  53. CVssAutoPWSZ awszProviderName(propProv.m_pwszProviderName);
  54. CVssAutoPWSZ awszProviderVersion(propProv.m_pwszProviderVersion);
  55. // Add to the ID list
  56. pList->Add(ft, propProv.m_ProviderId);
  57. }
  58. return;
  59. }
  60. HRESULT
  61. MapContextNameToEnum(
  62. IN const WCHAR* pwszContextName,
  63. OUT LONG* plContext
  64. ) throw(HRESULT)
  65. {
  66. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"MapContextToEnum");
  67. _ASSERTE(pwszContextName != NULL);
  68. _ASSERTE(plContext != NULL);
  69. *plContext = 0;
  70. if (!_wcsicmp(pwszContextName, VSS_CTX_NAME_CLIENTACCESSIBLE))
  71. {
  72. *plContext = VSS_CTX_CLIENT_ACCESSIBLE;
  73. }
  74. else if (!_wcsicmp(pwszContextName, VSS_CTX_NAME_NASROLLBACK))
  75. {
  76. *plContext = VSS_CTX_NAS_ROLLBACK;
  77. }
  78. else
  79. {
  80. ft.hr = VSS_E_UNSUPPORTED_CONTEXT;
  81. ft.Trace(VSSDBG_VSSADMIN,
  82. L"Unsupported context name, context<%lS>", pwszContextName);
  83. }
  84. return ft.hr;
  85. }
  86. //****************************************************************************
  87. //
  88. // CProvider
  89. //
  90. //****************************************************************************
  91. CProvider::CProvider(
  92. IN LPCWSTR pwszName,
  93. IN CWbemServices* pNamespace
  94. )
  95. : CProvBase( pwszName, pNamespace )
  96. {
  97. } //*** CProvider::CProvider()
  98. CProvBase *
  99. CProvider::S_CreateThis(
  100. IN LPCWSTR pwszName,
  101. IN CWbemServices* pNamespace
  102. )
  103. {
  104. HRESULT hr = WBEM_E_FAILED;
  105. CProvider * pProvider = NULL;
  106. pProvider = new CProvider(pwszName, pNamespace);
  107. if (pProvider)
  108. {
  109. hr = pProvider->Initialize();
  110. }
  111. else
  112. {
  113. hr = E_OUTOFMEMORY;
  114. }
  115. if (FAILED(hr))
  116. {
  117. delete pProvider;
  118. pProvider = NULL;
  119. }
  120. return pProvider;
  121. } //*** CProvider::S_CreateThis()
  122. HRESULT
  123. CProvider::EnumInstance(
  124. IN long lFlags,
  125. IN IWbemContext* pCtx,
  126. IN IWbemObjectSink* pHandler
  127. )
  128. {
  129. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CProvider::EnumInstance");
  130. HANDLE hToken = INVALID_HANDLE_VALUE;
  131. try
  132. {
  133. CComPtr<IVssEnumObject> spEnumProvider;
  134. ft.hr = m_spCoord->SetContext(VSS_CTX_ALL);
  135. if (ft.HrFailed())
  136. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  137. L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  138. ft.hr = m_spCoord->Query(
  139. GUID_NULL,
  140. VSS_OBJECT_NONE,
  141. VSS_OBJECT_PROVIDER,
  142. &spEnumProvider);
  143. if (ft.HrFailed())
  144. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  145. L"IVssCoordinator::Query failed, hr<%#x>", ft.hr);
  146. while (ft.HrSucceeded())
  147. {
  148. CComPtr<IWbemClassObject> spInstance;
  149. VSS_OBJECT_PROP prop;
  150. VSS_PROVIDER_PROP& propProv = prop.Obj.Prov;
  151. ULONG ulFetch = 0;
  152. ft.hr = spEnumProvider->Next(1, &prop, &ulFetch);
  153. if (ft.HrFailed())
  154. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  155. if (ft.hr == S_FALSE)
  156. {
  157. ft.hr = S_OK;
  158. break; // All done
  159. }
  160. CVssAutoPWSZ awszProviderName(propProv.m_pwszProviderName);
  161. CVssAutoPWSZ awszProviderVersion(propProv.m_pwszProviderVersion);
  162. // Spawn an instance of the class
  163. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  164. if (ft.HrFailed())
  165. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  166. LoadInstance(&propProv, spInstance.p);
  167. ft.hr = pHandler->Indicate(1, &spInstance.p);
  168. }
  169. }
  170. catch (HRESULT hrEx)
  171. {
  172. ft.hr = hrEx;
  173. }
  174. return ft.hr;
  175. } //*** CProvider::EnumInstance()
  176. HRESULT
  177. CProvider::GetObject(
  178. IN CObjPath& rObjPath,
  179. IN long lFlags,
  180. IN IWbemContext* pCtx,
  181. IN IWbemObjectSink* pHandler
  182. )
  183. {
  184. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CProvider::GetObject");
  185. try
  186. {
  187. CComPtr<IWbemClassObject> spInstance;
  188. CComPtr<IVssEnumObject> spEnumProvider;
  189. _bstr_t bstrID;
  190. GUID guid;
  191. // Get the Shadow ID (GUID)
  192. bstrID = rObjPath.GetStringValueForProperty(PVDR_PROP_ID);
  193. IF_WSTR_NULL_THROW(bstrID, WBEM_E_INVALID_OBJECT_PATH, L"CProvider::GetObject: provider key property not found");
  194. // Convert string GUID
  195. if (FAILED(CLSIDFromString(bstrID, &guid)))
  196. {
  197. ft.hr = E_INVALIDARG;
  198. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  199. L"CProvider::GetObject failed invalid ID (%lS), CLSIDFromString hr<%#x>", bstrID, ft.hr);
  200. }
  201. ft.hr = m_spCoord->Query(
  202. GUID_NULL,
  203. VSS_OBJECT_NONE,
  204. VSS_OBJECT_PROVIDER,
  205. &spEnumProvider);
  206. if (ft.HrFailed())
  207. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  208. L"IVssCoordinator::Query failed, hr<%#x>", ft.hr);
  209. while (ft.HrSucceeded())
  210. {
  211. VSS_OBJECT_PROP prop;
  212. VSS_PROVIDER_PROP& propProv = prop.Obj.Prov;
  213. ULONG ulFetch = 0;
  214. _bstr_t bstrValue;
  215. ft.hr = spEnumProvider->Next(1, &prop, &ulFetch);
  216. if (ft.HrFailed())
  217. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  218. if (ft.hr == S_FALSE)
  219. {
  220. ft.hr = WBEM_E_NOT_FOUND;
  221. break; // All done; the provider was not found
  222. }
  223. CVssAutoPWSZ awszProviderName(propProv.m_pwszProviderName);
  224. CVssAutoPWSZ awszProviderVersion(propProv.m_pwszProviderVersion);
  225. if (guid == propProv.m_ProviderId)
  226. {
  227. // Spawn an instance of the class
  228. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  229. if (ft.HrFailed())
  230. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  231. LoadInstance(&propProv, spInstance.p);
  232. ft.hr = pHandler->Indicate(1, &spInstance.p);
  233. break; // Found the provider; stop looking
  234. }
  235. }
  236. }
  237. catch (HRESULT hrEx)
  238. {
  239. ft.hr = hrEx;
  240. }
  241. return ft.hr;
  242. } //*** CProvider::GetObject()
  243. void
  244. CProvider::LoadInstance(
  245. IN VSS_PROVIDER_PROP* pProp,
  246. IN OUT IWbemClassObject* pObject
  247. )
  248. {
  249. CWbemClassObject wcoInstance(pObject);
  250. // Set the ID property
  251. CVssAutoPWSZ awszGUID(GuidToString(pProp->m_ProviderId)); // Auto-delete string
  252. wcoInstance.SetProperty(awszGUID, PVDR_PROP_ID);
  253. // Set the CLSID property
  254. awszGUID.Attach(GuidToString(pProp->m_ClassId));
  255. wcoInstance.SetProperty(awszGUID, PVDR_PROP_CLSID);
  256. // Set the VersionID property
  257. awszGUID.Attach(GuidToString(pProp->m_ProviderVersionId));
  258. wcoInstance.SetProperty(awszGUID, PVDR_PROP_VERSIONID);
  259. // Set the Version string property
  260. wcoInstance.SetProperty(pProp->m_pwszProviderVersion, PVDR_PROP_VERSION);
  261. // Set the Name property
  262. wcoInstance.SetProperty(pProp->m_pwszProviderName, PVDR_PROP_NAME);
  263. // Set the Type property
  264. wcoInstance.SetProperty(pProp->m_eProviderType, PVDR_PROP_TYPE);
  265. }
  266. #ifdef ENABLE_WRITERS
  267. //****************************************************************************
  268. //
  269. // CWriter
  270. //
  271. //****************************************************************************
  272. CWriter::CWriter(
  273. IN LPCWSTR pwszName,
  274. IN CWbemServices* pNamespace
  275. )
  276. : CProvBase(pwszName, pNamespace)
  277. {
  278. } //*** CWriter::CWriter()
  279. CProvBase *
  280. CWriter::S_CreateThis(
  281. IN LPCWSTR pwszName,
  282. IN CWbemServices* pNamespace
  283. )
  284. {
  285. HRESULT hr = WBEM_E_FAILED;
  286. CWriter * pWriter = NULL;
  287. pWriter = new CWriter(pwszName, pNamespace);
  288. if (pWriter)
  289. {
  290. hr = pWriter->Initialize();
  291. }
  292. else
  293. {
  294. hr = E_OUTOFMEMORY;
  295. }
  296. if (FAILED(hr))
  297. {
  298. delete pWriter;
  299. pWriter = NULL;
  300. }
  301. return pWriter;
  302. } //*** CWriter::S_CreateThis()
  303. HRESULT
  304. CWriter::EnumInstance(
  305. IN long lFlags,
  306. IN IWbemContext* pCtx,
  307. IN IWbemObjectSink* pHandler
  308. )
  309. {
  310. CComPtr<IVssBackupComponents> spBackup;
  311. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CWriter::EnumInstance");
  312. try
  313. {
  314. CComPtr<IVssAsync> spAsync;
  315. HRESULT hrAsync = S_OK;
  316. int nReserved = 0;
  317. UINT unWriterCount = 0;
  318. // Get the backup components object
  319. ft.hr = ::CreateVssBackupComponents(&spBackup);
  320. if (ft.HrFailed())
  321. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"CreateVssBackupComponents failed, hr<%#x>", ft.hr);
  322. // Ininitilize the backup components object
  323. ft.hr = spBackup->InitializeForBackup();
  324. if (ft.HrFailed())
  325. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"InitializeForBackup failed, hr<%#x>", ft.hr);
  326. // Get metadata for all writers
  327. ft.hr = spBackup->GatherWriterMetadata(&spAsync);
  328. if (ft.HrFailed())
  329. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"GatherWriterMetadata failed, hr<%#x>", ft.hr);
  330. ft.hr = spAsync->QueryStatus(&hrAsync, &nReserved);
  331. if (ft.HrFailed())
  332. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IVssAsync::QueryStatus failed, hr<%#x>", ft.hr);
  333. if (hrAsync == VSS_S_ASYNC_PENDING)
  334. {
  335. // Wait some more if needed
  336. ft.hr = spAsync->Wait();
  337. if (ft.HrFailed())
  338. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IVssAsync::Wait failed, hr<%#x>", ft.hr);
  339. ft.hr = spAsync->QueryStatus(&hrAsync, &nReserved);
  340. if (ft.HrFailed())
  341. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IVssAsync::QueryStatus failed, hr<%#x>", ft.hr);
  342. }
  343. // Check the async status for errors
  344. if (FAILED(hrAsync))
  345. ft.Throw(VSSDBG_VSSADMIN, hrAsync, L"GatherWriterMetadata async method failed, hr<%#x>", hrAsync);
  346. // Release the async helper
  347. spAsync = NULL;
  348. // Free the writer metadata
  349. ft.hr = spBackup->FreeWriterMetadata();
  350. if (ft.HrFailed())
  351. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"FreeWriterMetadata failed, hr<%#x>", ft.hr);
  352. // Gather the status of all writers
  353. ft.hr = spBackup->GatherWriterStatus(&spAsync);
  354. if (ft.HrFailed())
  355. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"GatherWriterStatus failed, hr<%#x>", ft.hr);
  356. ft.hr = spAsync->Wait();
  357. if (ft.HrFailed())
  358. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IVssAsync::Wait failed, hr<%#x>", ft.hr);
  359. ft.hr = spAsync->QueryStatus(&hrAsync, &nReserved);
  360. if (ft.HrFailed())
  361. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IVssAsync::QueryStatus failed, hr<%#x>", ft.hr);
  362. // Check the async status for errors
  363. if (FAILED(hrAsync))
  364. ft.Throw(VSSDBG_VSSADMIN, hrAsync, L"GatherWriterStatus async method failed, hr<%#x>", hrAsync);
  365. spAsync = NULL;
  366. ft.hr = spBackup->GetWriterStatusCount(&unWriterCount);
  367. if (ft.HrFailed())
  368. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"GetWriterStatusCount failed, hr<%#x>", ft.hr);
  369. for (DWORD i = 0; i < unWriterCount; i++)
  370. {
  371. VSS_ID idInstance = GUID_NULL;
  372. VSS_ID idWriter = GUID_NULL;
  373. CComBSTR bstrWriter;
  374. VSS_WRITER_STATE eState = VSS_WS_UNKNOWN;
  375. HRESULT hrLastError = S_OK;
  376. CComPtr<IWbemClassObject> spInstance;
  377. ft.hr = spBackup->GetWriterStatus(
  378. i,
  379. &idInstance,
  380. &idWriter,
  381. &bstrWriter,
  382. &eState,
  383. &hrLastError);
  384. if (ft.HrFailed())
  385. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"GetWriterStatus failed, hr<%#x>", ft.hr);
  386. ft.hr = m_pClass->SpawnInstance(0, &spInstance);
  387. CWbemClassObject wcoInstance(spInstance.p);
  388. // Set the ID property
  389. CVssAutoPWSZ awszGUID(GuidToString(idInstance)); // Auto-delete string
  390. wcoInstance.SetProperty(awszGUID, PVDR_PROP_ID);
  391. // Set the CLSID property
  392. awszGUID.Attach(GuidToString(idWriter));
  393. wcoInstance.SetProperty(awszGUID, PVDR_PROP_CLSID);
  394. // Set the Name property
  395. wcoInstance.SetProperty(bstrWriter, PVDR_PROP_NAME);
  396. // Set the State property
  397. wcoInstance.SetProperty(eState, PVDR_PROP_STATE);
  398. // Set the LastError property
  399. wcoInstance.SetProperty(hrLastError, PVDR_PROP_LASTERROR);
  400. ft.hr = pHandler->Indicate(1, wcoInstance.dataPtr());
  401. }
  402. ft.hr = spBackup->FreeWriterStatus();
  403. if (ft.HrFailed())
  404. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"FreeWriterStatus failed, hr<%#x>", ft.hr);
  405. }
  406. catch (HRESULT hrEx)
  407. {
  408. ft.hr = hrEx;
  409. }
  410. return ft.hr;
  411. } //*** CWriter::EnumInstance()
  412. HRESULT
  413. CWriter::GetObject(
  414. IN CObjPath& rObjPath,
  415. IN long lFlags,
  416. IN IWbemContext* pCtx,
  417. IN IWbemObjectSink* pHandler
  418. )
  419. {
  420. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CWriter::GetObject");
  421. HRESULT hr = WBEM_E_NOT_FOUND;
  422. //_bstr_t bstrClassName;
  423. _bstr_t bstrName;
  424. //CComPtr< IWbemClassObject > spInstance;
  425. bstrName = rObjPath.GetStringValueForProperty( PVDR_PROP_NAME );
  426. return hr;
  427. } //*** CWriter::GetObject()
  428. #endif // ENABLE_WRITERS
  429. //****************************************************************************
  430. //
  431. // CShadow
  432. //
  433. //****************************************************************************
  434. CShadow::CShadow(
  435. IN LPCWSTR pwszName,
  436. IN CWbemServices* pNamespace
  437. )
  438. : CProvBase(pwszName, pNamespace)
  439. {
  440. } //*** CShadow::CShadow()
  441. CProvBase *
  442. CShadow::S_CreateThis(
  443. IN LPCWSTR pwszName,
  444. IN CWbemServices* pNamespace
  445. )
  446. {
  447. HRESULT hr = WBEM_E_FAILED;
  448. CShadow * pShadow = NULL;
  449. pShadow = new CShadow(pwszName, pNamespace);
  450. if (pShadow)
  451. {
  452. hr = pShadow->Initialize();
  453. }
  454. else
  455. {
  456. hr = E_OUTOFMEMORY;
  457. }
  458. if (FAILED(hr))
  459. {
  460. delete pShadow;
  461. pShadow = NULL;
  462. }
  463. return pShadow;
  464. } //*** CShadow::S_CreateThis()
  465. HRESULT
  466. CShadow::EnumInstance(
  467. IN long lFlags,
  468. IN IWbemContext* pCtx,
  469. IN IWbemObjectSink* pHandler
  470. )
  471. {
  472. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadow::EnumInstance");
  473. try
  474. {
  475. CComPtr<IVssEnumObject> spEnumShadow;
  476. ft.hr = m_spCoord->SetContext(VSS_CTX_ALL);
  477. if (ft.HrFailed())
  478. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  479. L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  480. ft.hr = m_spCoord->Query(
  481. GUID_NULL,
  482. VSS_OBJECT_NONE,
  483. VSS_OBJECT_SNAPSHOT,
  484. &spEnumShadow);
  485. if (ft.HrFailed())
  486. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  487. L"IVssCoordinator::Query failed, hr<%#x>", ft.hr);
  488. while (ft.HrSucceeded() && ft.hr != S_FALSE)
  489. {
  490. CComPtr<IWbemClassObject> spInstance;
  491. VSS_OBJECT_PROP prop;
  492. ULONG ulFetch = 0;
  493. ft.hr = spEnumShadow->Next(1, &prop, &ulFetch);
  494. if (ft.HrFailed())
  495. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  496. if (ft.hr == S_FALSE)
  497. {
  498. ft.hr = S_OK;
  499. break; // All done
  500. }
  501. CVssAutoSnapshotProperties apropSnap(prop);
  502. // Spawn an instance of the class
  503. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  504. if (ft.HrFailed())
  505. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  506. LoadInstance(apropSnap.GetPtr(), spInstance.p);
  507. ft.hr = pHandler->Indicate(1, &spInstance.p);
  508. }
  509. }
  510. catch (HRESULT hrEx)
  511. {
  512. ft.hr = hrEx;
  513. }
  514. return ft.hr;
  515. } //*** CShadow::EnumInstance()
  516. HRESULT
  517. CShadow::GetObject(
  518. IN CObjPath& rObjPath,
  519. IN long lFlags,
  520. IN IWbemContext* pCtx,
  521. IN IWbemObjectSink* pHandler
  522. )
  523. {
  524. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadow::GetObject");
  525. try
  526. {
  527. CComPtr<IVssEnumObject> spEnumShadow;
  528. VSS_SNAPSHOT_PROP propSnap;
  529. _bstr_t bstrID;
  530. GUID guid = GUID_NULL;
  531. // Get the Shadow ID (GUID)
  532. bstrID = rObjPath.GetStringValueForProperty(PVDR_PROP_ID);
  533. IF_WSTR_NULL_THROW(bstrID, WBEM_E_INVALID_OBJECT_PATH, L"CShadow::GetObject: shadow key property not found");
  534. // Convert string GUID
  535. if (FAILED(CLSIDFromString(bstrID, &guid)))
  536. {
  537. ft.hr = E_INVALIDARG;
  538. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  539. L"CShadow::GetObject invalid ID (guid), hr<%#x>", ft.hr);
  540. }
  541. // Set the context to see all shadows
  542. ft.hr = m_spCoord->SetContext(VSS_CTX_ALL);
  543. if (ft.HrFailed())
  544. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  545. L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  546. // Query for a particular shadow
  547. ft.hr = m_spCoord->GetSnapshotProperties(
  548. guid,
  549. &propSnap);
  550. if (ft.hr == VSS_E_OBJECT_NOT_FOUND)
  551. {
  552. ft.hr = WBEM_E_NOT_FOUND;
  553. }
  554. else
  555. {
  556. CComPtr<IWbemClassObject> spInstance;
  557. CVssAutoSnapshotProperties apropSnap(propSnap);
  558. if (ft.HrFailed())
  559. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  560. L"GetSnapshotProperties failed, hr<%#x>", ft.hr);
  561. // Spawn an instance of the class
  562. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  563. if (ft.HrFailed())
  564. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  565. LoadInstance(apropSnap.GetPtr(), spInstance.p);
  566. ft.hr = pHandler->Indicate(1, &spInstance.p);
  567. }
  568. }
  569. catch (HRESULT hrEx)
  570. {
  571. ft.hr = hrEx;
  572. }
  573. return ft.hr;
  574. } //*** CShadow::GetObject()
  575. HRESULT
  576. CShadow::ExecuteMethod(
  577. IN BSTR bstrObjPath,
  578. IN WCHAR* pwszMethodName,
  579. IN long lFlag,
  580. IN IWbemClassObject* pParams,
  581. IN IWbemObjectSink* pHandler
  582. )
  583. {
  584. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadow::ExecuteMethod");
  585. try
  586. {
  587. if (!_wcsicmp(pwszMethodName, PVDR_MTHD_CREATE))
  588. {
  589. CComPtr<IWbemClassObject> spOutParamClass;
  590. _bstr_t bstrVolume, bstrContext;
  591. VSS_ID idShadow = GUID_NULL;
  592. DWORD rcCreateStatus = ERROR_SUCCESS;
  593. if (pParams == NULL)
  594. {
  595. ft.hr = WBEM_E_INVALID_METHOD_PARAMETERS;
  596. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Shadow::Create called with no parameters, hr<%#x>", ft.hr);
  597. }
  598. CWbemClassObject wcoInParam(pParams);
  599. CWbemClassObject wcoOutParam;
  600. if (wcoInParam.data() == NULL)
  601. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Create GetMethod failed, hr<%#x>", ft.hr);
  602. // Gets the Context name string - input param
  603. wcoInParam.GetProperty(bstrContext, PVDR_PROP_CONTEXT);
  604. IF_WSTR_NULL_THROW(bstrContext, WBEM_E_INVALID_METHOD_PARAMETERS, L"Shadow: Create Context param is NULL");
  605. // Gets the Volume name string - input param
  606. wcoInParam.GetProperty(bstrVolume, PVDR_PROP_VOLUME);
  607. IF_WSTR_NULL_THROW(bstrVolume, WBEM_E_INVALID_METHOD_PARAMETERS, L"Shadow: Create Volume param is NULL");
  608. ft.hr = m_pClass->GetMethod(
  609. _bstr_t(PVDR_MTHD_CREATE),
  610. 0,
  611. NULL,
  612. &spOutParamClass
  613. );
  614. if (ft.HrFailed())
  615. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Create GetMethod failed, hr<%#x>", ft.hr);
  616. ft.hr = spOutParamClass->SpawnInstance(0, &wcoOutParam);
  617. if (ft.HrFailed())
  618. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  619. rcCreateStatus = Create(bstrContext, bstrVolume, &idShadow);
  620. ft.hr = wcoOutParam.SetProperty(rcCreateStatus, PVD_WBEM_PROP_RETURNVALUE);
  621. if (ft.HrFailed())
  622. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SetProperty failed, hr<%#x>", ft.hr);
  623. CVssAutoPWSZ awszGUID(GuidToString(idShadow)); // Auto-delete string
  624. ft.hr = wcoOutParam.SetProperty(awszGUID, PVDR_PROP_SHADOWID);
  625. if (ft.HrFailed())
  626. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SetProperty failed, hr<%#x>", ft.hr);
  627. ft.hr = pHandler->Indicate( 1, wcoOutParam.dataPtr() );
  628. }
  629. else
  630. {
  631. ft.hr = WBEM_E_INVALID_METHOD;
  632. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Invalid method called, %lS, hr<%#x>", pwszMethodName, ft.hr);
  633. }
  634. }
  635. catch (HRESULT hrEx)
  636. {
  637. ft.hr = hrEx;
  638. }
  639. return ft.hr;
  640. } //*** CShadow::ExecuteMethod()
  641. HRESULT
  642. CShadow::Create(
  643. IN BSTR bstrContext,
  644. IN BSTR bstrVolume,
  645. OUT VSS_ID* pidShadowID)
  646. {
  647. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadow::Create");
  648. DWORD rcStatus = ERROR_SUCCESS;
  649. do
  650. {
  651. CComPtr<IVssAsync> spAsync;
  652. VSS_ID idShadow = GUID_NULL;
  653. VSS_ID idShadowSet = GUID_NULL;
  654. LONG lContext = VSS_CTX_ALL;
  655. HRESULT hrStatus = S_OK;
  656. WCHAR wszVolumeGUIDName[MAX_PATH];
  657. DWORD dwRet = ERROR_SUCCESS;
  658. _ASSERTE(bstrContext != NULL);
  659. _ASSERTE(bstrVolume != NULL);
  660. _ASSERTE(pidShadowID != NULL);
  661. // Decode the context name string (gen exception for unsupported/invalid context)
  662. ft.hr = MapContextNameToEnum(bstrContext, &lContext);
  663. if (ft.HrFailed()) break;
  664. // Input volume name can be drive letter path, mount point or volume GUID name.
  665. // Get the volume GUID name; error if none found
  666. // This API returns the volume GUID name when the GUID name is input
  667. if (!GetVolumeNameForVolumeMountPoint(
  668. bstrVolume,
  669. wszVolumeGUIDName,
  670. ARRAY_LEN(wszVolumeGUIDName)))
  671. {
  672. dwRet = GetLastError();
  673. if (dwRet == ERROR_INVALID_NAME)
  674. {
  675. ft.hr = WBEM_E_INVALID_METHOD_PARAMETERS;
  676. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"invalid volume name %lS", (WCHAR*)bstrVolume);
  677. }
  678. // may return ERROR_FILE_NOT_FOUND == GetLastError()
  679. ft.hr = HRESULT_FROM_WIN32(GetLastError());
  680. ft.Trace(VSSDBG_VSSADMIN, L"GetVolumeNameForVolumeMountPoint failed %#x", GetLastError());
  681. break;
  682. }
  683. // Set the context
  684. ft.hr = m_spCoord->SetContext(lContext);
  685. //ft.hr = m_spCoord->SetContext(VSS_CTX_CLIENT_ACCESSIBLE);
  686. if (ft.HrFailed())
  687. {
  688. ft.Trace(VSSDBG_VSSADMIN, L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  689. break;
  690. }
  691. // Start the shadow copy set
  692. ft.hr = m_spCoord->StartSnapshotSet(&idShadowSet);
  693. if (ft.HrFailed())
  694. {
  695. ft.Trace(VSSDBG_VSSADMIN, L"StartSnapshotSet failed, hr<%#x>", ft.hr);
  696. break;
  697. }
  698. // Add the selected volume
  699. ft.hr = m_spCoord->AddToSnapshotSet(
  700. wszVolumeGUIDName,
  701. GUID_NULL, // VSS Coordinator will choose the best provider
  702. &idShadow);
  703. if (ft.HrFailed())
  704. {
  705. ft.Trace(VSSDBG_VSSADMIN, L"AddToSnapshotSet failed, hr<%#x>", ft.hr);
  706. break;
  707. }
  708. // Initiate the shadow copy
  709. ft.hr = m_spCoord->DoSnapshotSet(
  710. NULL,
  711. &spAsync);
  712. if (ft.HrFailed())
  713. {
  714. ft.Trace(VSSDBG_VSSADMIN, L"DoSnapshotSet failed, hr<%#x>", ft.hr);
  715. break;
  716. }
  717. // Wait for the result
  718. ft.hr = spAsync->Wait();
  719. if ( ft.HrFailed() )
  720. {
  721. ft.Trace( VSSDBG_VSSADMIN, L"IVssAsync::Wait failed hr<%#x>", ft.hr);
  722. break;
  723. }
  724. ft.hr = spAsync->QueryStatus(&hrStatus, NULL);
  725. if ( ft.HrFailed() )
  726. {
  727. ft.Trace( VSSDBG_VSSADMIN, L"IVssAsync::QueryStatus failed hr<%#x>", ft.hr);
  728. break;
  729. }
  730. if (SUCCEEDED(hrStatus))
  731. {
  732. *pidShadowID = idShadow;
  733. hrStatus = S_OK; // VSS returns VSS_S_ASYNC_COMPLETED for async operations
  734. }
  735. ft.hr = hrStatus;
  736. }
  737. while(0);
  738. // Don't map out of memory to return code
  739. if (ft.hr == E_OUTOFMEMORY)
  740. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"CShadow::Create: out of memory");
  741. // Map HRESULT to WMI method return code
  742. CreateMapStatus(ft.hr, rcStatus);
  743. return rcStatus;
  744. } //*** CShadow::Create()
  745. void
  746. CShadow::CreateMapStatus(
  747. IN HRESULT hr,
  748. OUT DWORD& rc
  749. )
  750. {
  751. HRESULT hrFileNotFound = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  752. if (hr == hrFileNotFound)
  753. rc = VSS_SHADOW_CREATE_RC_VOLUME_NOT_FOUND;
  754. else if (hr == S_OK)
  755. rc = VSS_SHADOW_CREATE_RC_NO_ERROR;
  756. else if (hr == E_ACCESSDENIED)
  757. rc = VSS_SHADOW_CREATE_RC_ACCESS_DENIED;
  758. else if (hr == E_INVALIDARG)
  759. rc = VSS_SHADOW_CREATE_RC_INVALID_ARG;
  760. else if (hr == VSS_E_OBJECT_NOT_FOUND)
  761. rc = VSS_SHADOW_CREATE_RC_VOLUME_NOT_FOUND;
  762. else if (hr == VSS_E_VOLUME_NOT_SUPPORTED)
  763. rc = VSS_SHADOW_CREATE_RC_VOLUME_NOT_SUPPORTED;
  764. else if (hr == VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER)
  765. rc = VSS_SHADOW_CREATE_RC_VOLUME_NOT_SUPPORTED;
  766. else if (hr == VSS_E_UNSUPPORTED_CONTEXT)
  767. rc = VSS_SHADOW_CREATE_RC_UNSUPPORTED_CONTEXT;
  768. else if (hr == VSS_E_INSUFFICIENT_STORAGE)
  769. rc = VSS_SHADOW_CREATE_RC_INSUFFICIENT_STORAGE;
  770. else if (hr == VSS_E_VOLUME_IN_USE)
  771. rc = VSS_SHADOW_CREATE_RC_VOLUME_IN_USE;
  772. else if (hr == VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED)
  773. rc = VSS_SHADOW_CREATE_RC_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED;
  774. else if (hr == VSS_E_SNAPSHOT_SET_IN_PROGRESS)
  775. rc = VSS_SHADOW_CREATE_RC_SHADOW_COPY_IN_PROGRESS;
  776. else if (hr == VSS_E_PROVIDER_VETO)
  777. rc = VSS_SHADOW_CREATE_RC_PROVIDER_VETO;
  778. else if (hr == VSS_E_PROVIDER_NOT_REGISTERED)
  779. rc = VSS_SHADOW_CREATE_RC_PROVIDER_NOT_REGISTERED;
  780. else if (hr == VSS_E_UNEXPECTED_PROVIDER_ERROR)
  781. rc = VSS_SHADOW_CREATE_RC_UNEXPECTED_PROVIDER_FAILURE;
  782. else if (hr == E_UNEXPECTED)
  783. rc = VSS_SHADOW_CREATE_RC_UNEXPECTED;
  784. else if (hr == VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED)
  785. rc = VSS_SHADOW_CREATE_RC_UNEXPECTED;
  786. else if (hr == VSS_E_OBJECT_ALREADY_EXISTS)
  787. rc = VSS_SHADOW_CREATE_RC_UNEXPECTED;
  788. else if (hr == VSS_E_BAD_STATE)
  789. rc = VSS_SHADOW_CREATE_RC_UNEXPECTED;
  790. else
  791. rc = VSS_SHADOW_CREATE_RC_UNEXPECTED;
  792. }
  793. HRESULT
  794. CShadow::DeleteInstance(
  795. IN CObjPath& rObjPath,
  796. IN long lFlag,
  797. IN IWbemContext* pCtx,
  798. IN IWbemObjectSink* pHandler
  799. )
  800. {
  801. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadow::DeleteInstance");
  802. try
  803. {
  804. CComPtr<IVssSnapshotMgmt> spMgmt;
  805. _bstr_t bstrID;
  806. VSS_ID guid;
  807. long nDeleted = 0;
  808. VSS_ID idNonDeleted = GUID_NULL;
  809. // Get the Shadow ID
  810. bstrID = rObjPath.GetStringValueForProperty(PVDR_PROP_ID);
  811. IF_WSTR_NULL_THROW(bstrID, WBEM_E_INVALID_OBJECT_PATH, L"CShadow::DeleteInstance: shadow key property not found");
  812. // Convert string GUID
  813. if (FAILED(CLSIDFromString(bstrID, &guid)))
  814. {
  815. ft.hr = E_INVALIDARG;
  816. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  817. L"CShadow::DeleteInstance failed invalid ID (%lS), CLSIDFromString hr<%#x>", bstrID, ft.hr);
  818. }
  819. ft.hr = m_spCoord->SetContext(VSS_CTX_ALL);
  820. if (ft.HrFailed())
  821. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  822. ft.hr = m_spCoord->DeleteSnapshots(
  823. guid,
  824. VSS_OBJECT_SNAPSHOT,
  825. TRUE, // Force delete
  826. &nDeleted,
  827. &idNonDeleted);
  828. if (ft.hr == VSS_E_OBJECT_NOT_FOUND)
  829. {
  830. ft.hr = WBEM_E_NOT_FOUND;
  831. ft.Trace(VSSDBG_VSSADMIN, L"CShadow::DeleteInstance: object not found");
  832. }
  833. if (ft.HrFailed())
  834. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"DeleteSnapshots failed, hr<%#x>", ft.hr);
  835. }
  836. catch (HRESULT hrEx)
  837. {
  838. ft.hr = hrEx;
  839. }
  840. return ft.hr;
  841. } //*** CShadow::DeleteInstance()
  842. void
  843. CShadow::LoadInstance(
  844. IN VSS_SNAPSHOT_PROP* pProp,
  845. IN OUT IWbemClassObject* pObject
  846. )
  847. {
  848. WBEMTime wbemTime;
  849. FILETIME ftGMT = {0,0};
  850. CWbemClassObject wcoInstance(pObject);
  851. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadow::LoadInstance");
  852. // Set the ID property
  853. CVssAutoPWSZ awszGUID(GuidToString(pProp->m_SnapshotId)); // Auto-delete string
  854. wcoInstance.SetProperty(awszGUID, PVDR_PROP_ID);
  855. // Set the SetID property
  856. awszGUID.Attach(GuidToString(pProp->m_SnapshotSetId));
  857. wcoInstance.SetProperty(awszGUID, PVDR_PROP_SETID);
  858. // Set the ProviderID property
  859. awszGUID.Attach(GuidToString(pProp->m_ProviderId));
  860. wcoInstance.SetProperty(awszGUID, PVDR_PROP_PROVIDERID);
  861. // Set the Count property
  862. wcoInstance.SetProperty(pProp->m_lSnapshotsCount, PVDR_PROP_COUNT);
  863. // Set the DeviceObject property
  864. wcoInstance.SetProperty(pProp->m_pwszSnapshotDeviceObject, PVDR_PROP_DEVICEOBJECT);
  865. // Set the VolumeName property
  866. wcoInstance.SetProperty(pProp->m_pwszOriginalVolumeName, PVDR_PROP_VOLUMENAME);
  867. // Set the OriginatingMachine property
  868. wcoInstance.SetProperty(pProp->m_pwszOriginatingMachine, PVDR_PROP_ORIGINATINGMACHINE);
  869. // Set the ServiceMachine property
  870. wcoInstance.SetProperty(pProp->m_pwszServiceMachine, PVDR_PROP_SERVICEMACHINE);
  871. // Set the ExposedName property
  872. wcoInstance.SetProperty(pProp->m_pwszExposedName, PVDR_PROP_EXPOSEDNAME);
  873. // Set the ExposedPath property
  874. wcoInstance.SetProperty(pProp->m_pwszExposedPath, PVDR_PROP_EXPOSEDPATH);
  875. // Set the TimeStamp property
  876. CopyMemory(&ftGMT, &pProp->m_tsCreationTimestamp, sizeof(ftGMT));
  877. wbemTime = ftGMT;
  878. if (wbemTime.IsOk())
  879. {
  880. CComBSTR bstrTime;
  881. bstrTime.Attach(wbemTime.GetDMTF(TRUE));
  882. wcoInstance.SetProperty(bstrTime, PVDR_PROP_TIMESTAMP);
  883. }
  884. else
  885. ft.Trace(VSSDBG_VSSADMIN, L"invalid shadow copy timespamp");
  886. // Set the State property
  887. wcoInstance.SetProperty(pProp->m_eStatus, PVDR_PROP_STATE);
  888. // Set the Persistent property
  889. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_PERSISTENT, PVDR_PROP_PERSISTENT);
  890. // Set the ClientAccessible property
  891. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_CLIENT_ACCESSIBLE, PVDR_PROP_CLIENTACCESSIBLE);
  892. // Set the NoAutoRelease property
  893. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_NO_AUTO_RELEASE, PVDR_PROP_NOAUTORELEASE);
  894. // Set the NoWriters property
  895. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_NO_WRITERS, PVDR_PROP_NOWRITERS);
  896. // Set the Transportable property
  897. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_TRANSPORTABLE, PVDR_PROP_TRANSPORTABLE);
  898. // Set the NotSurfaced property
  899. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_NOT_SURFACED, PVDR_PROP_NOTSURFACED);
  900. // Set the HardwareAssisted property
  901. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_HARDWARE_ASSISTED, PVDR_PROP_HARDWAREASSISTED);
  902. // Set the Differential property
  903. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_DIFFERENTIAL, PVDR_PROP_DIFFERENTIAL);
  904. // Set the Plex property
  905. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_PLEX, PVDR_PROP_PLEX);
  906. // Set the Imported property
  907. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_IMPORTED, PVDR_PROP_IMPORTED);
  908. // Set the ExposedRemotely property
  909. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_EXPOSED_REMOTELY, PVDR_PROP_EXPOSEDREMOTELY);
  910. // Set the ExposedLocally property
  911. wcoInstance.SetProperty(pProp->m_lSnapshotAttributes & VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY, PVDR_PROP_EXPOSEDLOCALLY);
  912. }
  913. //****************************************************************************
  914. //
  915. // CStorage
  916. //
  917. //****************************************************************************
  918. CStorage::CStorage(
  919. IN LPCWSTR pwszName,
  920. IN CWbemServices* pNamespace
  921. )
  922. : CProvBase(pwszName, pNamespace)
  923. {
  924. } //*** CStorage::CStorage()
  925. CProvBase *
  926. CStorage::S_CreateThis(
  927. IN LPCWSTR pwszName,
  928. IN CWbemServices* pNamespace
  929. )
  930. {
  931. HRESULT hr = WBEM_E_FAILED;
  932. CStorage* pStorage = NULL;
  933. pStorage = new CStorage(pwszName, pNamespace);
  934. if (pStorage)
  935. {
  936. hr = pStorage->Initialize();
  937. }
  938. else
  939. {
  940. hr = E_OUTOFMEMORY;
  941. }
  942. if (FAILED(hr))
  943. {
  944. delete pStorage;
  945. pStorage = NULL;
  946. }
  947. return pStorage;
  948. } //*** CStorage::S_CreateThis()
  949. HRESULT
  950. CStorage::EnumInstance(
  951. IN long lFlags,
  952. IN IWbemContext* pCtx,
  953. IN IWbemObjectSink* pHandler
  954. )
  955. {
  956. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::EnumInstance");
  957. try
  958. {
  959. CComPtr<IVssSnapshotMgmt> spMgmt;
  960. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  961. CComPtr<IVssEnumMgmtObject> spEnumVolume;
  962. VSS_ID idProvider = GUID_NULL;
  963. SelectDiffAreaProvider(&idProvider);
  964. // Create snapshot mgmt object
  965. ft.CoCreateInstanceWithLog(
  966. VSSDBG_VSSADMIN,
  967. CLSID_VssSnapshotMgmt,
  968. L"VssSnapshotMgmt",
  969. CLSCTX_ALL,
  970. IID_IVssSnapshotMgmt,
  971. (IUnknown**)&(spMgmt));
  972. if (ft.HrFailed())
  973. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  974. ft.hr = spMgmt->GetProviderMgmtInterface(
  975. idProvider,
  976. IID_IVssDifferentialSoftwareSnapshotMgmt,
  977. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  978. if (ft.HrFailed())
  979. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  980. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  981. ft.hr = spDiffMgmt->QueryVolumesSupportedForDiffAreas(NULL, &spEnumVolume);
  982. if (ft.HrFailed())
  983. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  984. L"QueryVolumesSupportedForDiffAreas failed, hr<%#x>", ft.hr);
  985. while (ft.hr == S_OK)
  986. {
  987. VSS_MGMT_OBJECT_PROP propMgmt;
  988. VSS_DIFF_VOLUME_PROP& propDiff = propMgmt.Obj.DiffVol;
  989. CComPtr<IVssEnumMgmtObject> spEnumDiffArea;
  990. ULONG ulFetch = 0;
  991. ft.hr = spEnumVolume->Next(1, &propMgmt, &ulFetch);
  992. if (ft.HrFailed())
  993. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  994. if (ft.hr == S_FALSE)
  995. {
  996. ft.hr = S_OK;
  997. break; // No more volumes; try next provider
  998. }
  999. CVssAutoPWSZ awszDiffVolumeName(propDiff.m_pwszVolumeName);
  1000. CVssAutoPWSZ awszDiffVolumeDisplayName(propDiff.m_pwszVolumeDisplayName);
  1001. ft.hr = spDiffMgmt->QueryDiffAreasOnVolume(
  1002. propDiff.m_pwszVolumeName,
  1003. &spEnumDiffArea);
  1004. if (ft.HrFailed())
  1005. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1006. L"QueryVolumesSupportedOnDiffAreas failed, hr<%#x>", ft.hr);
  1007. if (ft.hr == S_FALSE)
  1008. {
  1009. ft.hr = S_OK;
  1010. continue; // No diff areas, continue to next volume
  1011. }
  1012. while (1)
  1013. {
  1014. CComPtr<IWbemClassObject> spInstance;
  1015. VSS_MGMT_OBJECT_PROP propMgmtDA;
  1016. VSS_DIFF_AREA_PROP& propDiffArea = propMgmtDA.Obj.DiffArea;
  1017. ulFetch = 0;
  1018. ft.hr = spEnumDiffArea->Next(1, &propMgmtDA, &ulFetch);
  1019. if (ft.HrFailed())
  1020. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  1021. if (ft.hr == S_FALSE)
  1022. {
  1023. ft.hr = S_OK;
  1024. break; // No more diff areas; try next volume
  1025. }
  1026. CVssAutoPWSZ awszVolumeName(propDiffArea.m_pwszVolumeName);
  1027. CVssAutoPWSZ awszDiffAreaVolumeName(propDiffArea.m_pwszDiffAreaVolumeName);
  1028. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  1029. if (ft.HrFailed())
  1030. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  1031. LoadInstance(&propDiffArea, spInstance.p);
  1032. ft.hr = pHandler->Indicate(1, &spInstance.p);
  1033. }
  1034. }
  1035. }
  1036. catch (HRESULT hrEx)
  1037. {
  1038. ft.hr = hrEx;
  1039. }
  1040. return ft.hr;
  1041. } //*** CStorage::EnumInstance()
  1042. HRESULT
  1043. CStorage::GetObject(
  1044. IN CObjPath& rObjPath,
  1045. IN long lFlags,
  1046. IN IWbemContext* pCtx,
  1047. IN IWbemObjectSink* pHandler
  1048. )
  1049. {
  1050. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::GetObject");
  1051. try
  1052. {
  1053. CComPtr<IVssSnapshotMgmt> spMgmt;
  1054. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  1055. CComPtr<IVssEnumMgmtObject> spEnumDiffArea;
  1056. _bstr_t bstrVolumeRef, bstrVolumeName;
  1057. _bstr_t bstrDiffVolumeRef, bstrDiffVolumeName;
  1058. CObjPath objPathVolume;
  1059. CObjPath objPathDiffVolume;
  1060. VSS_ID idProvider = GUID_NULL;
  1061. BOOL fSupported = false;
  1062. // Get the Volume reference
  1063. bstrVolumeRef = rObjPath.GetStringValueForProperty(PVDR_PROP_VOLUME);
  1064. IF_WSTR_NULL_THROW(bstrVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"Storage::GetObject: storage volume key property not found");
  1065. // Get the DiffVolume reference
  1066. bstrDiffVolumeRef = rObjPath.GetStringValueForProperty(PVDR_PROP_DIFFVOLUME);
  1067. IF_WSTR_NULL_THROW(bstrDiffVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"Storage::GetObject: storage diff volume key property not found");
  1068. // Extract the Volume and DiffVolume Names
  1069. if (!objPathVolume.Init(bstrVolumeRef))
  1070. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"Storage::GetObject: Volume Object path parse failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1071. if (!objPathDiffVolume.Init(bstrDiffVolumeRef))
  1072. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"Storage::GetObject: DiffVolume Object path parse failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1073. bstrVolumeName = objPathVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  1074. IF_WSTR_NULL_THROW(bstrVolumeName, WBEM_E_INVALID_OBJECT_PATH, L"Storage::GetObject: storage volume key DeviceID property not found");
  1075. bstrDiffVolumeName = objPathDiffVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  1076. IF_WSTR_NULL_THROW(bstrDiffVolumeName, WBEM_E_INVALID_OBJECT_PATH, L"Storage::GetObject: storage diff volume key DeviceID property not found");
  1077. SelectDiffAreaProvider(&idProvider);
  1078. ft.hr = m_spCoord->IsVolumeSupported(idProvider, bstrVolumeName, &fSupported);
  1079. if (ft.HrFailed())
  1080. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IsVolumeSupported failed, hr<%#x>", ft.hr);
  1081. if (!fSupported)
  1082. {
  1083. ft.hr = WBEM_E_NOT_FOUND;
  1084. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Volume not supported by selected provider");
  1085. }
  1086. // Create snapshot mgmt object
  1087. ft.CoCreateInstanceWithLog(
  1088. VSSDBG_VSSADMIN,
  1089. CLSID_VssSnapshotMgmt,
  1090. L"VssSnapshotMgmt",
  1091. CLSCTX_ALL,
  1092. IID_IVssSnapshotMgmt,
  1093. (IUnknown**)&(spMgmt));
  1094. if (ft.HrFailed())
  1095. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  1096. // Get the Mgmt object for the Provider
  1097. ft.hr = spMgmt->GetProviderMgmtInterface(
  1098. idProvider,
  1099. IID_IVssDifferentialSoftwareSnapshotMgmt,
  1100. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  1101. if (ft.HrFailed())
  1102. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1103. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  1104. ft.hr = spDiffMgmt->QueryDiffAreasOnVolume(
  1105. bstrDiffVolumeName,
  1106. &spEnumDiffArea);
  1107. if (ft.HrFailed())
  1108. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1109. L"QueryVolumesSupportedOnDiffAreas failed, hr<%#x>", ft.hr);
  1110. while (ft.hr != S_FALSE)
  1111. {
  1112. CComPtr<IWbemClassObject> spInstance;
  1113. VSS_MGMT_OBJECT_PROP propMgmtDA;
  1114. VSS_DIFF_AREA_PROP& propDiffArea = propMgmtDA.Obj.DiffArea;
  1115. ULONG ulFetch = 0;
  1116. ft.hr = spEnumDiffArea->Next(1, &propMgmtDA, &ulFetch);
  1117. if (ft.HrFailed())
  1118. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  1119. if (ft.hr == S_FALSE)
  1120. {
  1121. break; // No more diff areas on this volume; diff area not found
  1122. }
  1123. CVssAutoPWSZ awszVolumeName(propDiffArea.m_pwszVolumeName);
  1124. CVssAutoPWSZ awszDiffAreaVolumeName(propDiffArea.m_pwszDiffAreaVolumeName);
  1125. if (_wcsicmp(awszVolumeName, bstrVolumeName) == 0)
  1126. {
  1127. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  1128. if (ft.HrFailed())
  1129. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  1130. LoadInstance(&propDiffArea, spInstance.p);
  1131. ft.hr = pHandler->Indicate(1, &spInstance.p);
  1132. break;
  1133. }
  1134. }
  1135. if (ft.hr == S_FALSE)
  1136. {
  1137. ft.hr = WBEM_E_NOT_FOUND;
  1138. }
  1139. }
  1140. catch (HRESULT hrEx)
  1141. {
  1142. ft.hr = hrEx;
  1143. }
  1144. return ft.hr;
  1145. }
  1146. HRESULT
  1147. CStorage::PutInstance(
  1148. IN CWbemClassObject& rInstToPut,
  1149. IN long lFlag,
  1150. IN IWbemContext* pCtx,
  1151. IN IWbemObjectSink* pHandler
  1152. )
  1153. {
  1154. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::PutInstance");
  1155. try
  1156. {
  1157. CComPtr<IVssSnapshotMgmt> spMgmt;
  1158. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  1159. _bstr_t bstrVolumeRef, bstrVolumeName;
  1160. _bstr_t bstrDiffVolumeRef, bstrDiffVolumeName;
  1161. CObjPath objPathVolume;
  1162. CObjPath objPathDiffVolume;
  1163. VSS_ID idProvider = GUID_NULL;
  1164. BOOL fSupported = false;
  1165. LONGLONG llMaxSpace = -1;
  1166. // Retrieve key properties of the object to be saved.
  1167. rInstToPut.GetProperty(bstrVolumeRef, PVDR_PROP_VOLUME);
  1168. IF_WSTR_NULL_THROW(bstrVolumeRef, WBEM_E_INVALID_OBJECT, L"Storage volume key property not found");
  1169. rInstToPut.GetProperty(bstrDiffVolumeRef, PVDR_PROP_DIFFVOLUME);
  1170. IF_WSTR_NULL_THROW(bstrDiffVolumeRef, WBEM_E_INVALID_OBJECT, L"Storage diff volume key property not found");
  1171. // Extract the Volume and DiffVolume Names
  1172. if (!objPathVolume.Init(bstrVolumeRef))
  1173. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"Storage::PutInstance: Volume Object path parse failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1174. if (!objPathDiffVolume.Init(bstrDiffVolumeRef))
  1175. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"Storage::PutInstance: DiffVolume Object path parse failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1176. bstrVolumeName = objPathVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  1177. IF_WSTR_NULL_THROW(bstrVolumeName, WBEM_E_INVALID_OBJECT_PATH, L"Storage volume key property DeviceID not found");
  1178. bstrDiffVolumeName = objPathDiffVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  1179. IF_WSTR_NULL_THROW(bstrDiffVolumeName, WBEM_E_INVALID_OBJECT_PATH, L"Storage diff volume key property DeviceID not found");
  1180. // Get the provider ID list
  1181. SelectDiffAreaProvider(&idProvider);
  1182. // Create snapshot mgmt object
  1183. ft.CoCreateInstanceWithLog(
  1184. VSSDBG_VSSADMIN,
  1185. CLSID_VssSnapshotMgmt,
  1186. L"VssSnapshotMgmt",
  1187. CLSCTX_ALL,
  1188. IID_IVssSnapshotMgmt,
  1189. (IUnknown**)&(spMgmt));
  1190. if (ft.HrFailed())
  1191. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  1192. // Get the Mgmt object for the Provider
  1193. ft.hr = spMgmt->GetProviderMgmtInterface(
  1194. idProvider,
  1195. IID_IVssDifferentialSoftwareSnapshotMgmt,
  1196. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  1197. if (ft.HrFailed())
  1198. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1199. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  1200. // Retrieve non-key properties of the object to be saved.
  1201. rInstToPut.GetPropertyI64(&llMaxSpace, PVDR_PROP_MAXSPACE);
  1202. // Change the max storage space for this association
  1203. ft.hr = spDiffMgmt->ChangeDiffAreaMaximumSize(
  1204. bstrVolumeName,
  1205. bstrDiffVolumeName,
  1206. llMaxSpace);
  1207. }
  1208. catch (HRESULT hrEx)
  1209. {
  1210. ft.hr = hrEx;
  1211. }
  1212. return ft.hr;
  1213. } //*** CStorage::PutInstance()
  1214. HRESULT
  1215. CStorage::ExecuteMethod(
  1216. IN BSTR bstrObjPath,
  1217. IN WCHAR* pwszMethodName,
  1218. IN long lFlag,
  1219. IN IWbemClassObject* pParams,
  1220. IN IWbemObjectSink* pHandler
  1221. )
  1222. {
  1223. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::ExecuteMethod");
  1224. try
  1225. {
  1226. if (!_wcsicmp(pwszMethodName, PVDR_MTHD_CREATE))
  1227. {
  1228. CComPtr<IWbemClassObject> spOutParamClass;
  1229. _bstr_t bstrVolume, bstrDiffVolume;
  1230. LONGLONG llMaxSpace = -1;
  1231. CWbemClassObject wcoOutParam;
  1232. DWORD rcCreateStatus = ERROR_SUCCESS;
  1233. if (pParams == NULL)
  1234. {
  1235. ft.hr = WBEM_E_INVALID_METHOD_PARAMETERS;
  1236. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Storage::Create called with no parameters, hr<%#x>", ft.hr);
  1237. }
  1238. CWbemClassObject wcoInParam(pParams);
  1239. // Gets the Volume name string - input param
  1240. wcoInParam.GetProperty(bstrVolume, PVDR_PROP_VOLUME);
  1241. IF_WSTR_NULL_THROW(bstrVolume, WBEM_E_INVALID_METHOD_PARAMETERS, L"Storage Create volume param is NULL");
  1242. // Gets the DiffVolume name string - input param
  1243. wcoInParam.GetProperty(bstrDiffVolume, PVDR_PROP_DIFFVOLUME);
  1244. IF_WSTR_NULL_THROW(bstrDiffVolume, WBEM_E_INVALID_METHOD_PARAMETERS, L"Storage Create diff volume param is NULL");
  1245. // Gets the MaxSpace property - input param
  1246. wcoInParam.GetPropertyI64(&llMaxSpace, PVDR_PROP_MAXSPACE);
  1247. ft.hr = m_pClass->GetMethod(
  1248. _bstr_t(PVDR_MTHD_CREATE),
  1249. 0,
  1250. NULL,
  1251. &spOutParamClass
  1252. );
  1253. if (ft.HrFailed())
  1254. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Create GetMethod failed, hr<%#x>", ft.hr);
  1255. ft.hr = spOutParamClass->SpawnInstance(0, &wcoOutParam);
  1256. if (ft.HrFailed())
  1257. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  1258. rcCreateStatus = Create(bstrVolume, bstrDiffVolume, llMaxSpace);
  1259. ft.hr = wcoOutParam.SetProperty(rcCreateStatus, PVD_WBEM_PROP_RETURNVALUE);
  1260. if (ft.HrFailed())
  1261. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SetProperty failed, hr<%#x>", ft.hr);
  1262. ft.hr = pHandler->Indicate( 1, wcoOutParam.dataPtr() );
  1263. }
  1264. else
  1265. {
  1266. ft.hr = WBEM_E_INVALID_METHOD;
  1267. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Invalid method called, %lS, hr<%#x>", pwszMethodName, ft.hr);
  1268. }
  1269. }
  1270. catch (HRESULT hrEx)
  1271. {
  1272. ft.hr = hrEx;
  1273. }
  1274. return ft.hr;
  1275. } //*** CStorage::ExecuteMethod()
  1276. HRESULT
  1277. CStorage::Create(
  1278. IN BSTR bstrVolume,
  1279. IN BSTR bstrDiffVolume,
  1280. IN LONGLONG llMaxSpace)
  1281. {
  1282. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::Create");
  1283. DWORD rcStatus = ERROR_SUCCESS;
  1284. DWORD dwRet = ERROR_SUCCESS;
  1285. do
  1286. {
  1287. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  1288. CComPtr<IVssSnapshotMgmt> spMgmt;
  1289. VSS_ID idProvider = GUID_NULL;
  1290. BOOL fSupported = false;
  1291. WCHAR wszVolumeGUIDName[MAX_PATH];
  1292. WCHAR wszDiffVolumeGUIDName[MAX_PATH];
  1293. // Input volume name can be drive letter path, mount point or volume GUID name.
  1294. // Get the volume GUID name; error if none found
  1295. // This API returns the volume GUID name when the GUID name is input
  1296. if (!GetVolumeNameForVolumeMountPoint(
  1297. bstrVolume,
  1298. wszVolumeGUIDName,
  1299. ARRAY_LEN(wszVolumeGUIDName)))
  1300. {
  1301. dwRet = GetLastError();
  1302. if (dwRet == ERROR_INVALID_NAME)
  1303. {
  1304. ft.hr = WBEM_E_INVALID_METHOD_PARAMETERS;
  1305. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"invalid volume name %lS", (WCHAR*)bstrVolume);
  1306. }
  1307. // may return ERROR_FILE_NOT_FOUND == GetLastError()
  1308. ft.hr = HRESULT_FROM_WIN32(dwRet);
  1309. ft.Trace(VSSDBG_VSSADMIN, L"GetVolumeNameForVolumeMountPoint failed %#x", dwRet);
  1310. break;
  1311. }
  1312. // Get the differential volume GUID name; error if none found
  1313. if (!GetVolumeNameForVolumeMountPoint(
  1314. bstrDiffVolume,
  1315. wszDiffVolumeGUIDName,
  1316. ARRAY_LEN(wszDiffVolumeGUIDName)))
  1317. {
  1318. dwRet = GetLastError();
  1319. if (dwRet == ERROR_INVALID_NAME)
  1320. {
  1321. ft.hr = WBEM_E_INVALID_METHOD_PARAMETERS;
  1322. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"invalid volume name %lS", (WCHAR*)bstrVolume);
  1323. }
  1324. // may return ERROR_FILE_NOT_FOUND == GetLastError()
  1325. ft.hr = HRESULT_FROM_WIN32(GetLastError());
  1326. ft.Trace(VSSDBG_VSSADMIN, L"GetVolumeNameForVolumeMountPoint failed %#x", GetLastError());
  1327. break;
  1328. }
  1329. // Create snapshot mgmt object
  1330. ft.CoCreateInstanceWithLog(
  1331. VSSDBG_VSSADMIN,
  1332. CLSID_VssSnapshotMgmt,
  1333. L"VssSnapshotMgmt",
  1334. CLSCTX_ALL,
  1335. IID_IVssSnapshotMgmt,
  1336. (IUnknown**)&(spMgmt));
  1337. if (ft.HrFailed())
  1338. {
  1339. ft.Trace(VSSDBG_VSSADMIN, L"Connection failed with hr<%#x>", ft.hr);
  1340. break;
  1341. }
  1342. SelectDiffAreaProvider(&idProvider);
  1343. ft.hr = m_spCoord->IsVolumeSupported(idProvider, wszVolumeGUIDName, &fSupported);
  1344. if (ft.HrFailed())
  1345. {
  1346. ft.Trace(VSSDBG_VSSADMIN, L"IsVolumeSupported failed, hr<%#x>", ft.hr);
  1347. break;
  1348. }
  1349. ft.hr = spMgmt->GetProviderMgmtInterface(
  1350. idProvider,
  1351. IID_IVssDifferentialSoftwareSnapshotMgmt,
  1352. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  1353. if (ft.HrFailed())
  1354. {
  1355. ft.Trace(VSSDBG_VSSADMIN, L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  1356. break;
  1357. }
  1358. ft.hr = spDiffMgmt->AddDiffArea(wszVolumeGUIDName, wszDiffVolumeGUIDName, llMaxSpace);
  1359. if (ft.HrFailed())
  1360. {
  1361. ft.Trace(VSSDBG_VSSADMIN, L"AddDiffArea failed, hr<%#x>", ft.hr);
  1362. break;
  1363. }
  1364. }
  1365. while(false);
  1366. if (ft.hr == E_OUTOFMEMORY)
  1367. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"CStorage::Create: out of memory");
  1368. CreateMapStatus(ft.hr, rcStatus);
  1369. return rcStatus;
  1370. } //*** CStorage::Create()
  1371. void
  1372. CStorage::CreateMapStatus(
  1373. IN HRESULT hr,
  1374. OUT DWORD& rc
  1375. )
  1376. {
  1377. HRESULT hrFileNotFound = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  1378. if (hr == hrFileNotFound)
  1379. rc = VSS_STORAGE_CREATE_RC_VOLUME_NOT_FOUND;
  1380. else if (hr == S_OK)
  1381. rc = VSS_STORAGE_CREATE_RC_NO_ERROR;
  1382. else if (hr == E_ACCESSDENIED)
  1383. rc = VSS_STORAGE_CREATE_RC_ACCESS_DENIED;
  1384. else if (hr == E_INVALIDARG)
  1385. rc = VSS_STORAGE_CREATE_RC_INVALID_ARG;
  1386. else if (hr == VSS_E_OBJECT_NOT_FOUND)
  1387. rc = VSS_STORAGE_CREATE_RC_VOLUME_NOT_FOUND;
  1388. else if (hr == VSS_E_VOLUME_NOT_SUPPORTED)
  1389. rc = VSS_STORAGE_CREATE_RC_VOLUME_NOT_SUPPORTED;
  1390. else if (hr == VSS_E_OBJECT_ALREADY_EXISTS)
  1391. rc = VSS_STORAGE_CREATE_RC_OBJECT_ALREADY_EXISTS;
  1392. else if (hr == VSS_E_MAXIMUM_DIFFAREA_ASSOCIATIONS_REACHED)
  1393. rc = VSS_STORAGE_CREATE_RC_MAXIMUM_NUMBER_OF_DIFFAREA_REACHED;
  1394. else if (hr == VSS_E_PROVIDER_VETO)
  1395. rc = VSS_STORAGE_CREATE_RC_PROVIDER_VETO;
  1396. else if (hr == VSS_E_PROVIDER_NOT_REGISTERED)
  1397. rc = VSS_STORAGE_CREATE_RC_PROVIDER_NOT_REGISTERED;
  1398. else if (hr == VSS_E_UNEXPECTED_PROVIDER_ERROR)
  1399. rc = VSS_STORAGE_CREATE_RC_UNEXPECTED_PROVIDER_FAILURE;
  1400. else if (hr == E_UNEXPECTED)
  1401. rc = VSS_STORAGE_CREATE_RC_UNEXPECTED;
  1402. else
  1403. rc = VSS_STORAGE_CREATE_RC_UNEXPECTED;
  1404. }
  1405. void
  1406. CStorage::LoadInstance(
  1407. IN VSS_DIFF_AREA_PROP* pProp,
  1408. IN OUT IWbemClassObject* pObject
  1409. )
  1410. {
  1411. CWbemClassObject wcoInstance(pObject);
  1412. CObjPath pathVolume;
  1413. CObjPath pathDiffVolume;
  1414. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::LoadInstance");
  1415. // Set the Volume Ref property
  1416. if (!pathVolume.Init(PVDR_CLASS_VOLUME))
  1417. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"Storage::LoadInstance: Volume object path initialization failed, hr<%#x>", E_UNEXPECTED);
  1418. if (!pathVolume.AddProperty(PVDR_PROP_DEVICEID, pProp->m_pwszVolumeName))
  1419. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"Storage::LoadInstance: unable to add DeviceID property to object path");
  1420. wcoInstance.SetProperty((wchar_t*)pathVolume.GetObjectPathString(), PVDR_PROP_VOLUME);
  1421. // Set the DiffVolume Ref property
  1422. if (!pathDiffVolume.Init(PVDR_CLASS_VOLUME))
  1423. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"Storage::LoadInstance: DiffVolume object path initialization failed, hr<%#x>", E_UNEXPECTED);
  1424. if (!pathDiffVolume.AddProperty(PVDR_PROP_DEVICEID, pProp->m_pwszDiffAreaVolumeName))
  1425. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"Storage::LoadInstance: unable to add DeviceID property to object path");
  1426. wcoInstance.SetProperty((wchar_t*)pathDiffVolume.GetObjectPathString(), PVDR_PROP_DIFFVOLUME);
  1427. // Set the MaxSpace property
  1428. wcoInstance.SetPropertyI64((ULONGLONG)pProp->m_llMaximumDiffSpace, PVDR_PROP_MAXSPACE);
  1429. // Set the AllocatedSpace property
  1430. wcoInstance.SetPropertyI64((ULONGLONG)pProp->m_llAllocatedDiffSpace, PVDR_PROP_ALLOCATEDSPACE);
  1431. // Set the UsedSpace property
  1432. wcoInstance.SetPropertyI64((ULONGLONG)pProp->m_llUsedDiffSpace, PVDR_PROP_USEDSPACE);
  1433. }
  1434. HRESULT
  1435. CStorage::DeleteInstance(
  1436. IN CObjPath& rObjPath,
  1437. IN long lFlag,
  1438. IN IWbemContext* pCtx,
  1439. IN IWbemObjectSink* pHandler
  1440. )
  1441. {
  1442. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::DeleteInstance");
  1443. try
  1444. {
  1445. CComPtr<IVssSnapshotMgmt> spMgmt;
  1446. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  1447. _bstr_t bstrVolumeRef, bstrVolumeName;
  1448. _bstr_t bstrDiffVolumeRef, bstrDiffVolumeName;
  1449. CObjPath objPathVolume;
  1450. CObjPath objPathDiffVolume;
  1451. VSS_ID idProvider = GUID_NULL;
  1452. BOOL fSupported = false;
  1453. // Get the Volume reference
  1454. bstrVolumeRef = rObjPath.GetStringValueForProperty(PVDR_PROP_VOLUME);
  1455. IF_WSTR_NULL_THROW(bstrVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"Storage::DeleteInstance: storage volume key property not found");
  1456. // Get the DiffVolume reference
  1457. bstrDiffVolumeRef = rObjPath.GetStringValueForProperty(PVDR_PROP_DIFFVOLUME);
  1458. IF_WSTR_NULL_THROW(bstrDiffVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"Storage::DeleteInstance: storage diff volume key property not found");
  1459. // Extract the Volume and DiffVolume Names
  1460. if (!objPathVolume.Init(bstrVolumeRef))
  1461. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"Storage::DeleteInstance: Volume object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1462. if (!objPathDiffVolume.Init(bstrDiffVolumeRef))
  1463. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"Storage::DeleteInstance: DiffVolume object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1464. bstrVolumeName = objPathVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  1465. IF_WSTR_NULL_THROW(bstrVolumeName, WBEM_E_INVALID_OBJECT_PATH, L"Storage::DeleteInstance: storage volume key DeviceID property not found");
  1466. bstrDiffVolumeName = objPathDiffVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  1467. IF_WSTR_NULL_THROW(bstrDiffVolumeName, WBEM_E_INVALID_OBJECT_PATH, L"Storage::DeleteInstance: storage diff volume key DeviceID property not found");
  1468. SelectDiffAreaProvider(&idProvider);
  1469. // Find the provider that supports the Volume
  1470. ft.hr = m_spCoord->IsVolumeSupported(idProvider, bstrVolumeName, &fSupported);
  1471. if (ft.HrFailed())
  1472. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"IsVolumeSupported failed, hr<%#x>", ft.hr);
  1473. if (!fSupported)
  1474. {
  1475. ft.hr = WBEM_E_NOT_FOUND;
  1476. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Volume not supported by selected provider");
  1477. }
  1478. // Create snapshot mgmt object
  1479. ft.CoCreateInstanceWithLog(
  1480. VSSDBG_VSSADMIN,
  1481. CLSID_VssSnapshotMgmt,
  1482. L"VssSnapshotMgmt",
  1483. CLSCTX_ALL,
  1484. IID_IVssSnapshotMgmt,
  1485. (IUnknown**)&(spMgmt));
  1486. if (ft.HrFailed())
  1487. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  1488. // Get the Mgmt object for the Provider
  1489. ft.hr = spMgmt->GetProviderMgmtInterface(
  1490. idProvider,
  1491. IID_IVssDifferentialSoftwareSnapshotMgmt,
  1492. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  1493. if (ft.HrFailed())
  1494. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1495. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  1496. // Change the max storage space to the
  1497. // 'magic number' reserved for deletion.
  1498. ft.hr = spDiffMgmt->ChangeDiffAreaMaximumSize(
  1499. bstrVolumeName,
  1500. bstrDiffVolumeName,
  1501. VSS_ASSOC_REMOVE);
  1502. }
  1503. catch (HRESULT hrEx)
  1504. {
  1505. ft.hr = hrEx;
  1506. }
  1507. return ft.hr;
  1508. } //*** CStorage::DeleteInstance()
  1509. //
  1510. // SelectDiffAreaProvider
  1511. //
  1512. // Returns the first 3rd party provider found
  1513. // Otherwise it returns the Microsoft Diff Area Provider.
  1514. //
  1515. void
  1516. CStorage::SelectDiffAreaProvider(
  1517. OUT GUID* pProviderID
  1518. )
  1519. {
  1520. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CStorage::SelectProviderForStorage");
  1521. CComPtr<IVssEnumObject> spEnumProvider;
  1522. CComPtr<IVssSnapshotMgmt> spMgmt;
  1523. // Set the default provider
  1524. *pProviderID = VSS_SWPRV_ProviderId;
  1525. // Create snapshot mgmt object
  1526. ft.CoCreateInstanceWithLog(
  1527. VSSDBG_VSSADMIN,
  1528. CLSID_VssSnapshotMgmt,
  1529. L"VssSnapshotMgmt",
  1530. CLSCTX_ALL,
  1531. IID_IVssSnapshotMgmt,
  1532. (IUnknown**)&(spMgmt));
  1533. if (ft.HrFailed())
  1534. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  1535. ft.hr = m_spCoord->Query(
  1536. GUID_NULL,
  1537. VSS_OBJECT_NONE,
  1538. VSS_OBJECT_PROVIDER,
  1539. &spEnumProvider);
  1540. if (ft.HrFailed())
  1541. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Query for Providers failed hr<%#x>", ft.hr);
  1542. while (1)
  1543. {
  1544. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  1545. VSS_OBJECT_PROP prop;
  1546. VSS_PROVIDER_PROP& propProv = prop.Obj.Prov;
  1547. ULONG ulFetch = 0;
  1548. ft.hr = spEnumProvider->Next(1, &prop, &ulFetch);
  1549. if (ft.HrFailed())
  1550. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  1551. if (ft.hr == S_FALSE)
  1552. break;
  1553. CVssAutoPWSZ awszProviderName(propProv.m_pwszProviderName);
  1554. CVssAutoPWSZ awszProviderVersion(propProv.m_pwszProviderVersion);
  1555. if (propProv.m_ProviderId != VSS_SWPRV_ProviderId)
  1556. {
  1557. ft.hr = spMgmt->GetProviderMgmtInterface(
  1558. propProv.m_ProviderId,
  1559. IID_IVssDifferentialSoftwareSnapshotMgmt,
  1560. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  1561. if (ft.hr == E_NOINTERFACE)
  1562. continue; // Inteface not supported, check next provider
  1563. if (ft.HrFailed())
  1564. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1565. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  1566. *pProviderID = propProv.m_ProviderId;
  1567. break;
  1568. }
  1569. }
  1570. return;
  1571. }
  1572. //****************************************************************************
  1573. //
  1574. // CShadowFor
  1575. //
  1576. //****************************************************************************
  1577. CShadowFor::CShadowFor(
  1578. IN LPCWSTR pwszName,
  1579. IN CWbemServices* pNamespace
  1580. )
  1581. : CProvBase(pwszName, pNamespace)
  1582. {
  1583. } //*** CShadowFor::CShadowFor()
  1584. CProvBase *
  1585. CShadowFor::S_CreateThis(
  1586. IN LPCWSTR pwszName,
  1587. IN CWbemServices* pNamespace
  1588. )
  1589. {
  1590. HRESULT hr = WBEM_E_FAILED;
  1591. CShadowFor * pShadowFor = NULL;
  1592. pShadowFor = new CShadowFor(pwszName, pNamespace);
  1593. if (pShadowFor)
  1594. {
  1595. hr = pShadowFor->Initialize();
  1596. }
  1597. else
  1598. {
  1599. hr = E_OUTOFMEMORY;
  1600. }
  1601. if (FAILED(hr))
  1602. {
  1603. delete pShadowFor;
  1604. pShadowFor = NULL;
  1605. }
  1606. return pShadowFor;
  1607. } //*** CShadowFor::S_CreateThis()
  1608. HRESULT
  1609. CShadowFor::EnumInstance(
  1610. long lFlags,
  1611. IWbemContext* pCtx,
  1612. IWbemObjectSink* pHandler
  1613. )
  1614. {
  1615. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowFor::EnumInstance");
  1616. try
  1617. {
  1618. CComPtr<IVssEnumObject> spEnumShadow;
  1619. ft.hr = m_spCoord->SetContext(VSS_CTX_ALL);
  1620. if (ft.HrFailed())
  1621. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1622. L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  1623. ft.hr = m_spCoord->Query(
  1624. GUID_NULL,
  1625. VSS_OBJECT_NONE,
  1626. VSS_OBJECT_SNAPSHOT,
  1627. &spEnumShadow);
  1628. if (ft.HrFailed())
  1629. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1630. L"IVssCoordinator::Query failed, hr<%#x>", ft.hr);
  1631. while (ft.HrSucceeded() && ft.hr != S_FALSE)
  1632. {
  1633. CComPtr<IWbemClassObject> spInstance;
  1634. VSS_OBJECT_PROP prop;
  1635. ULONG ulFetch = 0;
  1636. ft.hr = spEnumShadow->Next(1, &prop, &ulFetch);
  1637. if (ft.HrFailed())
  1638. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  1639. if (ft.hr == S_FALSE)
  1640. {
  1641. ft.hr = S_OK;
  1642. break; // All done
  1643. }
  1644. CVssAutoSnapshotProperties apropSnap(prop);
  1645. // Spawn an instance of the class
  1646. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  1647. if (ft.HrFailed())
  1648. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  1649. LoadInstance(apropSnap.GetPtr(), spInstance.p);
  1650. ft.hr = pHandler->Indicate(1, &spInstance.p);
  1651. }
  1652. }
  1653. catch (HRESULT hrEx)
  1654. {
  1655. ft.hr = hrEx;
  1656. }
  1657. return ft.hr;
  1658. } //*** CShadowFor::EnumInstance()
  1659. HRESULT
  1660. CShadowFor::GetObject(
  1661. IN CObjPath& rObjPath,
  1662. IN long lFlags,
  1663. IN IWbemContext* pCtx,
  1664. IN IWbemObjectSink* pHandler
  1665. )
  1666. {
  1667. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowFor::GetObject");
  1668. try
  1669. {
  1670. CComPtr<IWbemClassObject> spInstance;
  1671. _bstr_t bstrVolumeRef, bstrVolumeID;
  1672. _bstr_t bstrShadowRef, bstrShadowID;
  1673. CObjPath objPathVolume;
  1674. CObjPath objPathShadow;
  1675. VSS_SNAPSHOT_PROP propSnap;
  1676. // Get the Volume reference
  1677. bstrVolumeRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_ANTECEDENT);
  1678. IF_WSTR_NULL_THROW(bstrVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"ShadowFor volume key property not found");
  1679. // Get the Shadow reference
  1680. bstrShadowRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_DEPENDENT);
  1681. IF_WSTR_NULL_THROW(bstrShadowRef, WBEM_E_INVALID_OBJECT_PATH, L"ShadowFor shadow key property not found");
  1682. // Extract the Volume and Shadow IDs
  1683. if (!objPathVolume.Init(bstrVolumeRef))
  1684. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"ShadowFor::GetObject: Volume object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1685. if (!objPathShadow.Init(bstrShadowRef))
  1686. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"ShadowFor::GetObject: Shadow object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1687. bstrVolumeID = objPathVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  1688. IF_WSTR_NULL_THROW(bstrVolumeID, WBEM_E_INVALID_OBJECT_PATH, L"ShadowFor volume key property DeviceID not found");
  1689. bstrShadowID = objPathShadow.GetStringValueForProperty(PVDR_PROP_ID);
  1690. IF_WSTR_NULL_THROW(bstrShadowID, WBEM_E_INVALID_OBJECT_PATH, L"ShadowFor shadow key property ID not found");
  1691. ft.hr = GetShadowPropertyStruct(m_spCoord, bstrShadowID, &propSnap);
  1692. if (ft.HrFailed())
  1693. {
  1694. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1695. L"GetShadowPropertyStruct failed for shadow copy %lS, hr<%#x>", (WCHAR*)bstrShadowID, ft.hr);
  1696. }
  1697. CVssAutoSnapshotProperties apropSnap(propSnap);
  1698. // Verify the referenced Volume ID is the same as in the shadow properties
  1699. if (_wcsicmp(bstrVolumeID, propSnap.m_pwszOriginalVolumeName) != 0)
  1700. {
  1701. ft.hr = WBEM_E_NOT_FOUND;
  1702. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Referenced volume ID does not match shadow original volume");
  1703. }
  1704. // Spawn an instance of the class
  1705. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  1706. if (ft.HrFailed())
  1707. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  1708. LoadInstance(apropSnap.GetPtr(), spInstance.p);
  1709. ft.hr = pHandler->Indicate(1, &spInstance.p);
  1710. }
  1711. catch (HRESULT hrEx)
  1712. {
  1713. ft.hr = hrEx;
  1714. }
  1715. return ft.hr;
  1716. }
  1717. void
  1718. CShadowFor::LoadInstance(
  1719. IN VSS_SNAPSHOT_PROP* pProp,
  1720. IN OUT IWbemClassObject* pObject
  1721. )
  1722. {
  1723. CWbemClassObject wcoInstance(pObject);
  1724. CObjPath pathShadow;
  1725. CObjPath pathVolume;
  1726. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowFor::LoadInstance");
  1727. // Set the Shadow Ref property
  1728. CVssAutoPWSZ awszGUID(GuidToString(pProp->m_SnapshotId)); // Auto-delete string
  1729. if (!pathShadow.Init(PVDR_CLASS_SHADOW))
  1730. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowFor::LoadInstance: Shadow object path initialization failed, hr<%#x>", E_UNEXPECTED);
  1731. if (!pathShadow.AddProperty(PVDR_PROP_ID, awszGUID))
  1732. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowFor::LoadInstance: unable to add ID property to object path");
  1733. wcoInstance.SetProperty((wchar_t*)pathShadow.GetObjectPathString(), PVD_WBEM_PROP_DEPENDENT);
  1734. // Set the Volume Ref property
  1735. if (!pathVolume.Init(PVDR_CLASS_VOLUME))
  1736. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowFor::LoadInstance: Volume object path initialization failed, hr<%#x>", E_UNEXPECTED);
  1737. if (!pathVolume.AddProperty(PVDR_PROP_DEVICEID, pProp->m_pwszOriginalVolumeName))
  1738. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowFor::LoadInstance: unable to add DeviceID property to object path");
  1739. wcoInstance.SetProperty((wchar_t*)pathVolume.GetObjectPathString(), PVD_WBEM_PROP_ANTECEDENT);
  1740. }
  1741. //****************************************************************************
  1742. //
  1743. // CShadowBy
  1744. //
  1745. //****************************************************************************
  1746. CShadowBy::CShadowBy(
  1747. IN LPCWSTR pwszName,
  1748. IN CWbemServices* pNamespace
  1749. )
  1750. : CProvBase(pwszName, pNamespace)
  1751. {
  1752. } //*** CShadowBy::CShadowBy()
  1753. CProvBase *
  1754. CShadowBy::S_CreateThis(
  1755. IN LPCWSTR pwszName,
  1756. IN CWbemServices* pNamespace
  1757. )
  1758. {
  1759. HRESULT hr = WBEM_E_FAILED;
  1760. CShadowBy* pShadowBy = NULL;
  1761. pShadowBy = new CShadowBy(pwszName, pNamespace);
  1762. if ( pShadowBy )
  1763. {
  1764. hr = pShadowBy->Initialize();
  1765. }
  1766. else
  1767. {
  1768. hr = E_OUTOFMEMORY;
  1769. }
  1770. if (FAILED(hr))
  1771. {
  1772. delete pShadowBy;
  1773. pShadowBy = NULL;
  1774. }
  1775. return pShadowBy;
  1776. } //*** CShadowBy::S_CreateThis()
  1777. HRESULT
  1778. CShadowBy::EnumInstance(
  1779. IN long lFlags,
  1780. IN IWbemContext* pCtx,
  1781. IN IWbemObjectSink* pHandler
  1782. )
  1783. {
  1784. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowBy::EnumInstance");
  1785. try
  1786. {
  1787. CComPtr<IVssEnumObject> spEnumShadow;
  1788. ft.hr = m_spCoord->SetContext(VSS_CTX_ALL);
  1789. if (ft.HrFailed())
  1790. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1791. L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  1792. ft.hr = m_spCoord->Query(
  1793. GUID_NULL,
  1794. VSS_OBJECT_NONE,
  1795. VSS_OBJECT_SNAPSHOT,
  1796. &spEnumShadow);
  1797. if (ft.HrFailed())
  1798. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1799. L"IVssCoordinator::Query failed, hr<%#x>", ft.hr);
  1800. while (ft.HrSucceeded() && ft.hr != S_FALSE)
  1801. {
  1802. CComPtr<IWbemClassObject> spInstance;
  1803. VSS_OBJECT_PROP prop;
  1804. ULONG ulFetch = 0;
  1805. ft.hr = spEnumShadow->Next(1, &prop, &ulFetch);
  1806. if (ft.HrFailed())
  1807. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  1808. if (ft.hr == S_FALSE)
  1809. {
  1810. ft.hr = S_OK;
  1811. break; // All done
  1812. }
  1813. CVssAutoSnapshotProperties apropSnap(prop);
  1814. // Spawn an instance of the class
  1815. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  1816. if (ft.HrFailed())
  1817. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  1818. LoadInstance(apropSnap.GetPtr(), spInstance.p);
  1819. ft.hr = pHandler->Indicate(1, &spInstance.p);
  1820. }
  1821. }
  1822. catch (HRESULT hrEx)
  1823. {
  1824. ft.hr = hrEx;
  1825. }
  1826. return ft.hr;
  1827. } //*** CShadowBy::EnumInstance()
  1828. HRESULT
  1829. CShadowBy::GetObject(
  1830. IN CObjPath& rObjPath,
  1831. IN long lFlags,
  1832. IN IWbemContext* pCtx,
  1833. IN IWbemObjectSink* pHandler
  1834. )
  1835. {
  1836. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowBy::GetObject");
  1837. try
  1838. {
  1839. CComPtr<IWbemClassObject> spInstance;
  1840. _bstr_t bstrProviderRef, bstrProviderID;
  1841. _bstr_t bstrShadowRef, bstrShadowID;
  1842. CObjPath objPathProvider;
  1843. CObjPath objPathShadow;
  1844. VSS_SNAPSHOT_PROP propSnap;
  1845. // Get the Provider reference
  1846. bstrProviderRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_ANTECEDENT);
  1847. IF_WSTR_NULL_THROW(bstrProviderRef, WBEM_E_INVALID_OBJECT_PATH, L"ShadowBy provider key property not found");
  1848. // Get the Shadow reference
  1849. bstrShadowRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_DEPENDENT);
  1850. IF_WSTR_NULL_THROW(bstrShadowRef, WBEM_E_INVALID_OBJECT_PATH, L"ShadowBy shadow key property not found");
  1851. // Extract the Volume and Shadow IDs
  1852. if (!objPathProvider.Init(bstrProviderRef))
  1853. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"ShadowBy::GetObject: Provider object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1854. if (!objPathShadow.Init(bstrShadowRef))
  1855. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"ShadowBy::GetObject: Shadow object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  1856. bstrProviderID = objPathProvider.GetStringValueForProperty(PVDR_PROP_ID);
  1857. IF_WSTR_NULL_THROW(bstrProviderID, WBEM_E_INVALID_OBJECT_PATH, L"ShadowBy provider key property ID not found");
  1858. bstrShadowID = objPathShadow.GetStringValueForProperty(PVDR_PROP_ID);
  1859. IF_WSTR_NULL_THROW(bstrShadowID, WBEM_E_INVALID_OBJECT_PATH, L"ShadowBy shadow key property ID not found");
  1860. ft.hr = GetShadowPropertyStruct(m_spCoord, bstrShadowID, &propSnap);
  1861. if (ft.HrFailed())
  1862. {
  1863. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1864. L"GetShadowPropertyStruct failed for shadow copy %lS, hr<%#x>", (WCHAR*)bstrShadowID, ft.hr);
  1865. }
  1866. CVssAutoSnapshotProperties apropSnap(propSnap);
  1867. // Verify the referenced Volume ID is the same as in the shadow properties
  1868. if (!StringGuidIsGuid(bstrProviderID, propSnap.m_ProviderId))
  1869. {
  1870. ft.hr = WBEM_E_NOT_FOUND;
  1871. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Referenced provider ID does not match shadow provider id");
  1872. }
  1873. // Spawn an instance of the class
  1874. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  1875. if (ft.HrFailed())
  1876. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  1877. LoadInstance(apropSnap.GetPtr(), spInstance.p);
  1878. ft.hr = pHandler->Indicate(1, &spInstance.p);
  1879. }
  1880. catch (HRESULT hrEx)
  1881. {
  1882. ft.hr = hrEx;
  1883. }
  1884. return ft.hr;
  1885. }
  1886. void
  1887. CShadowBy::LoadInstance(
  1888. IN VSS_SNAPSHOT_PROP* pProp,
  1889. IN OUT IWbemClassObject* pObject
  1890. )
  1891. {
  1892. CWbemClassObject wcoInstance(pObject);
  1893. CObjPath pathShadow;
  1894. CObjPath pathProvider;
  1895. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowBy::LoadInstance");
  1896. // Set the Shadow Ref property
  1897. CVssAutoPWSZ awszGUID(GuidToString(pProp->m_SnapshotId)); // Auto-delete string
  1898. if (!pathShadow.Init(PVDR_CLASS_SHADOW))
  1899. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowBy::LoadInstance: Shadow object path initialization failed, hr<%#x>", E_UNEXPECTED);
  1900. if (!pathShadow.AddProperty(PVDR_PROP_ID, awszGUID))
  1901. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowBy::LoadInstance: unable to add ID property to object path");
  1902. wcoInstance.SetProperty((wchar_t*)pathShadow.GetObjectPathString(), PVD_WBEM_PROP_DEPENDENT);
  1903. // Set the Provider Ref property
  1904. awszGUID.Attach(GuidToString(pProp->m_ProviderId));
  1905. if (!pathProvider.Init(PVDR_CLASS_PROVIDER))
  1906. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowBy::LoadInstance: Provider object path initialization failed, hr<%#x>", E_UNEXPECTED);
  1907. if (!pathProvider.AddProperty(PVDR_PROP_ID, awszGUID))
  1908. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"ShadowBy::LoadInstance: unable to add ID property to object path");
  1909. wcoInstance.SetProperty((wchar_t*)pathProvider.GetObjectPathString(), PVD_WBEM_PROP_ANTECEDENT);
  1910. }
  1911. //****************************************************************************
  1912. //
  1913. // CShadowOn
  1914. //
  1915. //****************************************************************************
  1916. CShadowOn::CShadowOn(
  1917. IN LPCWSTR pwszName,
  1918. IN CWbemServices* pNamespace
  1919. )
  1920. : CProvBase(pwszName, pNamespace)
  1921. {
  1922. } //*** CShadowOn::CShadowOn()
  1923. CProvBase *
  1924. CShadowOn::S_CreateThis(
  1925. IN LPCWSTR pwszName,
  1926. IN CWbemServices* pNamespace
  1927. )
  1928. {
  1929. HRESULT hr = WBEM_E_FAILED;
  1930. CShadowOn * pShadowOn = NULL;
  1931. pShadowOn = new CShadowOn(pwszName, pNamespace);
  1932. if (pShadowOn)
  1933. {
  1934. hr = pShadowOn->Initialize();
  1935. }
  1936. else
  1937. {
  1938. hr = E_OUTOFMEMORY;
  1939. }
  1940. if (FAILED(hr))
  1941. {
  1942. delete pShadowOn;
  1943. pShadowOn = NULL;
  1944. }
  1945. return pShadowOn;
  1946. } //*** CShadowOn::S_CreateThis()
  1947. HRESULT
  1948. CShadowOn::EnumInstance(
  1949. IN long lFlagsIn,
  1950. IN IWbemContext* pCtx,
  1951. IN IWbemObjectSink* pHandler
  1952. )
  1953. {
  1954. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowOn::EnumInstance");
  1955. try
  1956. {
  1957. CComPtr<IVssEnumObject> spEnumShadow;
  1958. CComPtr<IVssSnapshotMgmt> spMgmt;
  1959. ft.CoCreateInstanceWithLog(
  1960. VSSDBG_VSSADMIN,
  1961. CLSID_VssSnapshotMgmt,
  1962. L"VssSnapshotMgmt",
  1963. CLSCTX_ALL,
  1964. IID_IVssSnapshotMgmt,
  1965. (IUnknown**)&(spMgmt));
  1966. if (ft.HrFailed())
  1967. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  1968. ft.hr = m_spCoord->SetContext(VSS_CTX_ALL);
  1969. if (ft.HrFailed())
  1970. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1971. L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  1972. ft.hr = m_spCoord->Query(
  1973. GUID_NULL,
  1974. VSS_OBJECT_NONE,
  1975. VSS_OBJECT_SNAPSHOT,
  1976. &spEnumShadow);
  1977. if (ft.HrFailed())
  1978. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  1979. L"IVssCoordinator::Query failed, hr<%#x>", ft.hr);
  1980. while (ft.HrSucceeded() && ft.hr != S_FALSE)
  1981. {
  1982. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  1983. CComPtr<IVssEnumMgmtObject> spEnumDiffArea;
  1984. VSS_OBJECT_PROP propObj;
  1985. ULONG ulFetch = 0;
  1986. ft.hr = spEnumShadow->Next(1, &propObj, &ulFetch);
  1987. if (ft.HrFailed())
  1988. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  1989. if (ft.hr == S_FALSE)
  1990. {
  1991. ft.hr = S_OK;
  1992. break; // All done
  1993. }
  1994. CVssAutoSnapshotProperties apropSnap(propObj);
  1995. // Does the provider support diff areas?
  1996. ft.hr = spMgmt->GetProviderMgmtInterface(
  1997. apropSnap->m_ProviderId,
  1998. IID_IVssDifferentialSoftwareSnapshotMgmt,
  1999. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  2000. if (ft.hr == E_NOINTERFACE)
  2001. {
  2002. ft.hr = S_OK;
  2003. continue; // Diff areas not supported; try next shadow
  2004. }
  2005. if (ft.HrFailed())
  2006. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2007. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  2008. // Diff areas supported, continue
  2009. ft.hr = spDiffMgmt->QueryDiffAreasForSnapshot(
  2010. apropSnap->m_SnapshotId,
  2011. &spEnumDiffArea);
  2012. if (ft.HrFailed())
  2013. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2014. L"QueryDiffAreasForSnapshot failed, hr<%#x>", ft.hr);
  2015. // Theoretically possible for a single snapshot to be on multiple diff areas
  2016. while (1)
  2017. {
  2018. CComPtr<IWbemClassObject> spInstance;
  2019. VSS_MGMT_OBJECT_PROP propMgmt;
  2020. VSS_DIFF_AREA_PROP& propDiffArea = propMgmt.Obj.DiffArea;
  2021. ulFetch = 0;
  2022. ft.hr = spEnumDiffArea->Next(1, &propMgmt, &ulFetch);
  2023. if (ft.HrFailed())
  2024. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  2025. if (ft.hr == S_FALSE)
  2026. {
  2027. ft.hr = S_OK;
  2028. break; // No more diff areas
  2029. }
  2030. CVssAutoPWSZ awszVolumeName(propDiffArea.m_pwszVolumeName);
  2031. CVssAutoPWSZ awszDiffAreaVolumeName(propDiffArea.m_pwszDiffAreaVolumeName);
  2032. // Spawn an instance of the class
  2033. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  2034. if (ft.HrFailed())
  2035. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  2036. LoadInstance(apropSnap.GetPtr(), &propDiffArea, spInstance.p);
  2037. ft.hr = pHandler->Indicate(1, &spInstance.p);
  2038. }
  2039. }
  2040. }
  2041. catch (HRESULT hrEx)
  2042. {
  2043. ft.hr = hrEx;
  2044. }
  2045. return ft.hr;
  2046. } //*** CShadowOn::EnumInstance()
  2047. HRESULT
  2048. CShadowOn::GetObject(
  2049. IN CObjPath& rObjPath,
  2050. IN long lFlags,
  2051. IN IWbemContext* pCtx,
  2052. IN IWbemObjectSink* pHandler
  2053. )
  2054. {
  2055. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowOn::GetObject");
  2056. try
  2057. {
  2058. CComPtr<IVssSnapshotMgmt> spMgmt;
  2059. CComPtr<IVssEnumMgmtObject> spEnumDiffArea;
  2060. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  2061. _bstr_t bstrVolumeRef, bstrVolumeID;
  2062. _bstr_t bstrShadowRef, bstrShadowID;
  2063. CObjPath objPathVolume;
  2064. CObjPath objPathShadow;
  2065. VSS_SNAPSHOT_PROP propSnap;
  2066. // Get the Provider reference
  2067. bstrVolumeRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_ANTECEDENT);
  2068. IF_WSTR_NULL_THROW(bstrVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"ShadowOn volume key property not found");
  2069. // Get the Shadow reference
  2070. bstrShadowRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_DEPENDENT);
  2071. IF_WSTR_NULL_THROW(bstrShadowRef, WBEM_E_INVALID_OBJECT_PATH, L"ShadowOn shadow key property not found");
  2072. // Extract the Volume and Shadow IDs
  2073. if (!objPathVolume.Init(bstrVolumeRef))
  2074. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"ShadowOn::GetObject: Volume object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  2075. if (!objPathShadow.Init(bstrShadowRef))
  2076. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"ShadowOn::GetObject: Shadow object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  2077. bstrVolumeID = objPathVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  2078. IF_WSTR_NULL_THROW(bstrVolumeID, WBEM_E_INVALID_OBJECT_PATH, L"ShadowOn volume key property DeviceID not found");
  2079. bstrShadowID = objPathShadow.GetStringValueForProperty(PVDR_PROP_ID);
  2080. IF_WSTR_NULL_THROW(bstrShadowID, WBEM_E_INVALID_OBJECT_PATH, L"ShadowOn shadow key property ID not found");
  2081. ft.hr = GetShadowPropertyStruct(m_spCoord, bstrShadowID, &propSnap);
  2082. if (ft.HrFailed())
  2083. {
  2084. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2085. L"GetShadowPropertyStruct failed for shadow copy %lS, hr<%#x>", (WCHAR*)bstrShadowID, ft.hr);
  2086. }
  2087. CVssAutoSnapshotProperties apropSnap(propSnap);
  2088. ft.CoCreateInstanceWithLog(
  2089. VSSDBG_VSSADMIN,
  2090. CLSID_VssSnapshotMgmt,
  2091. L"VssSnapshotMgmt",
  2092. CLSCTX_ALL,
  2093. IID_IVssSnapshotMgmt,
  2094. (IUnknown**)&(spMgmt));
  2095. if (ft.HrFailed())
  2096. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  2097. // Does the provider support diff areas?
  2098. ft.hr = spMgmt->GetProviderMgmtInterface(
  2099. apropSnap->m_ProviderId,
  2100. IID_IVssDifferentialSoftwareSnapshotMgmt,
  2101. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  2102. if (ft.hr == E_NOINTERFACE)
  2103. {
  2104. ft.hr = WBEM_E_NOT_FOUND;
  2105. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"shadow copy %lS was not created by a differential provider", (WCHAR*)bstrShadowID);
  2106. }
  2107. if (ft.HrFailed())
  2108. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2109. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  2110. // Diff areas supported, continue
  2111. ft.hr = spDiffMgmt->QueryDiffAreasForSnapshot(
  2112. apropSnap->m_SnapshotId,
  2113. &spEnumDiffArea);
  2114. if (ft.HrFailed())
  2115. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2116. L"QueryDiffAreasForSnapshot failed, hr<%#x>", ft.hr);
  2117. // Theoretically possible for a single snapshot to be on multiple diff areas
  2118. while (ft.hr != FALSE)
  2119. {
  2120. CComPtr<IWbemClassObject> spInstance;
  2121. VSS_MGMT_OBJECT_PROP propMgmt;
  2122. VSS_DIFF_AREA_PROP& propDiffArea = propMgmt.Obj.DiffArea;
  2123. ULONG ulFetch = 0;
  2124. ft.hr = spEnumDiffArea->Next(1, &propMgmt, &ulFetch);
  2125. if (ft.HrFailed())
  2126. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  2127. if (ft.hr == S_FALSE)
  2128. {
  2129. break; // No more diff areas; diff area not found
  2130. }
  2131. CVssAutoPWSZ awszVolumeName(propDiffArea.m_pwszVolumeName);
  2132. CVssAutoPWSZ awszDiffAreaVolumeName(propDiffArea.m_pwszDiffAreaVolumeName);
  2133. // Look for the difference area that is stored ON the referenced volume
  2134. if (_wcsicmp(awszDiffAreaVolumeName, bstrVolumeID) == 0)
  2135. {
  2136. CComPtr<IWbemClassObject> spInstance;
  2137. // Spawn an instance of the class
  2138. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  2139. if (ft.HrFailed())
  2140. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  2141. LoadInstance(apropSnap.GetPtr(), &propDiffArea, spInstance.p);
  2142. ft.hr = pHandler->Indicate(1, &spInstance.p);
  2143. break;
  2144. }
  2145. }
  2146. if (ft.hr == S_FALSE)
  2147. {
  2148. ft.hr = WBEM_E_NOT_FOUND;
  2149. }
  2150. }
  2151. catch (HRESULT hrEx)
  2152. {
  2153. ft.hr = hrEx;
  2154. }
  2155. return ft.hr;
  2156. }
  2157. void
  2158. CShadowOn::LoadInstance(
  2159. IN VSS_SNAPSHOT_PROP* pPropSnap,
  2160. IN VSS_DIFF_AREA_PROP* pPropDiff,
  2161. IN OUT IWbemClassObject* pObject
  2162. )
  2163. {
  2164. CWbemClassObject wcoInstance(pObject);
  2165. CObjPath pathShadow;
  2166. CObjPath pathVolume;
  2167. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CShadowOn::LoadInstance");
  2168. // Set the Shadow Ref property
  2169. CVssAutoPWSZ awszGUID(GuidToString(pPropSnap->m_SnapshotId)); // Auto-delete string
  2170. if (!pathShadow.Init(PVDR_CLASS_SHADOW))
  2171. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"CShadowOn::LoadInstance: Shadow object path initialization failed, hr<%#x>", E_UNEXPECTED);
  2172. if (!pathShadow.AddProperty(PVDR_PROP_ID, awszGUID))
  2173. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"CShadowOn::LoadInstance: unable to add ID property to object path");
  2174. wcoInstance.SetProperty((wchar_t*)pathShadow.GetObjectPathString(), PVD_WBEM_PROP_DEPENDENT);
  2175. // Set the DiffVolume Ref property
  2176. if (!pathVolume.Init(PVDR_CLASS_VOLUME))
  2177. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"CShadowOn::LoadInstance: DiffVolume object path initialization failed, hr<%#x>", E_UNEXPECTED);
  2178. if (!pathVolume.AddProperty(PVDR_PROP_DEVICEID, pPropDiff->m_pwszDiffAreaVolumeName))
  2179. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"CShadowOn::LoadInstance: unable to add DeviceID property to object path");
  2180. wcoInstance.SetProperty((wchar_t*)pathVolume.GetObjectPathString(), PVD_WBEM_PROP_ANTECEDENT);
  2181. }
  2182. //****************************************************************************
  2183. //
  2184. // CVolumeSupport
  2185. //
  2186. //****************************************************************************
  2187. CVolumeSupport::CVolumeSupport(
  2188. IN LPCWSTR pwszName,
  2189. IN CWbemServices* pNamespace
  2190. )
  2191. : CProvBase(pwszName, pNamespace)
  2192. {
  2193. } //*** CVolumeSupport::CVolumeSupport()
  2194. CProvBase *
  2195. CVolumeSupport::S_CreateThis(
  2196. IN PCWSTR pwszName,
  2197. IN CWbemServices* pNamespace
  2198. )
  2199. {
  2200. HRESULT hr = WBEM_E_FAILED;
  2201. CVolumeSupport * pVolumeSupport = NULL;
  2202. pVolumeSupport = new CVolumeSupport(pwszName, pNamespace);
  2203. if (pVolumeSupport)
  2204. {
  2205. hr = pVolumeSupport->Initialize();
  2206. }
  2207. else
  2208. {
  2209. hr = E_OUTOFMEMORY;
  2210. }
  2211. if (FAILED(hr))
  2212. {
  2213. delete pVolumeSupport;
  2214. pVolumeSupport = NULL;
  2215. }
  2216. return pVolumeSupport;
  2217. } //*** CVolumeSupport::S_CreateThis()
  2218. HRESULT
  2219. CVolumeSupport::EnumInstance(
  2220. IN long lFlags,
  2221. IN IWbemContext* pCtx,
  2222. IN IWbemObjectSink* pHandler
  2223. )
  2224. {
  2225. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CVolumeSupport::EnumInstance");
  2226. try
  2227. {
  2228. CComPtr<IVssSnapshotMgmt> spMgmt;
  2229. CGUIDList listProviderID;
  2230. GUID guid;
  2231. // Get the provider IDs
  2232. GetProviderIDList(m_spCoord, &listProviderID);
  2233. // Create snapshot mgmt object
  2234. ft.CoCreateInstanceWithLog(
  2235. VSSDBG_VSSADMIN,
  2236. CLSID_VssSnapshotMgmt,
  2237. L"VssSnapshotMgmt",
  2238. CLSCTX_ALL,
  2239. IID_IVssSnapshotMgmt,
  2240. (IUnknown**)&(spMgmt));
  2241. if (ft.HrFailed())
  2242. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  2243. while (listProviderID.Extract(guid))
  2244. {
  2245. CComPtr<IVssEnumMgmtObject> spEnumMgmt;
  2246. ft.hr = spMgmt->QueryVolumesSupportedForSnapshots(
  2247. guid,
  2248. VSS_CTX_ALL,
  2249. &spEnumMgmt );
  2250. if (ft.HrFailed())
  2251. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2252. L"QueryVolumesSupportedForSnapshots failed, hr<%#x>", ft.hr);
  2253. // An empty enumerator was returned (S_FALSE) for this provider; try next one
  2254. if (ft.hr == S_FALSE)
  2255. {
  2256. ft.hr = S_OK;
  2257. continue;
  2258. }
  2259. while (1)
  2260. {
  2261. CComPtr<IWbemClassObject> spInstance;
  2262. VSS_MGMT_OBJECT_PROP prop;
  2263. VSS_VOLUME_PROP& propVolume = prop.Obj.Vol;
  2264. ULONG ulFetch = 0;
  2265. ft.hr = spEnumMgmt->Next(1, &prop, &ulFetch);
  2266. if (ft.HrFailed())
  2267. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  2268. if (ft.hr == S_FALSE)
  2269. {
  2270. ft.hr = S_OK;
  2271. break; // All done with this provider
  2272. }
  2273. CVssAutoPWSZ awszVolumeName(propVolume.m_pwszVolumeName);
  2274. CVssAutoPWSZ awszVolumeDisplayName(propVolume.m_pwszVolumeDisplayName);
  2275. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  2276. if (ft.HrFailed())
  2277. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  2278. LoadInstance(&guid, &propVolume, spInstance.p);
  2279. ft.hr = pHandler->Indicate(1, &spInstance.p);
  2280. }
  2281. }
  2282. }
  2283. catch (HRESULT hrEx)
  2284. {
  2285. ft.hr = hrEx;
  2286. }
  2287. return ft.hr;
  2288. } //*** CVolumeSupport::EnumInstance()
  2289. HRESULT
  2290. CVolumeSupport::GetObject(
  2291. IN CObjPath& rObjPath,
  2292. IN long lFlags,
  2293. IN IWbemContext* pCtx,
  2294. IN IWbemObjectSink* pHandler
  2295. )
  2296. {
  2297. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CVolumeSupportr::GetObject");
  2298. try
  2299. {
  2300. CComPtr<IVssSnapshotMgmt> spMgmt;
  2301. CComPtr<IVssEnumMgmtObject> spEnumMgmt;
  2302. _bstr_t bstrProviderRef, bstrProviderID;
  2303. _bstr_t bstrVolumeRef, bstrVolumeID;
  2304. CObjPath objPathProvider;
  2305. CObjPath objPathVolume;
  2306. GUID guid = GUID_NULL;
  2307. // Get the Provider reference
  2308. bstrProviderRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_ANTECEDENT);
  2309. IF_WSTR_NULL_THROW(bstrProviderRef, WBEM_E_INVALID_OBJECT_PATH, L"VolumeSupport provider key property not found");
  2310. // Get the Shadow reference
  2311. bstrVolumeRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_DEPENDENT);
  2312. IF_WSTR_NULL_THROW(bstrVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"VolumeSupport volume key property not found");
  2313. // Extract the Volume and Shadow IDs
  2314. if (!objPathProvider.Init(bstrProviderRef))
  2315. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"VolumeSupport::GetObject: Provider object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  2316. if (!objPathVolume.Init(bstrVolumeRef))
  2317. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"VolumeSupport::GetObject: Volume object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  2318. bstrProviderID = objPathProvider.GetStringValueForProperty(PVDR_PROP_ID);
  2319. IF_WSTR_NULL_THROW(bstrProviderID, WBEM_E_INVALID_OBJECT_PATH, L"VolumeSupport provider key property ID not found");
  2320. bstrVolumeID = objPathVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  2321. IF_WSTR_NULL_THROW(bstrVolumeID, WBEM_E_INVALID_OBJECT_PATH, L"VolumeSupport support key property DeviceID not found");
  2322. // Create snapshot mgmt object
  2323. ft.CoCreateInstanceWithLog(
  2324. VSSDBG_VSSADMIN,
  2325. CLSID_VssSnapshotMgmt,
  2326. L"VssSnapshotMgmt",
  2327. CLSCTX_ALL,
  2328. IID_IVssSnapshotMgmt,
  2329. (IUnknown**)&(spMgmt));
  2330. if (ft.HrFailed())
  2331. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  2332. // Convert string GUID
  2333. if (FAILED(CLSIDFromString(bstrProviderID, &guid)))
  2334. {
  2335. ft.hr = E_INVALIDARG;
  2336. ft.Trace(VSSDBG_VSSADMIN, L"CLSIDFromString failed");
  2337. }
  2338. ft.hr = spMgmt->QueryVolumesSupportedForSnapshots(
  2339. guid,
  2340. VSS_CTX_ALL,
  2341. &spEnumMgmt );
  2342. if (ft.HrFailed())
  2343. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2344. L"QueryVolumesSupportedForSnapshots failed, hr<%#x>", ft.hr);
  2345. while (ft.hr != S_FALSE)
  2346. {
  2347. VSS_MGMT_OBJECT_PROP prop;
  2348. VSS_VOLUME_PROP& propVolume = prop.Obj.Vol;
  2349. ULONG ulFetch = 0;
  2350. ft.hr = spEnumMgmt->Next(1, &prop, &ulFetch);
  2351. if (ft.HrFailed())
  2352. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  2353. if (ft.hr == S_FALSE)
  2354. {
  2355. break; // Volume not found for this provider
  2356. }
  2357. CVssAutoPWSZ awszVolumeName(propVolume.m_pwszVolumeName);
  2358. CVssAutoPWSZ awszVolumeDisplayName(propVolume.m_pwszVolumeDisplayName);
  2359. if (_wcsicmp(awszVolumeName, bstrVolumeID) == 0)
  2360. {
  2361. CComPtr<IWbemClassObject> spInstance;
  2362. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  2363. if (ft.HrFailed())
  2364. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  2365. LoadInstance(&guid, &propVolume, spInstance.p);
  2366. ft.hr = pHandler->Indicate(1, &spInstance.p);
  2367. break;
  2368. }
  2369. }
  2370. if (ft.hr == S_FALSE)
  2371. {
  2372. ft.hr = WBEM_E_NOT_FOUND;
  2373. }
  2374. }
  2375. catch (HRESULT hrEx)
  2376. {
  2377. ft.hr = hrEx;
  2378. }
  2379. return ft.hr;
  2380. }
  2381. void
  2382. CVolumeSupport::LoadInstance(
  2383. IN GUID* pProviderID,
  2384. IN VSS_VOLUME_PROP* pPropVol,
  2385. IN OUT IWbemClassObject* pObject
  2386. )
  2387. {
  2388. CWbemClassObject wcoInstance(pObject);
  2389. CObjPath pathProvider;
  2390. CObjPath pathVolume;
  2391. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CVolumeSupport::LoadInstance");
  2392. // Set the Provider Ref property
  2393. CVssAutoPWSZ awszGUID(GuidToString(*pProviderID)); // Auto-delete string
  2394. if (!pathProvider.Init(PVDR_CLASS_PROVIDER))
  2395. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"VolumeSupport::LoadInstance: Provider object path initialization failed, hr<%#x>", E_UNEXPECTED);
  2396. if (!pathProvider.AddProperty(PVDR_PROP_ID, awszGUID))
  2397. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"VolumeSupport::LoadInstance: unable to add ID property to object path");
  2398. wcoInstance.SetProperty((wchar_t*)pathProvider.GetObjectPathString(), PVD_WBEM_PROP_ANTECEDENT);
  2399. // Set the Volume Ref property
  2400. if (!pathVolume.Init(PVDR_CLASS_VOLUME))
  2401. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"VolumeSupport::LoadInstance: Volume object path initialization failed, hr<%#x>", E_UNEXPECTED);
  2402. if (!pathVolume.AddProperty(PVDR_PROP_DEVICEID, pPropVol->m_pwszVolumeName))
  2403. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"VolumeSupport::LoadInstance: unable to add DeviceID property to object path");
  2404. wcoInstance.SetProperty((wchar_t*)pathVolume.GetObjectPathString(), PVD_WBEM_PROP_DEPENDENT);
  2405. }
  2406. //****************************************************************************
  2407. //
  2408. // CDiffVolumeSupport
  2409. //
  2410. //****************************************************************************
  2411. CDiffVolumeSupport::CDiffVolumeSupport(
  2412. IN LPCWSTR pwszName,
  2413. IN CWbemServices* pNamespace
  2414. )
  2415. : CProvBase(pwszName, pNamespace)
  2416. {
  2417. } //*** CDiffVolumeSupport::CDiffVolumeSupport()
  2418. CProvBase *
  2419. CDiffVolumeSupport::S_CreateThis(
  2420. IN PCWSTR pwszName,
  2421. IN CWbemServices* pNamespace
  2422. )
  2423. {
  2424. HRESULT hr = WBEM_E_FAILED;
  2425. CDiffVolumeSupport * pVolumeSupport = NULL;
  2426. pVolumeSupport = new CDiffVolumeSupport(pwszName, pNamespace);
  2427. if (pVolumeSupport)
  2428. {
  2429. hr = pVolumeSupport->Initialize();
  2430. }
  2431. else
  2432. {
  2433. hr = E_OUTOFMEMORY;
  2434. }
  2435. if (FAILED(hr))
  2436. {
  2437. delete pVolumeSupport;
  2438. pVolumeSupport = NULL;
  2439. }
  2440. return pVolumeSupport;
  2441. } //*** CDiffVolumeSupport::S_CreateThis()
  2442. HRESULT
  2443. CDiffVolumeSupport::EnumInstance(
  2444. IN long lFlags,
  2445. IN IWbemContext* pCtx,
  2446. IN IWbemObjectSink* pHandler
  2447. )
  2448. {
  2449. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CDiffVolumeSupport::EnumInstance");
  2450. try
  2451. {
  2452. CComPtr<IVssSnapshotMgmt> spMgmt;
  2453. CGUIDList listProviderID;
  2454. GUID guid;
  2455. // Get the provider IDs
  2456. GetProviderIDList(m_spCoord, &listProviderID);
  2457. // Create snapshot mgmt object
  2458. ft.CoCreateInstanceWithLog(
  2459. VSSDBG_VSSADMIN,
  2460. CLSID_VssSnapshotMgmt,
  2461. L"VssSnapshotMgmt",
  2462. CLSCTX_ALL,
  2463. IID_IVssSnapshotMgmt,
  2464. (IUnknown**)&(spMgmt));
  2465. if (ft.HrFailed())
  2466. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  2467. while (listProviderID.Extract(guid))
  2468. {
  2469. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  2470. CComPtr<IVssEnumMgmtObject> spEnumMgmt;
  2471. ft.hr = spMgmt->GetProviderMgmtInterface(
  2472. guid,
  2473. IID_IVssDifferentialSoftwareSnapshotMgmt,
  2474. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  2475. if (ft.hr == E_NOINTERFACE)
  2476. {
  2477. ft.hr = S_OK;
  2478. continue; // Inteface not supported, try next provider
  2479. }
  2480. if (ft.HrFailed())
  2481. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2482. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  2483. ft.hr = spDiffMgmt->QueryVolumesSupportedForDiffAreas(NULL, &spEnumMgmt);
  2484. if (ft.HrFailed())
  2485. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2486. L"QueryVolumesSupportedForDiffAreas failed, hr<%#x>", ft.hr);
  2487. if (ft.hr == S_FALSE)
  2488. {
  2489. ft.hr = S_OK;
  2490. continue; // no Voumes supported; try next provider
  2491. }
  2492. while (1)
  2493. {
  2494. VSS_MGMT_OBJECT_PROP prop;
  2495. VSS_DIFF_VOLUME_PROP& propDiff = prop.Obj.DiffVol;
  2496. CComPtr<IWbemClassObject> spInstance;
  2497. ULONG ulFetch = 0;
  2498. ft.hr = spEnumMgmt->Next(1, &prop, &ulFetch);
  2499. if (ft.HrFailed())
  2500. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  2501. if (ft.hr == S_FALSE)
  2502. {
  2503. ft.hr = S_OK;
  2504. break; // No more volumes
  2505. }
  2506. CVssAutoPWSZ awszVolumeName(propDiff.m_pwszVolumeName);
  2507. CVssAutoPWSZ awszVolumeDisplayName(propDiff.m_pwszVolumeDisplayName);
  2508. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  2509. if (ft.HrFailed())
  2510. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  2511. LoadInstance(&guid, &propDiff, spInstance.p);
  2512. ft.hr = pHandler->Indicate(1, &spInstance.p);
  2513. }
  2514. }
  2515. }
  2516. catch (HRESULT hrEx)
  2517. {
  2518. ft.hr = hrEx;
  2519. }
  2520. return ft.hr;
  2521. } //*** CDiffVolumeSupport::EnumInstance()
  2522. HRESULT
  2523. CDiffVolumeSupport::GetObject(
  2524. IN CObjPath& rObjPath,
  2525. IN long lFlags,
  2526. IN IWbemContext* pCtx,
  2527. IN IWbemObjectSink* pHandler
  2528. )
  2529. {
  2530. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CDiffVolumeSupport::GetObject");
  2531. try
  2532. {
  2533. CComPtr<IVssSnapshotMgmt> spMgmt;
  2534. CComPtr<IVssEnumMgmtObject> spEnumMgmt;
  2535. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> spDiffMgmt;
  2536. _bstr_t bstrProviderRef, bstrProviderID;
  2537. _bstr_t bstrVolumeRef, bstrVolumeID;
  2538. CObjPath objPathProvider;
  2539. CObjPath objPathVolume;
  2540. GUID guid = GUID_NULL;
  2541. // Get the Provider reference
  2542. bstrProviderRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_ANTECEDENT);
  2543. IF_WSTR_NULL_THROW(bstrProviderRef, WBEM_E_INVALID_OBJECT_PATH, L"DiffVolumeSupport provider key property not found");
  2544. // Get the Shadow reference
  2545. bstrVolumeRef = rObjPath.GetStringValueForProperty(PVD_WBEM_PROP_DEPENDENT);
  2546. IF_WSTR_NULL_THROW(bstrVolumeRef, WBEM_E_INVALID_OBJECT_PATH, L"DiffVolumeSupport volume key property not found");
  2547. // Extract the Volume and Shadow IDs
  2548. if (!objPathProvider.Init(bstrProviderRef))
  2549. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"DiffVolumeSupport::GetObject: Provider object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  2550. if (!objPathVolume.Init(bstrVolumeRef))
  2551. ft.Throw(VSSDBG_VSSADMIN, WBEM_E_INVALID_OBJECT_PATH, L"DiffVolumeSupport::GetObject: Volume object path initialization failed, hr<%#x>", WBEM_E_INVALID_OBJECT_PATH);
  2552. bstrProviderID = objPathProvider.GetStringValueForProperty(PVDR_PROP_ID);
  2553. IF_WSTR_NULL_THROW(bstrProviderID, WBEM_E_INVALID_OBJECT_PATH, L"DiffVolumeSupport provider key property ID not found");
  2554. bstrVolumeID = objPathVolume.GetStringValueForProperty(PVDR_PROP_DEVICEID);
  2555. IF_WSTR_NULL_THROW(bstrVolumeID, WBEM_E_INVALID_OBJECT_PATH, L"DiffVolumeSupport support key property DeviceID not found");
  2556. // Convert provider string GUID
  2557. if (FAILED(CLSIDFromString(bstrProviderID, &guid)))
  2558. {
  2559. ft.hr = E_INVALIDARG;
  2560. ft.Trace(VSSDBG_VSSADMIN, L"CLSIDFromString failed");
  2561. }
  2562. // Create snapshot mgmt object
  2563. ft.CoCreateInstanceWithLog(
  2564. VSSDBG_VSSADMIN,
  2565. CLSID_VssSnapshotMgmt,
  2566. L"VssSnapshotMgmt",
  2567. CLSCTX_ALL,
  2568. IID_IVssSnapshotMgmt,
  2569. (IUnknown**)&(spMgmt));
  2570. if (ft.HrFailed())
  2571. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Connection failed with hr<%#x>", ft.hr);
  2572. ft.hr = spMgmt->GetProviderMgmtInterface(
  2573. guid,
  2574. IID_IVssDifferentialSoftwareSnapshotMgmt,
  2575. reinterpret_cast<IUnknown**>(&spDiffMgmt));
  2576. if (ft.hr == E_NOINTERFACE)
  2577. {
  2578. ft.hr = WBEM_E_NOT_FOUND;
  2579. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"DiffVolumeSupport: provider is not a differential provider");
  2580. }
  2581. if (ft.HrFailed())
  2582. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2583. L"GetProviderMgmtInterface failed, hr<%#x>", ft.hr);
  2584. ft.hr = spDiffMgmt->QueryVolumesSupportedForDiffAreas(NULL, &spEnumMgmt);
  2585. if (ft.HrFailed())
  2586. ft.Throw(VSSDBG_VSSADMIN, ft.hr,
  2587. L"QueryVolumesSupportedForDiffAreas failed, hr<%#x>", ft.hr);
  2588. while (ft.hr != S_FALSE)
  2589. {
  2590. VSS_MGMT_OBJECT_PROP prop;
  2591. VSS_DIFF_VOLUME_PROP& propDiff = prop.Obj.DiffVol;
  2592. ULONG ulFetch = 0;
  2593. ft.hr = spEnumMgmt->Next(1, &prop, &ulFetch);
  2594. if (ft.HrFailed())
  2595. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"Next failed, hr<%#x>", ft.hr);
  2596. if (ft.hr == S_FALSE)
  2597. {
  2598. break; // Diff volume not found for this provider
  2599. }
  2600. CVssAutoPWSZ awszVolumeName(propDiff.m_pwszVolumeName);
  2601. CVssAutoPWSZ awszVolumeDisplayName(propDiff.m_pwszVolumeDisplayName);
  2602. if (_wcsicmp(awszVolumeName, bstrVolumeID) == 0)
  2603. {
  2604. CComPtr<IWbemClassObject> spInstance;
  2605. ft.hr = m_pClass->SpawnInstance( 0, &spInstance );
  2606. if (ft.HrFailed())
  2607. ft.Throw(VSSDBG_VSSADMIN, ft.hr, L"SpawnInstance failed, hr<%#x>", ft.hr);
  2608. LoadInstance(&guid, &propDiff, spInstance.p);
  2609. ft.hr = pHandler->Indicate(1, &spInstance.p);
  2610. break;
  2611. }
  2612. }
  2613. if (ft.hr == S_FALSE)
  2614. {
  2615. ft.hr = WBEM_E_NOT_FOUND;
  2616. }
  2617. }
  2618. catch (HRESULT hrEx)
  2619. {
  2620. ft.hr = hrEx;
  2621. }
  2622. return ft.hr;
  2623. }
  2624. void
  2625. CDiffVolumeSupport::LoadInstance(
  2626. IN GUID* pProviderID,
  2627. IN VSS_DIFF_VOLUME_PROP* pPropVol,
  2628. IN OUT IWbemClassObject* pObject
  2629. )
  2630. {
  2631. CWbemClassObject wcoInstance(pObject);
  2632. CObjPath pathProvider;
  2633. CObjPath pathVolume;
  2634. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"CDiffVolumeSupport::LoadInstance");
  2635. // Set the Provider Ref property
  2636. CVssAutoPWSZ awszGUID(GuidToString(*pProviderID)); // Auto-delete string
  2637. if (!pathProvider.Init(PVDR_CLASS_PROVIDER))
  2638. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"DiffVolumeSupport::LoadInstance: Provider object path initialization failed, hr<%#x>", E_UNEXPECTED);
  2639. if (!pathProvider.AddProperty(PVDR_PROP_ID, awszGUID))
  2640. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"DiffVolumeSupport::LoadInstance: unable to add ID property to object path");
  2641. wcoInstance.SetProperty((wchar_t*)pathProvider.GetObjectPathString(), PVD_WBEM_PROP_ANTECEDENT);
  2642. // Set the Volume Ref property
  2643. if (!pathVolume.Init(PVDR_CLASS_VOLUME))
  2644. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"DiffVolumeSupport::LoadInstance: Volume object path initialization failed, hr<%#x>", E_UNEXPECTED);
  2645. if (!pathVolume.AddProperty(PVDR_PROP_DEVICEID, pPropVol->m_pwszVolumeName))
  2646. ft.Throw(VSSDBG_VSSADMIN, E_UNEXPECTED, L"DiffVolumeSupport::LoadInstance: unable to add DeviceID property to object path");
  2647. wcoInstance.SetProperty((wchar_t*)pathVolume.GetObjectPathString(), PVD_WBEM_PROP_DEPENDENT);
  2648. }
  2649. HRESULT
  2650. GetShadowPropertyStruct(
  2651. IN IVssCoordinator* pCoord,
  2652. IN WCHAR* pwszShadowID,
  2653. OUT VSS_SNAPSHOT_PROP* pPropSnap
  2654. )
  2655. {
  2656. CVssFunctionTracer ft(VSSDBG_VSSADMIN, L"GetShadowPropertyStruct");
  2657. GUID guid = GUID_NULL;
  2658. _ASSERTE(pPropSnap != NULL);
  2659. _ASSERTE(pwszShadowID != NULL);
  2660. // Convert string GUID
  2661. if (FAILED(CLSIDFromString(pwszShadowID, &guid)))
  2662. {
  2663. ft.hr = E_INVALIDARG;
  2664. ft.Trace(VSSDBG_VSSADMIN, L"CLSIDFromString failed");
  2665. }
  2666. else
  2667. {
  2668. // Set the context to see all shadows
  2669. ft.hr = pCoord->SetContext(VSS_CTX_ALL);
  2670. if (ft.HrFailed())
  2671. {
  2672. ft.Trace(VSSDBG_VSSADMIN,
  2673. L"IVssCoordinator::SetContext failed, hr<%#x>", ft.hr);
  2674. }
  2675. else
  2676. {
  2677. // Query for the context to see all shadows
  2678. ft.hr = pCoord->GetSnapshotProperties(
  2679. guid,
  2680. pPropSnap);
  2681. if (ft.hr == VSS_E_OBJECT_NOT_FOUND)
  2682. {
  2683. ft.hr = WBEM_E_NOT_FOUND;
  2684. }
  2685. }
  2686. }
  2687. return ft.hr;
  2688. }
  2689. BOOL
  2690. StringGuidIsGuid(
  2691. IN WCHAR* pwszGuid,
  2692. IN GUID& guidIn
  2693. )
  2694. {
  2695. BOOL fIsEqual = FALSE;
  2696. GUID guid = GUID_NULL;
  2697. if (SUCCEEDED(CLSIDFromString(pwszGuid, &guid)))
  2698. {
  2699. fIsEqual = IsEqualGUID(guid, guidIn);
  2700. }
  2701. return fIsEqual;
  2702. }