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.

648 lines
12 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. fsarcvy.cpp
  5. Abstract:
  6. Defines the functions for the recovery record class.
  7. Author:
  8. Ron White [ronw] 8-Sep-1997
  9. Revision History:
  10. Steve Wimmer [stevew] 30-July-1998
  11. - updated CFsaRecoveryRec::GetClassId's WsbTraceOut to hold
  12. the proper function name
  13. --*/
  14. #include "stdafx.h"
  15. #include "wsb.h"
  16. #include "fsarcvy.h"
  17. #define WSB_TRACE_IS WSB_TRACE_BIT_FSA
  18. HRESULT
  19. CFsaRecoveryRec::GetBagId(
  20. OUT GUID* pId
  21. )
  22. /*++
  23. Implements:
  24. IFsaRecoveryRec::GetBagId
  25. --*/
  26. {
  27. HRESULT hr = S_OK;
  28. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetBagId"),OLESTR(""));
  29. try {
  30. WsbAssert(0 != pId, E_POINTER);
  31. *pId = m_BagId;
  32. } WsbCatch(hr);
  33. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetBagId"), OLESTR("hr = <%ls> Id = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pId));
  34. return(hr);
  35. }
  36. HRESULT
  37. CFsaRecoveryRec::GetBagOffset(
  38. OUT LONGLONG* pOffset
  39. )
  40. /*++
  41. Implements:
  42. IFsaRecoveryRec::GetBagOffset
  43. --*/
  44. {
  45. HRESULT hr = S_OK;
  46. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetBagOffset"),OLESTR(""));
  47. try {
  48. WsbAssert(0 != pOffset, E_POINTER);
  49. *pOffset = m_BagOffset;
  50. } WsbCatch(hr);
  51. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetBagOffset"), OLESTR("hr = <%ls> Offset = <%ls>"), WsbHrAsString(hr), WsbLonglongAsString(*pOffset));
  52. return(hr);
  53. }
  54. HRESULT
  55. CFsaRecoveryRec::GetFileId(
  56. OUT LONGLONG* pFileId
  57. )
  58. /*++
  59. Implements:
  60. IFsaRecoveryRec::GetFileId
  61. --*/
  62. {
  63. HRESULT hr = S_OK;
  64. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetFileId"),OLESTR(""));
  65. try {
  66. WsbAssert(0 != pFileId, E_POINTER);
  67. *pFileId = m_FileId;
  68. } WsbCatch(hr);
  69. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetFileId"),
  70. OLESTR("hr = <%ls> Size = <%ls>"), WsbHrAsString( hr ), WsbLonglongAsString( *pFileId ) );
  71. return(hr);
  72. }
  73. HRESULT
  74. CFsaRecoveryRec::GetOffsetSize(
  75. OUT LONGLONG* pOffset,
  76. OUT LONGLONG* pSize
  77. )
  78. /*++
  79. Implements:
  80. IFsaRecoveryRec::GetOffsetSize
  81. --*/
  82. {
  83. HRESULT hr = S_OK;
  84. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetOffsetSize"),OLESTR(""));
  85. try {
  86. WsbAssertPointer(pOffset);
  87. WsbAssertPointer(pSize);
  88. *pOffset = m_Offset;
  89. *pSize = m_Size;
  90. } WsbCatch(hr);
  91. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetOffsetSize"), OLESTR("hr = <%ls> Offset = %I64d, Size = %I64d"),
  92. WsbHrAsString(hr), *pOffset, *pSize);
  93. return(hr);
  94. }
  95. HRESULT
  96. CFsaRecoveryRec::GetPath(
  97. OUT OLECHAR** ppPath,
  98. IN ULONG bufferSize
  99. )
  100. /*++
  101. Implements:
  102. IFsaRecoveryRec::GetPath
  103. --*/
  104. {
  105. HRESULT hr = S_OK;
  106. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetPath"),OLESTR(""));
  107. try {
  108. WsbAssert(0 != ppPath, E_POINTER);
  109. WsbAffirmHr(m_Path.CopyTo(ppPath, bufferSize));
  110. WsbTrace( OLESTR("CFsaRecoveryRec::GetPath path = <%ls>\n"), *ppPath );
  111. } WsbCatch(hr);
  112. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetPath"),
  113. OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  114. return(hr);
  115. }
  116. HRESULT
  117. CFsaRecoveryRec::GetRecoveryCount(
  118. OUT LONG* pRecoveryCount
  119. )
  120. /*++
  121. Implements:
  122. IFsaRecoveryRec::GetRecoveryCount
  123. --*/
  124. {
  125. HRESULT hr = S_OK;
  126. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetRecoveryCount"),OLESTR(""));
  127. try {
  128. WsbAssertPointer(pRecoveryCount);
  129. *pRecoveryCount = m_RecoveryCount;
  130. } WsbCatch(hr);
  131. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetRecoveryCount"), OLESTR("hr = <%ls> RecoveryCount = %ld"),
  132. WsbHrAsString(hr), *pRecoveryCount);
  133. return(hr);
  134. }
  135. HRESULT
  136. CFsaRecoveryRec::GetStatus(
  137. OUT ULONG* pStatus
  138. )
  139. /*++
  140. Implements:
  141. IFsaRecoveryRec::GetStatus
  142. --*/
  143. {
  144. HRESULT hr = S_OK;
  145. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetStatus"),OLESTR(""));
  146. try {
  147. WsbAssertPointer(pStatus);
  148. *pStatus = m_Status;
  149. } WsbCatch(hr);
  150. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetStatus"), OLESTR("hr = <%ls> Status = %lx"),
  151. WsbHrAsString(hr), *pStatus);
  152. return(hr);
  153. }
  154. HRESULT
  155. CFsaRecoveryRec::FinalConstruct(
  156. void
  157. )
  158. /*++
  159. Implements:
  160. CComObjectRoot::FinalConstruct().
  161. --*/
  162. {
  163. HRESULT hr = S_OK;
  164. try {
  165. WsbAssertHr(CWsbDbEntity::FinalConstruct());
  166. m_BagId = GUID_NULL;
  167. m_BagOffset = 0;
  168. m_FileId = 0;
  169. m_Offset = 0;
  170. m_RecoveryCount = 0;
  171. m_Size = 0;
  172. m_Status = 0;
  173. } WsbCatch(hr);
  174. return(hr);
  175. }
  176. HRESULT
  177. CFsaRecoveryRec::FinalRelease(
  178. void
  179. )
  180. /*++
  181. Implements:
  182. CComObjectRoot::FinalRelease
  183. --*/
  184. {
  185. HRESULT hr = S_OK;
  186. CWsbDbEntity::FinalRelease();
  187. return(hr);
  188. }
  189. HRESULT CFsaRecoveryRec::GetClassID
  190. (
  191. OUT LPCLSID pclsid
  192. )
  193. /*++
  194. Implements:
  195. IPerist::GetClassID
  196. --*/
  197. {
  198. HRESULT hr = S_OK;
  199. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetClassID"), OLESTR(""));
  200. try {
  201. WsbAssertPointer(pclsid);
  202. *pclsid = CLSID_CFsaRecoveryRec;
  203. } WsbCatch(hr);
  204. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pclsid));
  205. return(hr);
  206. }
  207. HRESULT CFsaRecoveryRec::Load
  208. (
  209. IN IStream* pStream
  210. )
  211. /*++
  212. Implements:
  213. IPersistStream::Load
  214. --*/
  215. {
  216. HRESULT hr = S_OK;
  217. WsbTraceIn(OLESTR("CFsaRecoveryRec::Load"), OLESTR(""));
  218. try {
  219. OLECHAR* pPath = NULL;
  220. WsbAssertPointer(pStream);
  221. WsbAssertHr(WsbLoadFromStream(pStream, &m_BagId));
  222. WsbAssertHr(WsbLoadFromStream(pStream, &m_BagOffset));
  223. WsbAssertHr(WsbLoadFromStream(pStream, &m_FileId));
  224. WsbAssertHr(WsbLoadFromStream(pStream, &m_Offset));
  225. WsbAssertHr(WsbLoadFromStream(pStream, &m_Path, 0));
  226. WsbAssertHr(WsbLoadFromStream(pStream, &m_RecoveryCount));
  227. WsbAssertHr(WsbLoadFromStream(pStream, &m_Size));
  228. WsbAssertHr(WsbLoadFromStream(pStream, &m_Status));
  229. } WsbCatch(hr);
  230. WsbTraceOut(OLESTR("CFsaRecoveryRec::Load"),
  231. OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  232. return(hr);
  233. }
  234. HRESULT CFsaRecoveryRec::Print
  235. (
  236. IN IStream* pStream
  237. )
  238. /*++
  239. Implements:
  240. IWsbDbEntity::Print
  241. --*/
  242. {
  243. HRESULT hr = S_OK;
  244. WsbTraceIn(OLESTR("CFsaRecoveryRec::Print"), OLESTR(""));
  245. try {
  246. WsbAssertPointer(pStream);
  247. CWsbStringPtr strGuid;
  248. WsbAffirmHr(WsbSafeGuidAsString(m_BagId, strGuid));
  249. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" BagId = %ls"), (WCHAR *)strGuid));
  250. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" BagOffset = %I64d"), m_BagOffset));
  251. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" FileId = %I64d"), m_FileId));
  252. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Offset = %I64d"), m_Offset));
  253. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Size = %I64d"), m_Size));
  254. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RecoveryCount = %ld"),
  255. m_RecoveryCount));
  256. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Status = %lx"), m_Status));
  257. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(", Path = %ls"),
  258. static_cast<OLECHAR*>(m_Path)));
  259. } WsbCatch(hr);
  260. WsbTraceOut(OLESTR("CFsaRecoveryRec::Print"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  261. return(hr);
  262. }
  263. HRESULT CFsaRecoveryRec::Save
  264. (
  265. IN IStream* pStream,
  266. IN BOOL clearDirty
  267. )
  268. /*++
  269. Implements:
  270. IPersistStream::Save
  271. --*/
  272. {
  273. HRESULT hr = S_OK;
  274. WsbTraceIn(OLESTR("CFsaRecoveryRec::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  275. try {
  276. WsbAssertPointer(pStream);
  277. WsbAssertHr(WsbSaveToStream(pStream, m_BagId));
  278. WsbAssertHr(WsbSaveToStream(pStream, m_BagOffset));
  279. WsbAssertHr(WsbSaveToStream(pStream, m_FileId));
  280. WsbAssertHr(WsbSaveToStream(pStream, m_Offset));
  281. WsbAssertHr(WsbSaveToStream(pStream, m_Path));
  282. WsbAssertHr(WsbSaveToStream(pStream, m_RecoveryCount));
  283. WsbAssertHr(WsbSaveToStream(pStream, m_Size));
  284. WsbAssertHr(WsbSaveToStream(pStream, m_Status));
  285. // If we got it saved and we were asked to clear the dirty bit, then
  286. // do so now.
  287. if (clearDirty) {
  288. m_isDirty = FALSE;
  289. }
  290. } WsbCatch(hr);
  291. WsbTraceOut(OLESTR("CFsaRecoveryRec::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  292. return(hr);
  293. }
  294. HRESULT
  295. CFsaRecoveryRec::SetBagId(
  296. IN GUID BagId
  297. )
  298. /*++
  299. Implements:
  300. IFsaRecoveryRec::SetBagId
  301. --*/
  302. {
  303. HRESULT hr = S_OK;
  304. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetBagId"),OLESTR(""));
  305. m_BagId = BagId;
  306. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetBagId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  307. return(hr);
  308. }
  309. HRESULT
  310. CFsaRecoveryRec::SetBagOffset(
  311. IN LONGLONG BagOffset
  312. )
  313. /*++
  314. Implements:
  315. IFsaRecoveryRec::SetBagOffset
  316. --*/
  317. {
  318. HRESULT hr = S_OK;
  319. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetBagOffset"),OLESTR(""));
  320. m_BagOffset = BagOffset;
  321. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetBagOffset"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  322. return(hr);
  323. }
  324. HRESULT
  325. CFsaRecoveryRec::SetFileId(
  326. IN LONGLONG FileId
  327. )
  328. /*++
  329. Implements:
  330. IFsaRecoveryRec::SetFileId
  331. --*/
  332. {
  333. HRESULT hr = S_OK;
  334. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetFileId"),OLESTR(""));
  335. try {
  336. m_FileId = FileId;
  337. } WsbCatch(hr);
  338. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetFileId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  339. return(hr);
  340. }
  341. HRESULT
  342. CFsaRecoveryRec::SetOffsetSize(
  343. IN LONGLONG Offset,
  344. IN LONGLONG Size
  345. )
  346. /*++
  347. Implements:
  348. IFsaRecoveryRec::SetOffsetSize
  349. --*/
  350. {
  351. HRESULT hr = S_OK;
  352. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetOffsetSize"),OLESTR("Offset = %I64d, Size = %I64d"),
  353. Offset, Size);
  354. m_Offset = Offset;
  355. m_Size = Size;
  356. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetOffsetSize"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  357. return(hr);
  358. }
  359. HRESULT
  360. CFsaRecoveryRec::SetPath(
  361. IN OLECHAR* Path
  362. )
  363. /*++
  364. Implements:
  365. IFsaRecoveryRec::SetPath
  366. --*/
  367. {
  368. HRESULT hr = S_OK;
  369. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetPath"),OLESTR("Path = <%ls>"),
  370. Path);
  371. try {
  372. m_Path = Path;
  373. } WsbCatch(hr);
  374. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetPath"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  375. return(hr);
  376. }
  377. HRESULT
  378. CFsaRecoveryRec::SetRecoveryCount(
  379. IN LONG RecoveryCount
  380. )
  381. /*++
  382. Implements:
  383. IFsaRecoveryRec::SetRecoveryCount
  384. --*/
  385. {
  386. HRESULT hr = S_OK;
  387. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetRecoveryCount"),OLESTR("RecoveryCount = %ld"),
  388. RecoveryCount);
  389. m_RecoveryCount = RecoveryCount;
  390. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetRecoveryCount"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  391. return(hr);
  392. }
  393. HRESULT
  394. CFsaRecoveryRec::SetStatus(
  395. IN ULONG Status
  396. )
  397. /*++
  398. Implements:
  399. IFsaRecoveryRec::SetStatus
  400. --*/
  401. {
  402. HRESULT hr = S_OK;
  403. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetStatus"),OLESTR("Status = %lx"),
  404. Status);
  405. m_Status = Status;
  406. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetStatus"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  407. return(hr);
  408. }
  409. HRESULT
  410. CFsaRecoveryRec::UpdateKey(
  411. IWsbDbKey *pKey
  412. )
  413. /*++
  414. Implements:
  415. IWsbDbEntity::UpdateKey
  416. --*/
  417. {
  418. HRESULT hr = E_FAIL;
  419. try {
  420. UCHAR FileKey[RECOVERY_KEY_SIZE + 1];
  421. ULONG KeyType;
  422. WsbAffirmHr(pKey->GetType(&KeyType));
  423. if (RECOVERY_KEY_TYPE == KeyType) {
  424. WsbAffirmHr(SquashFilepath(m_Path, FileKey, RECOVERY_KEY_SIZE));
  425. WsbAffirmHr(pKey->SetToBytes(FileKey, RECOVERY_KEY_SIZE));
  426. hr = S_OK;
  427. }
  428. } WsbCatch(hr);
  429. return(hr);
  430. }