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.

181 lines
3.9 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: restore.cpp
  7. //
  8. // Contents: Cert Server Database interface implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include <pch.cpp>
  12. #pragma hdrstop
  13. #include "db.h"
  14. #include "dbw.h"
  15. #include "restore.h"
  16. #define __dwFILE__ __dwFILE_CERTDB_RESTORE_CPP__
  17. #if DBG
  18. LONG g_cCertDBRestore;
  19. LONG g_cCertDBRestoreTotal;
  20. #endif
  21. CCertDBRestore::CCertDBRestore()
  22. {
  23. DBGCODE(InterlockedIncrement(&g_cCertDBRestore));
  24. DBGCODE(InterlockedIncrement(&g_cCertDBRestoreTotal));
  25. }
  26. CCertDBRestore::~CCertDBRestore()
  27. {
  28. DBGCODE(InterlockedDecrement(&g_cCertDBRestore));
  29. _Cleanup();
  30. }
  31. VOID
  32. CCertDBRestore::_Cleanup()
  33. {
  34. }
  35. HRESULT
  36. CCertDBRestore::RecoverAfterRestore(
  37. IN DWORD cSession,
  38. IN DWORD DBFlags,
  39. IN WCHAR const *pwszEventSource,
  40. IN WCHAR const *pwszLogDir,
  41. IN WCHAR const *pwszSystemDir,
  42. IN WCHAR const *pwszTempDir,
  43. IN WCHAR const *pwszCheckPointFile,
  44. IN WCHAR const *pwszLogPath,
  45. IN CSEDB_RSTMAPW rgrstmap[],
  46. IN LONG crstmap,
  47. IN WCHAR const *pwszBackupLogPath,
  48. IN DWORD genLow,
  49. IN DWORD genHigh)
  50. {
  51. HRESULT hr;
  52. LONG i;
  53. char *pszCheckPointFile = NULL;
  54. char *pszLogPath = NULL;
  55. char *pszBackupLogPath = NULL;
  56. JET_RSTMAP *arstmap = NULL;
  57. JET_INSTANCE Instance = 0;
  58. // Call into JET to let it munge the databases. Note that the JET
  59. // interpretation of LogPath and BackupLogPath is totally wierd, and we
  60. // want to pass in LogPath to both parameters.
  61. hr = E_OUTOFMEMORY;
  62. if ((NULL != pwszCheckPointFile &&
  63. !ConvertWszToSz(&pszCheckPointFile, pwszCheckPointFile, -1)) ||
  64. (NULL != pwszLogPath &&
  65. !ConvertWszToSz(&pszLogPath, pwszLogPath, -1)) ||
  66. (NULL != pwszBackupLogPath &&
  67. !ConvertWszToSz(&pszBackupLogPath, pwszBackupLogPath, -1)))
  68. {
  69. _JumpError(hr, error, "ConvertWszToSz");
  70. }
  71. arstmap = (JET_RSTMAP *) LocalAlloc(
  72. LMEM_FIXED | LMEM_ZEROINIT,
  73. crstmap * sizeof(*arstmap));
  74. if (NULL == arstmap)
  75. {
  76. _JumpError(hr, error, "ConvertWszToSz");
  77. }
  78. for (i = 0; i < crstmap; i++)
  79. {
  80. if (!ConvertWszToSz(
  81. &arstmap[i].szDatabaseName,
  82. rgrstmap[i].pwszDatabaseName,
  83. -1) ||
  84. !ConvertWszToSz(
  85. &arstmap[i].szNewDatabaseName,
  86. rgrstmap[i].pwszNewDatabaseName,
  87. -1))
  88. {
  89. _JumpError(hr, error, "ConvertWszToSz");
  90. }
  91. }
  92. hr = DBInitParms(
  93. cSession,
  94. DBFlags,
  95. pwszEventSource,
  96. pwszLogDir,
  97. pwszSystemDir,
  98. pwszTempDir,
  99. &Instance);
  100. _JumpIfError(hr, error, "DBInitParms");
  101. hr = _dbgJetExternalRestore(
  102. pszCheckPointFile,
  103. pszLogPath,
  104. arstmap,
  105. crstmap,
  106. pszLogPath,
  107. genLow,
  108. genHigh,
  109. NULL);
  110. hr = myJetHResult(hr);
  111. _JumpIfError(hr, error, "JetExternalRestore");
  112. error:
  113. DBFreeParms();
  114. if (NULL != arstmap)
  115. {
  116. for (i = 0; i < crstmap; i++)
  117. {
  118. if (NULL != arstmap[i].szDatabaseName)
  119. {
  120. LocalFree(arstmap[i].szDatabaseName);
  121. }
  122. if (NULL != arstmap[i].szNewDatabaseName)
  123. {
  124. LocalFree(arstmap[i].szNewDatabaseName);
  125. }
  126. }
  127. LocalFree(arstmap);
  128. }
  129. if (NULL != pszCheckPointFile)
  130. {
  131. LocalFree(pszCheckPointFile);
  132. }
  133. if (NULL != pszLogPath)
  134. {
  135. LocalFree(pszLogPath);
  136. }
  137. if (NULL != pszBackupLogPath)
  138. {
  139. LocalFree(pszBackupLogPath);
  140. }
  141. return(hr);
  142. }
  143. STDMETHODIMP
  144. CCertDBRestore::InterfaceSupportsErrorInfo(
  145. IN REFIID riid)
  146. {
  147. static const IID *arr[] =
  148. {
  149. &IID_ICertDBRestore,
  150. };
  151. for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++)
  152. {
  153. if (InlineIsEqualGUID(*arr[i], riid))
  154. {
  155. return(S_OK);
  156. }
  157. }
  158. return(S_FALSE);
  159. }