Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

341 lines
5.5 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: backup.cpp
  7. //
  8. // Contents: Cert Server Database interface implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include <pch.cpp>
  12. #pragma hdrstop
  13. #include "csprop.h"
  14. #include "db.h"
  15. #include "backup.h"
  16. #if DBG
  17. LONG g_cCertDBBackup;
  18. LONG g_cCertDBBackupTotal;
  19. #endif
  20. CCertDBBackup::CCertDBBackup()
  21. {
  22. DBGCODE(InterlockedIncrement(&g_cCertDBBackup));
  23. DBGCODE(InterlockedIncrement(&g_cCertDBBackupTotal));
  24. m_pdb = NULL;
  25. m_pcs = NULL;
  26. m_fFileOpen = FALSE;
  27. m_fBegin = FALSE;
  28. m_fTruncated = FALSE;
  29. m_cRef = 1;
  30. }
  31. CCertDBBackup::~CCertDBBackup()
  32. {
  33. DBGCODE(InterlockedDecrement(&g_cCertDBBackup));
  34. _Cleanup();
  35. }
  36. VOID
  37. CCertDBBackup::_Cleanup()
  38. {
  39. HRESULT hr;
  40. if (NULL != m_pdb)
  41. {
  42. if (m_fFileOpen)
  43. {
  44. CloseFile();
  45. }
  46. if (m_fBegin)
  47. {
  48. hr = ((CCertDB *) m_pdb)->BackupEnd();
  49. _PrintIfError(hr, "BackupEnd");
  50. m_fBegin = FALSE;
  51. }
  52. if (NULL != m_pcs)
  53. {
  54. hr = ((CCertDB *) m_pdb)->ReleaseSession(m_pcs);
  55. _PrintIfError(hr, "ReleaseSession");
  56. m_pcs = NULL;
  57. }
  58. m_pdb->Release();
  59. m_pdb = NULL;
  60. }
  61. }
  62. HRESULT
  63. CCertDBBackup::Open(
  64. IN LONG grbitJet,
  65. IN CERTSESSION *pcs,
  66. IN ICertDB *pdb)
  67. {
  68. HRESULT hr;
  69. _Cleanup();
  70. if (NULL == pcs || NULL == pdb)
  71. {
  72. hr = E_POINTER;
  73. _JumpError(hr, error, "NULL parm");
  74. }
  75. m_pdb = pdb;
  76. m_pdb->AddRef();
  77. m_grbitJet = grbitJet;
  78. CSASSERT(0 == pcs->cTransact);
  79. hr = ((CCertDB *) m_pdb)->BackupBegin(m_grbitJet);
  80. _JumpIfError(hr, error, "BackupBegin");
  81. m_pcs = pcs;
  82. m_fBegin = TRUE;
  83. error:
  84. if (S_OK != hr)
  85. {
  86. _Cleanup();
  87. }
  88. return(hr);
  89. }
  90. STDMETHODIMP
  91. CCertDBBackup::GetDBFileList(
  92. IN OUT DWORD *pcwcList,
  93. OPTIONAL OUT WCHAR *pwszzList)
  94. {
  95. HRESULT hr;
  96. hr = E_UNEXPECTED;
  97. if (!m_fBegin)
  98. {
  99. _JumpError(hr, error, "!m_fBegin");
  100. }
  101. if (NULL == pcwcList)
  102. {
  103. hr = E_POINTER;
  104. _JumpError(hr, error, "NULL parm");
  105. }
  106. hr = ((CCertDB *) m_pdb)->BackupGetDBFileList(pcwcList, pwszzList);
  107. _JumpIfError(hr, error, "BackupGetDBFileList");
  108. error:
  109. return(hr);
  110. }
  111. STDMETHODIMP
  112. CCertDBBackup::GetLogFileList(
  113. IN OUT DWORD *pcwcList,
  114. OPTIONAL OUT WCHAR *pwszzList)
  115. {
  116. HRESULT hr;
  117. if (!m_fBegin)
  118. {
  119. hr = E_UNEXPECTED;
  120. _JumpError(hr, error, "!m_fBegin");
  121. }
  122. if (NULL == pcwcList)
  123. {
  124. hr = E_POINTER;
  125. _JumpError(hr, error, "NULL parm");
  126. }
  127. hr = ((CCertDB *) m_pdb)->BackupGetLogFileList(pcwcList, pwszzList);
  128. _JumpIfError(hr, error, "BackupGetLogFileList");
  129. error:
  130. return(hr);
  131. }
  132. STDMETHODIMP
  133. CCertDBBackup::OpenFile(
  134. IN WCHAR const *pwszFile,
  135. OPTIONAL OUT ULARGE_INTEGER *pliSize)
  136. {
  137. HRESULT hr;
  138. hr = E_UNEXPECTED;
  139. if (!m_fBegin)
  140. {
  141. _JumpError(hr, error, "!m_fBegin");
  142. }
  143. if (m_fFileOpen)
  144. {
  145. _JumpError(hr, error, "m_fFileOpen");
  146. }
  147. if (m_fTruncated)
  148. {
  149. _JumpError(hr, error, "m_fTruncated");
  150. }
  151. hr = ((CCertDB *) m_pdb)->BackupOpenFile(pwszFile, &m_hFileDB, pliSize);
  152. _JumpIfErrorStr(hr, error, "BackupOpenFile", pwszFile);
  153. m_fFileOpen = TRUE;
  154. error:
  155. return(hr);
  156. }
  157. STDMETHODIMP
  158. CCertDBBackup::ReadFile(
  159. IN OUT DWORD *pcb,
  160. OUT BYTE *pb)
  161. {
  162. HRESULT hr;
  163. if (!m_fFileOpen)
  164. {
  165. hr = E_UNEXPECTED;
  166. _JumpError(hr, error, "!m_fFileOpen");
  167. }
  168. if (NULL == pcb || NULL == pb)
  169. {
  170. hr = E_POINTER;
  171. _JumpError(hr, error, "NULL parm");
  172. }
  173. hr = ((CCertDB *) m_pdb)->BackupReadFile(m_hFileDB, pb, *pcb, pcb);
  174. _JumpIfError(hr, error, "BackupReadFile");
  175. error:
  176. return(hr);
  177. }
  178. STDMETHODIMP
  179. CCertDBBackup::CloseFile()
  180. {
  181. HRESULT hr;
  182. if (!m_fFileOpen)
  183. {
  184. hr = E_UNEXPECTED;
  185. _JumpError(hr, error, "!m_fFileOpen");
  186. }
  187. hr = ((CCertDB *) m_pdb)->BackupCloseFile(m_hFileDB);
  188. _JumpIfError(hr, error, "BackupCloseFile");
  189. m_fFileOpen = FALSE;
  190. error:
  191. return(hr);
  192. }
  193. STDMETHODIMP
  194. CCertDBBackup::TruncateLog()
  195. {
  196. HRESULT hr;
  197. hr = E_UNEXPECTED;
  198. if (!m_fBegin)
  199. {
  200. _JumpError(hr, error, "!m_fBegin");
  201. }
  202. if (m_fFileOpen)
  203. {
  204. _JumpError(hr, error, "m_fFileOpen");
  205. }
  206. hr = ((CCertDB *) m_pdb)->BackupTruncateLog();
  207. _JumpIfError(hr, error, "BackupTruncateLog");
  208. m_fTruncated = TRUE;
  209. error:
  210. return(hr);
  211. }
  212. // IUnknown implementation
  213. STDMETHODIMP
  214. CCertDBBackup::QueryInterface(
  215. const IID& iid,
  216. void **ppv)
  217. {
  218. HRESULT hr;
  219. if (NULL == ppv)
  220. {
  221. hr = E_POINTER;
  222. _JumpError(hr, error, "NULL parm");
  223. }
  224. if (iid == IID_IUnknown)
  225. {
  226. *ppv = static_cast<ICertDBBackup *>(this);
  227. }
  228. else if (iid == IID_ICertDBBackup)
  229. {
  230. *ppv = static_cast<ICertDBBackup *>(this);
  231. }
  232. else
  233. {
  234. *ppv = NULL;
  235. hr = E_NOINTERFACE;
  236. _JumpError(hr, error, "IID");
  237. }
  238. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  239. hr = S_OK;
  240. error:
  241. return(hr);
  242. }
  243. ULONG STDMETHODCALLTYPE
  244. CCertDBBackup::AddRef()
  245. {
  246. return(InterlockedIncrement(&m_cRef));
  247. }
  248. ULONG STDMETHODCALLTYPE
  249. CCertDBBackup::Release()
  250. {
  251. ULONG cRef = InterlockedDecrement(&m_cRef);
  252. if (0 == cRef)
  253. {
  254. delete this;
  255. }
  256. return(cRef);
  257. }
  258. #if 0
  259. STDMETHODIMP
  260. CCertDBBackup::InterfaceSupportsErrorInfo(
  261. IN REFIID riid)
  262. {
  263. static const IID *arr[] =
  264. {
  265. &IID_ICertDBBackup,
  266. };
  267. for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++)
  268. {
  269. if (InlineIsEqualGUID(*arr[i], riid))
  270. {
  271. return(S_OK);
  272. }
  273. }
  274. return(S_FALSE);
  275. }
  276. #endif