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.

728 lines
22 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. ntdsbcli.h
  5. Abstract:
  6. This header contains the interface definition for the NT Directory Service
  7. Backup Client APIs.
  8. Environment:
  9. User Mode - Win32
  10. Notes:
  11. --*/
  12. #ifndef _NTDSBCLI_H_
  13. #define _NTDSBCLI_H_
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #ifdef MIDL_PASS
  21. #define xRPC_STRING [string]
  22. #else
  23. #define xRPC_STRING
  24. #if !defined(_NATIVE_WCHAR_T_DEFINED)
  25. typedef unsigned short WCHAR;
  26. #else
  27. typedef wchar_t WCHAR;
  28. #endif
  29. #endif
  30. #ifndef _NTDSBCLI_DEFINED
  31. #define NTDSBCLI_API __declspec(dllimport) _stdcall
  32. #else
  33. #define NTDSBCLI_API
  34. #endif
  35. // HRESULT should be defined if the user included ntdef.h or winnt.h or wtypes.h
  36. // Define it anyways just in case it is not defined yet
  37. #ifndef _HRESULT_DEFINED
  38. #define _HRESULT_DEFINED
  39. typedef LONG HRESULT;
  40. #endif // _HRESULT_DEFINED
  41. #define g_wszBackupAnnotation L"NTDS Backup Interface"
  42. #define g_aszBackupAnnotation "NTDS Backup Interface"
  43. #define g_wszRestoreAnnotation L"NTDS Restore Interface"
  44. #define g_aszRestoreAnnotation "NTDS Restore Interface"
  45. #ifdef UNICODE
  46. #define g_szBackupAnnotation g_wszBackupAnnotation
  47. #define g_szRestoreAnnotation g_wszRestoreAnnotation
  48. #else
  49. #define g_szBackupAnnotation g_aszBackupAnnotation
  50. #define g_szRestoreAnnotation g_aszRestoreAnnotation
  51. #endif // UNICODE
  52. // Type of Backup passed to DsBackupPrepare()
  53. // BACKUP_TYPE_FULL: Requesting backup of the complete DS (DIT, Log files, and Patch files)
  54. // BACKUP_TYPE_LOGS_ONLY: Requesting backup of only the log files
  55. // BACKUP_TYPE_INCREMENTAL: Requesting incremental backup i.e. backing up only changes that happened since last backup
  56. #define BACKUP_TYPE_FULL 0x01
  57. #define BACKUP_TYPE_LOGS_ONLY 0x02
  58. #define BACKUP_TYPE_INCREMENTAL 0x04 // not supported in product1
  59. // Type of Restore passed to DsRestorePrepare()
  60. // RESTORE_TYPE_AUTHORATATIVE: The restored version wins throughout the enterprise
  61. // RESTORE_TYPE_ONLINE: Restoration is done when NTDS is online.
  62. // RESTORE_TYPE_CATCHUP: The restored version is reconciled through the standard reconciliation logic so that the
  63. // restored DIT can catchup with the rest of the enterprise.
  64. #define RESTORE_TYPE_AUTHORATATIVE 0x01
  65. #define RESTORE_TYPE_ONLINE 0x02 // not supported in product1
  66. #define RESTORE_TYPE_CATCHUP 0x04 // this is the default restore mode
  67. // Setting the current log # to this value would disable incremental/differential backup
  68. #define BACKUP_DISABLE_INCREMENTAL 0xffffffff
  69. // BFT is the bit flag used to represent file types (directory/dit/logfile/etc.)
  70. // We keep them as a character so that we can append/prepend them to the actual file
  71. // path. The code in the Backup API's rely on the fact that values 0-256 in 8 bit ascii
  72. // map to the values 0-256 in unicode.
  73. #ifdef UNICODE
  74. typedef WCHAR BFT;
  75. #else
  76. typedef CHAR BFT;
  77. #endif
  78. // Bit flags:
  79. // BFT_DIRECTORY - indicates path specified is a directory
  80. // BFT_DATABASE_DIRECTORY - indicates that file goes into database directory
  81. // BFT_LOG_DIRECTORY - indicates that the file goes into log directory
  82. #define BFT_DIRECTORY 0x80
  83. #define BFT_DATABASE_DIRECTORY 0x40
  84. #define BFT_LOG_DIRECTORY 0x20
  85. // Following combinations are defined for easy use of the filetype and the directory into
  86. // into which it goes
  87. #define BFT_LOG (BFT)(TEXT('\x01') | BFT_LOG_DIRECTORY)
  88. #define BFT_LOG_DIR (BFT)(TEXT('\x02') | BFT_DIRECTORY)
  89. #define BFT_CHECKPOINT_DIR (BFT)(TEXT('\x03') | BFT_DIRECTORY)
  90. #define BFT_NTDS_DATABASE (BFT)(TEXT('\x04') | BFT_DATABASE_DIRECTORY)
  91. #define BFT_PATCH_FILE (BFT)(TEXT('\x05') | BFT_LOG_DIRECTORY)
  92. #define BFT_UNKNOWN (BFT)(TEXT('\x0f'))
  93. #include <ntdsbmsg.h>
  94. // Backup Context Handle
  95. typedef void *HBC;
  96. typedef struct tagEDB_RSTMAPA
  97. {
  98. xRPC_STRING char *szDatabaseName;
  99. xRPC_STRING char *szNewDatabaseName;
  100. } EDB_RSTMAPA, *PEDB_RSTMAPA; /* restore map */
  101. // required for NTDS unicode support.
  102. // UNDONE: NYI
  103. #define UNICODE_RSTMAP
  104. typedef struct tagEDB_RSTMAPW {
  105. xRPC_STRING WCHAR *wszDatabaseName;
  106. xRPC_STRING WCHAR *wszNewDatabaseName;
  107. } EDB_RSTMAPW, *PEDB_RSTMAPW;
  108. #ifdef UNICODE
  109. #define EDB_RSTMAP EDB_RSTMAPW
  110. #define PEDB_RSTMAP PEDB_RSTMAPW
  111. #else
  112. #define EDB_RSTMAP EDB_RSTMAPA
  113. #define PEDB_RSTMAP PEDB_RSTMAPA
  114. #endif
  115. // For all the functions in this interface that have atleast one string
  116. // parameter provide macros to invoke the appropriate version of the
  117. // corresponding function.
  118. #ifdef UNICODE
  119. #define DsIsNTDSOnline DsIsNTDSOnlineW
  120. #define DsBackupPrepare DsBackupPrepareW
  121. #define DsBackupGetDatabaseNames DsBackupGetDatabaseNamesW
  122. #define DsBackupOpenFile DsBackupOpenFileW
  123. #define DsBackupGetBackupLogs DsBackupGetBackupLogsW
  124. #define DsRestoreGetDatabaseLocations DsRestoreGetDatabaseLocationsW
  125. #define DsRestorePrepare DsRestorePrepareW
  126. #define DsRestoreRegister DsRestoreRegisterW
  127. #define DsSetCurrentBackupLog DsSetCurrentBackupLogW
  128. #define DsSetAuthIdentity DsSetAuthIdentityW
  129. #else
  130. #define DsIsNTDSOnline DsIsNTDSOnlineA
  131. #define DsBackupPrepare DsBackupPrepareA
  132. #define DsBackupGetDatabaseNames DsBackupGetDatabaseNamesA
  133. #define DsBackupOpenFile DsBackupOpenFileA
  134. #define DsBackupGetBackupLogs DsBackupGetBackupLogsA
  135. #define DsRestoreGetDatabaseLocations DsRestoreGetDatabaseLocationsA
  136. #define DsRestorePrepare DsRestorePrepareA
  137. #define DsRestoreRegister DsRestoreRegisterA
  138. #define DsSetCurrentBackupLog DsSetCurrentBackupLogA
  139. #define DsSetAuthIdentity DsSetAuthIdentityA
  140. #endif // #ifdef UNICODE
  141. /*************************************************************************************
  142. Routine Description:
  143. DsIsNTDSOnline
  144. Checks to see if the NTDS is Online on the given server. This call is
  145. guaranteed to return quickly.
  146. Arguments:
  147. [in] szServerName - UNC name of the server to check
  148. [out] pfNTDSOnline - pointer to receive the bool result (TRUE if NTDS is
  149. online; FALSE, otherwise)
  150. Return Value:
  151. ERROR_SUCCESS if the call executed successfully;
  152. Failure code otherwise.
  153. **************************************************************************************/
  154. HRESULT
  155. NTDSBCLI_API
  156. DsIsNTDSOnlineA(
  157. LPCSTR szServerName,
  158. BOOL *pfNTDSOnline
  159. );
  160. HRESULT
  161. NTDSBCLI_API
  162. DsIsNTDSOnlineW(
  163. LPCWSTR szServerName,
  164. BOOL *pfNTDSOnline
  165. );
  166. /*************************************************************************************
  167. Routine Description:
  168. DsBackupPrepare
  169. Prepares the DS for the online backup and returns a Backup Context Handle
  170. which should be used in the subsequent calls to other backup functions.
  171. Arguments:
  172. [in] szBackupServer - UNC name of the server to be prepared for online backup
  173. [in] grbit - flag to be passed to jet while backing up dbs
  174. [in] btFlag - BACKUP_TYPE_FULL or BACKUP_TYPE_LOGS_ONLY
  175. [out] ppvExpiryToken - pointer that will receive the pointer to the
  176. Expiry Token associated with this backup; Client should save
  177. this token and send it back through DsRestorePrepare() when
  178. attempting a restore; allocated memory should be freed using
  179. DsBackupFree() API by the caller when it is no longer needed.
  180. [out] pcbExpiryTokenSize - pointer to receive the size of the expiry token
  181. returned.
  182. [out] phbc - pointer that will receive the backup context handle
  183. Return Value:
  184. One of the standard HRESULT success codes;
  185. Failure code otherwise.
  186. **************************************************************************************/
  187. HRESULT
  188. NTDSBCLI_API
  189. DsBackupPrepareA(
  190. LPCSTR szBackupServer,
  191. ULONG grbit,
  192. ULONG btFlag,
  193. PVOID *ppvExpiryToken,
  194. LPDWORD pcbExpiryTokenSize,
  195. HBC *phbc
  196. );
  197. HRESULT
  198. NTDSBCLI_API
  199. DsBackupPrepareW(
  200. LPCWSTR szBackupServer,
  201. ULONG grbit,
  202. ULONG btFlag,
  203. PVOID *ppvExpiryToken,
  204. LPDWORD pcbExpiryTokenSize,
  205. HBC *phbc
  206. );
  207. /*************************************************************************************
  208. Routine Description:
  209. DsBackupGetDatabaseNames
  210. Gives the list of data bases that need to be backed up for the given
  211. backup context
  212. Arguments:
  213. [in] hbc - backup context handle
  214. [out] pszAttachmentInfo - pointer that will receive the pointer to the attachment
  215. info; allocated memory should be freed using DsBackupFree() API by the
  216. caller when it is no longer needed; Attachment info is an array of
  217. null-terminated filenames and and the list is terminated by two-nulls.
  218. [out] pcbSize - will receive the number of bytes returned
  219. Return Value:
  220. One of the standard HRESULT success codes;
  221. Failure code otherwise.
  222. **************************************************************************************/
  223. HRESULT
  224. NTDSBCLI_API
  225. DsBackupGetDatabaseNamesA(
  226. HBC hbc,
  227. LPSTR *pszAttachmentInfo,
  228. LPDWORD pcbSize
  229. );
  230. HRESULT
  231. NTDSBCLI_API
  232. DsBackupGetDatabaseNamesW(
  233. HBC hbc,
  234. LPWSTR *pszAttachmentInfo,
  235. LPDWORD pcbSize
  236. );
  237. /*************************************************************************************
  238. Routine Description:
  239. DsBackupOpenFile
  240. Opens the given attachment for read.
  241. Arguments:
  242. [in] hbc - backup context handle
  243. [in] szAttachmentName - name of the attachment to be opened for read
  244. [in] cbReadHintSize - suggested size in bytes that might be used during the
  245. subsequent reads on this attachement
  246. [out] pliFileSize - pointer to a large integer that would receive the size in
  247. bytes of the given attachment
  248. Return Value:
  249. One of the standard HRESULT success codes;
  250. Failure code otherwise.
  251. **************************************************************************************/
  252. HRESULT
  253. NTDSBCLI_API
  254. DsBackupOpenFileA(
  255. HBC hbc,
  256. LPCSTR szAttachmentName,
  257. DWORD cbReadHintSize,
  258. LARGE_INTEGER *pliFileSize
  259. );
  260. HRESULT
  261. NTDSBCLI_API
  262. DsBackupOpenFileW(
  263. HBC hbc,
  264. LPCWSTR szAttachmentName,
  265. DWORD cbReadHintSize,
  266. LARGE_INTEGER *pliFileSize
  267. );
  268. /*************************************************************************************
  269. Routine Description:
  270. DsBackupRead
  271. Reads the currently open attachment bytes into the given buffer. The client
  272. application is expected to call this function repeatedly until it gets the
  273. entire file (the application would have received the file size through the
  274. DsBackupOpenFile() call before.
  275. Arguments:
  276. [in] hbc - backup context handle
  277. [in] pvBuffer - pointer to the buffer that would receive the read data.
  278. [in] cbBuffer - specifies the size of the above buffer
  279. [out] pcbRead - pointer to receive the actual number of bytes read.
  280. Return Value:
  281. One of the standard HRESULT success codes;
  282. Failure code otherwise.
  283. **************************************************************************************/
  284. HRESULT
  285. NTDSBCLI_API
  286. DsBackupRead(
  287. HBC hbc,
  288. PVOID pvBuffer,
  289. DWORD cbBuffer,
  290. PDWORD pcbRead
  291. );
  292. /*************************************************************************************
  293. Routine Description:
  294. DsBackupClose
  295. To be called by the application after it completes reading all the data in
  296. the currently opened attachement.
  297. Arguments:
  298. [in] hbc - backup context handle
  299. Return Value:
  300. One of the standard HRESULT success codes;
  301. Failure code otherwise.
  302. **************************************************************************************/
  303. HRESULT
  304. NTDSBCLI_API
  305. DsBackupClose(
  306. HBC hbc
  307. );
  308. /*************************************************************************************
  309. Routine Description:
  310. DsBackupGetBackupLogs
  311. Gives the list of log files that need to be backed up for the given
  312. backup context
  313. Arguments:
  314. [in] hbc - backup context handle
  315. [out] pszBackupLogFiles - pointer that will receive the pointer to the list of
  316. log files; allocated memory should be freed using DsBackupFree() API by the
  317. caller when it is no longer needed; Log files are returned in an array of
  318. null-terminated filenames and and the list is terminated by two-nulls.
  319. [out] pcbSize - will receive the number of bytes returned
  320. Return Value:
  321. One of the standard HRESULT success codes;
  322. Failure code otherwise.
  323. **************************************************************************************/
  324. HRESULT
  325. NTDSBCLI_API
  326. DsBackupGetBackupLogsA(
  327. HBC hbc,
  328. LPSTR *pszBackupLogFiles,
  329. LPDWORD pcbSize
  330. );
  331. HRESULT
  332. NTDSBCLI_API
  333. DsBackupGetBackupLogsW(
  334. HBC hbc,
  335. LPWSTR *pszBackupLogFiles,
  336. LPDWORD pcbSize
  337. );
  338. /*************************************************************************************
  339. Routine Description:
  340. DsBackupTruncateLogs
  341. Called to truncate the already read backup logs.
  342. Arguments:
  343. [in] hbc - backup context handle
  344. Return Value:
  345. One of the standard HRESULT success codes;
  346. Failure code otherwise.
  347. **************************************************************************************/
  348. HRESULT
  349. NTDSBCLI_API
  350. DsBackupTruncateLogs(
  351. HBC hbc
  352. );
  353. /*************************************************************************************
  354. Routine Description:
  355. DsBackupEnd
  356. Called to end the current backup session.
  357. Arguments:
  358. [in] hbc - backup context handle of the backup session
  359. Return Value:
  360. One of the standard HRESULT success codes;
  361. Failure code otherwise.
  362. **************************************************************************************/
  363. HRESULT
  364. NTDSBCLI_API
  365. DsBackupEnd(
  366. HBC hbc
  367. );
  368. /*************************************************************************************
  369. Routine Description:
  370. DsBackupFree
  371. Should be used by the application to free any buffer allocated by the
  372. NTDSBCLI dll.
  373. Arguments:
  374. [in] pvBuffer - pointer to the buffer that is to be freed.
  375. Return Value:
  376. None.
  377. **************************************************************************************/
  378. VOID
  379. NTDSBCLI_API
  380. DsBackupFree(
  381. PVOID pvBuffer
  382. );
  383. /*************************************************************************************
  384. Routine Description:
  385. DsRestoreGetDatabaseLocations
  386. Called both at backup time as well at restoration time to get the data base
  387. locations for different types of files.
  388. Arguments:
  389. [in] hbc - backup context handle which would have been obtained through
  390. DsBackupPrepare() in the backup case and through DsRestorePrepare()
  391. in the restore case.
  392. [out] pszDatabaseLocationList - pointer that will receive the pointer to the list of
  393. database locations; allocated memory should be freed using DsBackupFree() API by the
  394. caller when it is no longer needed; locations are returned in an array of
  395. null-terminated names and and the list is terminated by two-nulls.
  396. The first character of each name is the BFT character that indicates the type
  397. of the file and the rest of the name tells gives the path into which that
  398. particular type of file should be restored.
  399. [out] pcbSize - will receive the number of bytes returned
  400. Return Value:
  401. One of the standard HRESULT success codes;
  402. Failure code otherwise.
  403. **************************************************************************************/
  404. HRESULT
  405. NTDSBCLI_API
  406. DsRestoreGetDatabaseLocationsA(
  407. HBC hbc,
  408. LPSTR *pszDatabaseLocationList,
  409. LPDWORD pcbSize
  410. );
  411. HRESULT
  412. NTDSBCLI_API
  413. DsRestoreGetDatabaseLocationsW(
  414. HBC hbc,
  415. LPWSTR *pszDatabaseLocationList,
  416. LPDWORD pcbSize
  417. );
  418. /*************************************************************************************
  419. Routine Description:
  420. DsRestorePrepare
  421. Called to indicate beginning of a restore session.
  422. Arguments:
  423. [in] szServerName - UNC name of the server into which the restore operation is
  424. going to be performed.
  425. [in] rtFlag - Or'ed combination of RESTORE_TYPE_* flags; 0 if no special flags
  426. are to be specified
  427. [in] pvExpiryToken - pointer to the expiry token associated with this
  428. backup. The client would have received this when they backed up the DS.
  429. [in] cbExpiryTokenSize - size of the expiry token.
  430. [out] phbc - pointer to receive the backup context handle which is to be passed
  431. to the subsequent restore APIs
  432. Return Value:
  433. One of the standard HRESULT success codes;
  434. Failure code otherwise.
  435. **************************************************************************************/
  436. HRESULT
  437. NTDSBCLI_API
  438. DsRestorePrepareA(
  439. LPCSTR szServerName,
  440. ULONG rtFlag,
  441. PVOID pvExpiryToken,
  442. DWORD cbExpiryTokenSize,
  443. HBC *phbc
  444. );
  445. HRESULT
  446. NTDSBCLI_API
  447. DsRestorePrepareW(
  448. LPCWSTR szServerName,
  449. ULONG rtFlag,
  450. PVOID pvExpiryToken,
  451. DWORD cbExpiryTokenSize,
  452. HBC *phbc
  453. );
  454. /*************************************************************************************
  455. Routine Description:
  456. DsRestoreRegister
  457. This will register a restore operation. It will interlock all sbsequent restore
  458. operations, and will prevent the restore target from starting until the call
  459. to DsRestoreRegisterComplete() is made.
  460. Arguments:
  461. [in] hbc - backup context handle for the restore session.
  462. [in] szCheckPointFilePath - path where the check point files are restored
  463. [in] szLogPath - path where the log files are restored
  464. [in] rgrstmap - restore map
  465. [in] crstmap - tells if ther is a new restore map
  466. [in] szBackupLogPath - path where the backup logs are located
  467. [in] genLow - Lowest log# that was restored in this restore session
  468. [in] genHigh - Highest log# that was restored in this restore session
  469. Return Value:
  470. One of the standard HRESULT success codes;
  471. Failure code otherwise.
  472. **************************************************************************************/
  473. HRESULT
  474. NTDSBCLI_API
  475. DsRestoreRegisterA(
  476. HBC hbc,
  477. LPCSTR szCheckPointFilePath,
  478. LPCSTR szLogPath,
  479. EDB_RSTMAPA rgrstmap[],
  480. LONG crstmap,
  481. LPCSTR szBackupLogPath,
  482. ULONG genLow,
  483. ULONG genHigh
  484. );
  485. HRESULT
  486. NTDSBCLI_API
  487. DsRestoreRegisterW(
  488. HBC hbc,
  489. LPCWSTR szCheckPointFilePath,
  490. LPCWSTR szLogPath,
  491. EDB_RSTMAPW rgrstmap[],
  492. LONG crstmap,
  493. LPCWSTR szBackupLogPath,
  494. ULONG genLow,
  495. ULONG genHigh
  496. );
  497. /*************************************************************************************
  498. Routine Description:
  499. DsRestoreRegisterComplete
  500. Called to indicate that a previously registered restore is complete.
  501. Arguments:
  502. [in] hbc - backup context handle
  503. [in] hrRestoreState - success code if the restore was successful
  504. Return Value:
  505. One of the standard HRESULT success codes;
  506. Failure code otherwise.
  507. **************************************************************************************/
  508. HRESULT
  509. NTDSBCLI_API
  510. DsRestoreRegisterComplete(
  511. HBC hbc,
  512. HRESULT hrRestoreState
  513. );
  514. /*************************************************************************************
  515. Routine Description:
  516. DsRestoreEnd
  517. Called to end a restore session
  518. Arguments:
  519. [in] hbc - backup context handle
  520. Return Value:
  521. One of the standard HRESULT success codes;
  522. Failure code otherwise.
  523. **************************************************************************************/
  524. HRESULT
  525. NTDSBCLI_API
  526. DsRestoreEnd(
  527. HBC hbc
  528. );
  529. /*************************************************************************************
  530. Routine Description:
  531. DsSetCurrentBackupLog
  532. Called to set the current backup log number after a successful restore
  533. Arguments:
  534. [in] szServerName - UNC name of the server for which the current backup log has
  535. to be set
  536. [in] dwCurrentLog - current log number
  537. Return Value:
  538. One of the standard HRESULT success codes;
  539. Failure code otherwise.
  540. **************************************************************************************/
  541. HRESULT
  542. NTDSBCLI_API
  543. DsSetCurrentBackupLogA(
  544. LPCSTR szServerName,
  545. DWORD dwCurrentLog
  546. );
  547. HRESULT
  548. NTDSBCLI_API
  549. DsSetCurrentBackupLogW(
  550. LPCWSTR szServerName,
  551. DWORD dwCurrentLog
  552. );
  553. /*************************************************************************************
  554. Routine Description:
  555. DsSetAuthIdentity
  556. Used to set the security context under which the client APIs are to be
  557. called. If this function is not called, security context of the current
  558. process is assumed.
  559. Arguments:
  560. [in] szUserName - name of the user
  561. [in] szDomainName - name of the domain the user belongs to
  562. [in] szPassword - password of the user in the specified domain
  563. Return Value:
  564. One of the standard HRESULT success codes;
  565. Failure code otherwise.
  566. **************************************************************************************/
  567. HRESULT
  568. NTDSBCLI_API
  569. DsSetAuthIdentityA(
  570. LPCSTR szUserName,
  571. LPCSTR szDomainName,
  572. LPCSTR szPassword
  573. );
  574. HRESULT
  575. NTDSBCLI_API
  576. DsSetAuthIdentityW(
  577. LPCWSTR szUserName,
  578. LPCWSTR szDomainName,
  579. LPCWSTR szPassword
  580. );
  581. #ifdef __cplusplus
  582. }
  583. #endif
  584. #endif // _NTDSBCLI_H_