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.

162 lines
3.4 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. CComModule _Module;
  23. BEGIN_OBJECT_MAP(ObjectMap)
  24. OBJECT_ENTRY(CLSID_CCertDB, CCertDB)
  25. OBJECT_ENTRY(CLSID_CCertDBRestore, CCertDBRestore)
  26. END_OBJECT_MAP()
  27. #ifndef _DISABLE_VSS_
  28. const GUID cGuidCertSrvWriter = {0x6f5b15b5,0xda24,0x4d88,{0xb7, 0x37, 0x63, 0x06, 0x3e, 0x3a, 0x1f, 0x86}}; // 6f5b15b5-da24-4d88-b737-63063e3a1f86
  29. CVssJetWriter* g_pWriter = NULL;
  30. #endif
  31. HRESULT
  32. InitGlobalWriterState(VOID)
  33. {
  34. HRESULT hr;
  35. #ifndef _DISABLE_VSS_
  36. if (NULL == g_pWriter && IsWhistler())
  37. {
  38. // create writer object
  39. g_pWriter = new CVssJetWriter;
  40. if (NULL == g_pWriter)
  41. {
  42. hr = E_OUTOFMEMORY;
  43. _JumpError(hr, error, "new CVssJetWriter");
  44. }
  45. hr = g_pWriter->Initialize(
  46. cGuidCertSrvWriter, // id of writer
  47. L"Certificate Server Writer", // name of writer
  48. TRUE, // system service
  49. TRUE, // bootable state
  50. NULL, // files to include
  51. NULL); // files to exclude
  52. _JumpIfError(hr, error, "CVssJetWriter::Initialize");
  53. }
  54. #endif
  55. hr = S_OK;
  56. #ifndef _DISABLE_VSS_
  57. error:
  58. #endif
  59. return hr;
  60. }
  61. HRESULT
  62. UnInitGlobalWriterState(VOID)
  63. {
  64. #ifndef _DISABLE_VSS_
  65. if (NULL != g_pWriter)
  66. {
  67. g_pWriter->Uninitialize();
  68. delete g_pWriter;
  69. g_pWriter = NULL;
  70. }
  71. #endif
  72. return S_OK;
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // DLL Entry Point
  76. extern "C"
  77. BOOL WINAPI
  78. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  79. {
  80. switch (dwReason)
  81. {
  82. case DLL_PROCESS_ATTACH:
  83. _Module.Init(ObjectMap, hInstance);
  84. DisableThreadLibraryCalls(hInstance);
  85. break;
  86. case DLL_PROCESS_DETACH:
  87. _Module.Term();
  88. break;
  89. }
  90. return(TRUE); // ok
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // Used to determine whether the DLL can be unloaded by OLE
  94. STDAPI
  95. DllCanUnloadNow(void)
  96. {
  97. return(_Module.GetLockCount() == 0? S_OK : S_FALSE);
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. // Returns a class factory to create an object of the requested type
  101. STDAPI
  102. DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  103. {
  104. HRESULT hr;
  105. hr = _Module.GetClassObject(rclsid, riid, ppv);
  106. if (S_OK == hr && NULL != *ppv)
  107. {
  108. myRegisterMemFree(*ppv, CSM_NEW | CSM_GLOBALDESTRUCTOR);
  109. }
  110. return(hr);
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // DllRegisterServer - Adds entries to the system registry
  114. STDAPI
  115. DllRegisterServer(void)
  116. {
  117. // registers object, typelib and all interfaces in typelib
  118. return(_Module.RegisterServer(TRUE));
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // DllUnregisterServer - Removes entries from the system registry
  122. STDAPI
  123. DllUnregisterServer(void)
  124. {
  125. _Module.UnregisterServer();
  126. return(S_OK);
  127. }