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.

212 lines
4.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1999
  5. //
  6. // File: tlsbkup.cpp
  7. //
  8. // Contents:
  9. // Backup/restore of database
  10. //
  11. // History:
  12. // 5/28/99 Created RobLeit
  13. //---------------------------------------------------------------------------
  14. #include "pch.cpp"
  15. #include "globals.h"
  16. #include "init.h"
  17. extern "C" VOID ServiceStop();
  18. static BOOL g_fDoingBackupRestore = FALSE;
  19. static CCriticalSection g_csBackupRestore;
  20. ////////////////////////////////////////////////////////////////////////////
  21. extern "C" HRESULT WINAPI
  22. ExportTlsDatabase(
  23. )
  24. /*++
  25. --*/
  26. {
  27. RPC_STATUS rpcStatus;
  28. HRESULT hr = S_OK;
  29. TCHAR szExportedDb[MAX_PATH+1];
  30. if (g_fDoingBackupRestore)
  31. {
  32. return HRESULT_FROM_WIN32(ERROR_BUSY);
  33. }
  34. g_csBackupRestore.Lock();
  35. if (g_fDoingBackupRestore)
  36. {
  37. g_csBackupRestore.UnLock();
  38. return HRESULT_FROM_WIN32(ERROR_BUSY);
  39. }
  40. // ignore all call if service is shutting down
  41. if( IsServiceShuttingdown() == TRUE )
  42. {
  43. g_csBackupRestore.UnLock();
  44. return HRESULT_FROM_WIN32(ERROR_BUSY);
  45. }
  46. g_fDoingBackupRestore = TRUE;
  47. // Tell RPC threads to stop handling clients
  48. ServiceSignalShutdown();
  49. // Stop listening to other RPC interfaces
  50. (VOID)RpcServerUnregisterIf(TermServLicensing_v1_0_s_ifspec,
  51. NULL, // UUID
  52. TRUE); // Wait for calls to complete
  53. (VOID)RpcServerUnregisterIf(HydraLicenseService_v1_0_s_ifspec,
  54. NULL, // UUID
  55. TRUE); // Wait for calls to complete
  56. // Release handles to database
  57. TLSPrepareForBackupRestore();
  58. _tcscpy(szExportedDb,g_szDatabaseDir);
  59. _tcscat(szExportedDb,TLSBACKUP_EXPORT_DIR);
  60. CreateDirectoryEx(g_szDatabaseDir,
  61. szExportedDb,
  62. NULL); // Ignore errors, they'll show up in CopyFile
  63. _tcscat(szExportedDb, _TEXT("\\"));
  64. _tcscat(szExportedDb,g_szDatabaseFname);
  65. // Copy database file
  66. if (!CopyFile(g_szDatabaseFile,szExportedDb,FALSE))
  67. {
  68. hr = HRESULT_FROM_WIN32(GetLastError());
  69. goto cleanup;
  70. }
  71. cleanup:
  72. // Restart RPC and work manager
  73. ServiceResetShutdownEvent();
  74. // Restart after backup
  75. hr = TLSRestartAfterBackupRestore(TRUE);
  76. if( ERROR_SUCCESS != hr )
  77. {
  78. // force a shutdown...
  79. ServiceSignalShutdown();
  80. ServiceStop();
  81. }
  82. else
  83. {
  84. // Begin listening again
  85. RpcServerRegisterIf(TermServLicensing_v1_0_s_ifspec,
  86. NULL,
  87. NULL);
  88. RpcServerRegisterIf(HydraLicenseService_v1_0_s_ifspec,
  89. NULL,
  90. NULL);
  91. }
  92. g_fDoingBackupRestore = FALSE;
  93. g_csBackupRestore.UnLock();
  94. return hr;
  95. }
  96. ////////////////////////////////////////////////////////////////////////////
  97. extern "C" HRESULT WINAPI
  98. ImportTlsDatabase(
  99. )
  100. /*++
  101. --*/
  102. {
  103. HRESULT hr = S_OK;
  104. if (g_fDoingBackupRestore)
  105. {
  106. return HRESULT_FROM_WIN32(ERROR_BUSY);
  107. }
  108. g_csBackupRestore.Lock();
  109. if (g_fDoingBackupRestore)
  110. {
  111. g_csBackupRestore.UnLock();
  112. return HRESULT_FROM_WIN32(ERROR_BUSY);
  113. }
  114. // ignore all call if service is shutting down
  115. if( IsServiceShuttingdown() == TRUE )
  116. {
  117. g_csBackupRestore.UnLock();
  118. return HRESULT_FROM_WIN32(ERROR_BUSY);
  119. }
  120. g_fDoingBackupRestore = TRUE;
  121. // Tell RPC threads to stop handling clients
  122. ServiceSignalShutdown();
  123. // Stop listening to other RPC interfaces
  124. (VOID)RpcServerUnregisterIf(TermServLicensing_v1_0_s_ifspec,
  125. NULL, // UUID
  126. TRUE); // Wait for calls to complete
  127. (VOID)RpcServerUnregisterIf(HydraLicenseService_v1_0_s_ifspec,
  128. NULL, // UUID
  129. TRUE); // Wait for calls to complete
  130. TLSPrepareForBackupRestore();
  131. // Restart RPC
  132. ServiceResetShutdownEvent();
  133. // not restart after backup
  134. hr = TLSRestartAfterBackupRestore(FALSE);
  135. if( ERROR_SUCCESS != hr )
  136. {
  137. // force a shutdown...
  138. ServiceSignalShutdown();
  139. ServiceStop();
  140. }
  141. else
  142. {
  143. // Begin listening again
  144. RpcServerRegisterIf(TermServLicensing_v1_0_s_ifspec,
  145. NULL,
  146. NULL);
  147. RpcServerRegisterIf(HydraLicenseService_v1_0_s_ifspec,
  148. NULL,
  149. NULL);
  150. }
  151. g_fDoingBackupRestore = FALSE;
  152. g_csBackupRestore.UnLock();
  153. return hr;
  154. }