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.

201 lines
4.3 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: certdb.cpp
  7. //
  8. // Contents: Cert Server Database Access implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include "pch.cpp"
  12. #pragma hdrstop
  13. #include "db.h"
  14. #include "backup.h"
  15. #include "restore.h"
  16. // for new jet snapshotting
  17. #ifndef _DISABLE_VSS_
  18. #include <vss.h>
  19. #include <vswriter.h>
  20. #include "jetwriter.h"
  21. #endif
  22. #define __dwFILE__ __dwFILE_CERTDB_CERTDB_CPP__
  23. CComModule _Module;
  24. BEGIN_OBJECT_MAP(ObjectMap)
  25. OBJECT_ENTRY(CLSID_CCertDB, CCertDB)
  26. OBJECT_ENTRY(CLSID_CCertDBRestore, CCertDBRestore)
  27. END_OBJECT_MAP()
  28. #ifndef _DISABLE_VSS_
  29. class myVssWriter : public CVssJetWriter
  30. {
  31. public:
  32. // override OnIdentify
  33. bool STDMETHODCALLTYPE OnIdentify(IN IVssCreateWriterMetadata *pMetadata);
  34. };
  35. const GUID cGuidCertSrvWriter = {0x6f5b15b5,0xda24,0x4d88,{0xb7, 0x37, 0x63, 0x06, 0x3e, 0x3a, 0x1f, 0x86}}; // 6f5b15b5-da24-4d88-b737-63063e3a1f86
  36. myVssWriter* g_pWriter = NULL;
  37. // our class overrides a single method (bug 454582)
  38. bool myVssWriter::OnIdentify(IVssCreateWriterMetadata* pMetadata)
  39. {
  40. HRESULT hr;
  41. // specify how we want restore to happen
  42. hr = pMetadata->SetRestoreMethod
  43. (
  44. VSS_RME_RESTORE_AT_REBOOT,
  45. NULL,
  46. NULL,
  47. VSS_WRE_NEVER,
  48. true);
  49. _JumpIfError(hr, error, "SetRestoreMethod");
  50. // generate other metadata
  51. if (!CVssJetWriter::OnIdentify(pMetadata))
  52. {
  53. hr = myHLastError();
  54. _JumpError(hr, error, "::OnIdentify");
  55. }
  56. error:
  57. return (hr == S_OK);
  58. }
  59. #endif
  60. HRESULT
  61. InitGlobalWriterState(VOID)
  62. {
  63. HRESULT hr;
  64. #ifndef _DISABLE_VSS_
  65. if (NULL == g_pWriter && IsWhistler())
  66. {
  67. // create writer object
  68. g_pWriter = new myVssWriter; // CVssJetWriter;
  69. if (NULL == g_pWriter)
  70. {
  71. hr = E_OUTOFMEMORY;
  72. _JumpError(hr, error, "new CVssJetWriter");
  73. }
  74. hr = g_pWriter->Initialize(
  75. cGuidCertSrvWriter, // id of writer
  76. L"Certificate Authority", // name of writer, should match FilesNotToBackup key
  77. TRUE, // system service
  78. TRUE, // bootable state
  79. NULL, // files to include
  80. NULL); // files to exclude
  81. _JumpIfError(hr, error, "CVssJetWriter::Initialize");
  82. }
  83. #endif
  84. hr = S_OK;
  85. #ifndef _DISABLE_VSS_
  86. error:
  87. #endif
  88. return hr;
  89. }
  90. HRESULT
  91. UnInitGlobalWriterState(VOID)
  92. {
  93. #ifndef _DISABLE_VSS_
  94. if (NULL != g_pWriter)
  95. {
  96. g_pWriter->Uninitialize();
  97. delete g_pWriter;
  98. g_pWriter = NULL;
  99. }
  100. #endif
  101. return S_OK;
  102. }
  103. /////////////////////////////////////////////////////////////////////////////
  104. // DLL Entry Point
  105. extern "C"
  106. BOOL WINAPI
  107. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  108. {
  109. switch (dwReason)
  110. {
  111. case DLL_PROCESS_ATTACH:
  112. _Module.Init(ObjectMap, hInstance);
  113. DisableThreadLibraryCalls(hInstance);
  114. break;
  115. case DLL_PROCESS_DETACH:
  116. _Module.Term();
  117. break;
  118. }
  119. return(TRUE); // ok
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. // Used to determine whether the DLL can be unloaded by OLE
  123. STDAPI
  124. DllCanUnloadNow(void)
  125. {
  126. return(_Module.GetLockCount() == 0? S_OK : S_FALSE);
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. // Returns a class factory to create an object of the requested type
  130. STDAPI
  131. DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  132. {
  133. HRESULT hr;
  134. hr = _Module.GetClassObject(rclsid, riid, ppv);
  135. if (S_OK == hr && NULL != *ppv)
  136. {
  137. myRegisterMemFree(*ppv, CSM_NEW | CSM_GLOBALDESTRUCTOR);
  138. }
  139. return(hr);
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. // DllRegisterServer - Adds entries to the system registry
  143. STDAPI
  144. DllRegisterServer(void)
  145. {
  146. // registers object, typelib and all interfaces in typelib
  147. return(_Module.RegisterServer(TRUE));
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. // DllUnregisterServer - Removes entries from the system registry
  151. STDAPI
  152. DllUnregisterServer(void)
  153. {
  154. _Module.UnregisterServer();
  155. return(S_OK);
  156. }