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.

356 lines
8.3 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: csbjet.h
  7. //
  8. // Contents: Cert Server database backup/restore APIs
  9. //
  10. //---------------------------------------------------------------------------
  11. #ifndef __CSBJET_H__
  12. #define __CSBJET_H__
  13. //#include <dsjet.h>
  14. #ifndef MIDL_PASS
  15. //#include <jetbak.h>
  16. #endif
  17. //#include <nspapi.h>
  18. // MIDL 2.0 switched the names of the generated server interface globals (why!?).
  19. // This hack so that we only have to change one place.
  20. // Parameters are interface name, major and minor version numbers.
  21. #if (_MSC_VER > 800)
  22. #define ServerInterface(s, vMaj, vMin) s##_v##vMaj##_##vMin##_s_ifspec
  23. #define ClientInterface(s, vMaj, vMin) s##_v##vMaj##_##vMin##_c_ifspec
  24. #else
  25. #define ServerInterface(s, vMaj, vMin) s##_ServerIfHandle
  26. #define ClientInterface(s, vMaj, vMin) s##_ClientIfHandle
  27. #endif
  28. #define JetBack_ClientIfHandle ClientInterface(ICertDBBackup, 1, 0)
  29. #define JetBack_ServerIfHandle ServerInterface(s_ICertDBBackup, 1, 0)
  30. #define JetRest_ClientIfHandle ClientInterface(ICertDBRestore, 1, 0)
  31. #define JetRest_ServerIfHandle ServerInterface(s_ICertDBRestore, 1, 0)
  32. #define MAX_SOCKETS 10
  33. #define wszRESTORE_IN_PROGRESS L"\\Restore in Progress"
  34. #define wszRESTORE_STATUS L"RestoreStatus"
  35. #define wszBACKUP_LOG_PATH L"BackupLogPath"
  36. #define wszCHECKPOINT_FILE_PATH L"CheckpointFilePath"
  37. #define wszLOG_PATH L"LogPath"
  38. #define wszHIGH_LOG_NUMBER L"HighLog Number"
  39. #define wszLOW_LOG_NUMBER L"LowLog Number"
  40. #define wszJET_RSTMAP_NAME L"Certificate_Server_NTDS_RstMap"
  41. #define wszJET_RSTMAP_SIZE L"Certificate_Server_NTDS_RstMap Size"
  42. #define wszJET_DATABASE_RECOVERED L"Certificate_Server_NTDS Database recovered"
  43. #define wszBACKUP_INFO L"SYSTEM\\CurrentControlSet\\Services\\CertSvc\\Configuration\\BackupInformation\\"
  44. #define wszLAST_BACKUP_LOG L"Last Backup Log"
  45. #define wszDISABLE_LOOPBACK L"DisableLoopback"
  46. #define wszENABLE_TRACE L"Enable Trace"
  47. // Sockets protocol value.
  48. typedef INT PROTVAL;
  49. #define wszLOOPBACKED_READ_EVENT_NAME L"Certificate Server Backup Loopbacked Read Event - %d"
  50. #define wszLOOPBACKED_WRITE_EVENT_NAME L"Certificate Server Backup Loopbacked Write Event - %d"
  51. #define wszLOOPBACKED_CRITSEC_MUTEX_NAME L"Certificate Server Backup Loopbacked Critical Section - %d"
  52. #define wszLOOPBACKED_SHARED_REGION L"Certificate Server Backup Shared Memory Region - %d"
  53. #define READAHEAD_MULTIPLIER 5
  54. #ifdef DEBUG
  55. #define BACKUP_WAIT_TIMEOUT 10*60*1000
  56. #else
  57. #define BACKUP_WAIT_TIMEOUT 2*60*1000
  58. #endif
  59. typedef volatile struct {
  60. DWORD cbSharedBuffer;
  61. DWORD cbPage; // Convenient place to store page size
  62. DWORD dwReadPointer; // Read offset within shared buffer.
  63. DWORD dwWritePointer; // Write offset within buffer.
  64. LONG cbReadDataAvailable; // Number of bytes of data available.
  65. HRESULT hrApi; // Status of API - used to communicate to server if client fails.
  66. BOOLEAN fReadBlocked; // Read operation is blocked
  67. BOOLEAN fWriteBlocked; // Write operation is blocked
  68. } JETBACK_SHARED_HEADER;
  69. typedef struct {
  70. HANDLE hSharedMemoryMapping;
  71. HANDLE heventRead;
  72. HANDLE heventWrite;
  73. HANDLE hmutexSection;
  74. JETBACK_SHARED_HEADER *pjshSection;
  75. } JETBACK_SHARED_CONTROL;
  76. // Client side context.
  77. typedef struct _CSBACKUPCONTEXT {
  78. handle_t hBinding;
  79. HCSCTX csctx;
  80. BOOLEAN fLoopbacked;
  81. BOOLEAN fUseSockets;
  82. BOOLEAN fUseSharedMemory;
  83. // Socket support.
  84. SOCKET rgsockSocketHandles[MAX_SOCKETS];
  85. PROTVAL rgprotvalProtocolsUsed[MAX_SOCKETS];
  86. LONG cSockets;
  87. SOCKET sock;
  88. HANDLE hReadThread;
  89. DWORD tidThreadId;
  90. HANDLE hPingThread; // Keep alive thread for loopbacked backups.
  91. DWORD tidThreadIdPing; // And thread ID for that thread.
  92. HRESULT hrApiStatus;
  93. // Shared memory support.
  94. JETBACK_SHARED_CONTROL jsc;
  95. } CSBACKUPCONTEXT;
  96. #if 0
  97. typedef DWORD
  98. (*PRESTORE_DATABASE_LOCATIONS)(
  99. OUT CHAR rgLocationBuffer[],
  100. OUT PULONG pulLocationSize,
  101. OUT char rgRegistryBase[],
  102. OUT ULONG cbRegistryBase,
  103. OUT BOOL *pfCircularLogging);
  104. typedef DWORD
  105. (*PRESTORE_PERFORM_RESTORE)(
  106. CHAR *pszLogPath,
  107. CHAR *pszBackupLogPath,
  108. LONG crstmap,
  109. JET_RSTMAP rgrstmap[]);
  110. #endif
  111. // Server side context binding - the server context handle points to a
  112. // structure containing this information.
  113. typedef struct _JETBACK_SERVER_CONTEXT {
  114. BOOL fRestoreOperation;
  115. union {
  116. struct {
  117. //JET_HANDLE hFile;
  118. HANDLE hFile;
  119. BOOL fHandleIsValid;
  120. LONG cbReadHint;
  121. SOCKET sockClient;
  122. LARGE_INTEGER liFileSize;
  123. DWORD dwHighestLogNumber;
  124. WCHAR *pwszBackupAnnotation;
  125. DWORD dwFileSystemGranularity;
  126. BOOLEAN fUseSockets;
  127. BOOLEAN fUseSharedMemory;
  128. BOOLEAN fBackupIsRegistered;
  129. // Client identifer used to identify the client to the server - we
  130. // use this when opening the shared memory segment on local backup.
  131. DWORD dwClientIdentifier;
  132. JETBACK_SHARED_CONTROL jsc;
  133. } Backup;
  134. struct {
  135. BOOL fJetCompleted;
  136. LONG cUnitDone;
  137. LONG cUnitTotal;
  138. } Restore;
  139. } u;
  140. } JETBACK_SERVER_CONTEXT;
  141. // Server side private routines.
  142. VOID
  143. GetCurrentSid(
  144. PSID *ppsid);
  145. BOOL
  146. FBackupServerAccessCheck(
  147. BOOL fRestoreOperation);
  148. DWORD
  149. ErrAdjustRestorePrivelege(
  150. BOOL fEnable,
  151. PTOKEN_PRIVILEGES ptpPrevious,
  152. DWORD *pcbptpPrevious);
  153. #if 0
  154. HRESULT
  155. HrFromJetErr(
  156. JET_ERR jetError);
  157. #endif
  158. HRESULT
  159. HrDestroyCxh(
  160. HCSCTX csctx);
  161. BOOL
  162. FIsAbsoluteFileName(
  163. CHAR *pszFileName);
  164. HRESULT
  165. HrAnnotateMungedFileList(
  166. JETBACK_SERVER_CONTEXT *pjsc,
  167. WCHAR *wszFileList,
  168. LONG cbFileList,
  169. WCHAR **pwszAnnotatedList,
  170. LONG *pcbAnnotatedList);
  171. HRESULT
  172. HrMungedFileNamesFromJetFileNames(
  173. WCHAR **ppwszMungedList,
  174. LONG *pcbSize,
  175. CHAR *pszJetAttachmentList,
  176. LONG cbJetSize,
  177. BOOL fAnnotated);
  178. HRESULT
  179. HrMungedFileNameFromJetFileName(
  180. CHAR *pszJetFileName,
  181. WCHAR **ppwszMungedFileName);
  182. HRESULT
  183. HrJetFileNameFromMungedFileName(
  184. WCHAR *pwszMungedList,
  185. CHAR **ppszJetFileName);
  186. VOID
  187. RestoreRundown(
  188. JETBACK_SERVER_CONTEXT *pjsc);
  189. // Client side private routines.
  190. HRESULT
  191. HrCreateRpcBinding(
  192. IN LONG iszProtoseq,
  193. IN WCHAR const *pwszServer,
  194. OUT handle_t *phBinding);
  195. HRESULT
  196. HrJetbpConnectToBackupServer(
  197. WCHAR *pwszBackupServer,
  198. WCHAR *pwszBackupAnnotation,
  199. RPC_IF_HANDLE rifHandle,
  200. RPC_BINDING_HANDLE *prbhBinding);
  201. BOOL
  202. FBackupClientAccessCheck(
  203. BOOL fRestoreOperation);
  204. BOOL
  205. FIsInBackupGroup(
  206. BOOL fRestoreOperation);
  207. extern WCHAR *g_apszProtSeq[];
  208. extern long g_cProtSeq;
  209. BOOL
  210. FInitializeRestore();
  211. BOOL
  212. FUninitializeRestore();
  213. // Sockets related APIs and prototypes.
  214. HRESULT
  215. HrCreateBackupSockets(
  216. SOCKET rgsockSocketHandles[],
  217. PROTVAL rgprotvalProtocolsUsed[],
  218. LONG *pcSocketHandles);
  219. SOCKET
  220. SockWaitForConnections(
  221. SOCKET rgsockSocketHandles[],
  222. LONG cSocketMax);
  223. SOCKET
  224. SockConnectToRemote(
  225. SOCKADDR rgsockaddrClient[],
  226. LONG cSocketMax);
  227. HRESULT
  228. HrSockAddrsFromSocket(
  229. OUT SOCKADDR sockaddr[],
  230. OUT LONG *pcSockets,
  231. IN SOCKET sock,
  232. IN PROTVAL protval);
  233. BOOL
  234. FInitializeSocketClient();
  235. BOOL
  236. FInitializeSocketServer();
  237. BOOL
  238. FUninitializeSocketClient();
  239. BOOL
  240. FUninitializeSocketServer();
  241. HRESULT
  242. I_HrRestoreW(
  243. HCSBC hcsbc,
  244. WCHAR *pwszCheckpointFilePath,
  245. WCHAR *pwszLogPath,
  246. CSEDB_RSTMAPW __RPC_FAR rgrstmap[],
  247. LONG crstmap,
  248. WCHAR *pwszBackupLogPath,
  249. unsigned long genLow,
  250. unsigned long genHigh,
  251. BOOLEAN *pfRecoverJetDatabase);
  252. HRESULT
  253. I_HrCheckBackupLogs(
  254. WCHAR *wszBackupAnnotation);
  255. BOOLEAN
  256. FIsLoopbackedBinding(
  257. RPC_BINDING_HANDLE hBinding);
  258. BOOLEAN
  259. FCreateSharedMemorySection(
  260. JETBACK_SHARED_CONTROL *pjsc,
  261. DWORD dwClientIdentifier,
  262. BOOLEAN fClientOperation,
  263. LONG cbSharedMemory);
  264. VOID
  265. CloseSharedControl(
  266. JETBACK_SHARED_CONTROL *pjsc);
  267. #if DBG
  268. BOOL GetTextualSid(
  269. PSID pSid, // binary Sid
  270. LPTSTR TextualSid, // buffer for Textual representaion of Sid
  271. LPDWORD dwBufferLen); // required/provided TextualSid buffersize
  272. VOID
  273. OpenTraceLogFile(VOID);
  274. BOOL
  275. FInitializeTraceLog(VOID);
  276. VOID
  277. UninitializeTraceLog(VOID);
  278. NET_API_STATUS
  279. TruncateLog(VOID);
  280. #endif // DBG
  281. #define hrCommunicationError CO_E_REMOTE_COMMUNICATION_FAILURE
  282. #define hrCouldNotConnect HRESULT_FROM_WIN32(ERROR_CONNECTION_REFUSED)
  283. #endif // __CSBJET_H__