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.

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