📄 jwantdsbcli.pas
字号:
{******************************************************************************}
{ }
{ Directory Backup and Restore API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: ntdsbcli.h, released June 2000. The original Pascal }
{ code is: NtDsbCli.pas, released December 2000. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}
unit JwaNtDsbCli;
{$WEAKPACKAGEUNIT}
{$HPPEMIT ''}
{$HPPEMIT '#include ":ntdsbcli.h"'}
{$HPPEMIT ''}
{$I WINDEFINES.INC}
interface
uses
JwaWinType;
const
g_wszBackupAnnotation = 'NTDS Backup Interface';
{$EXTERNALSYM g_wszBackupAnnotation}
g_aszBackupAnnotation = 'NTDS Backup Interface';
{$EXTERNALSYM g_aszBackupAnnotation}
g_wszRestoreAnnotation = 'NTDS Restore Interface';
{$EXTERNALSYM g_wszRestoreAnnotation}
g_aszRestoreAnnotation = 'NTDS Restore Interface';
{$EXTERNALSYM g_aszRestoreAnnotation}
{$IFDEF UNICODE}
g_szBackupAnnotation = g_wszBackupAnnotation;
{$EXTERNALSYM g_szBackupAnnotation}
g_szRestoreAnnotation = g_wszRestoreAnnotation;
{$EXTERNALSYM g_szRestoreAnnotation}
{$ELSE}
g_szBackupAnnotation = g_aszBackupAnnotation;
{$EXTERNALSYM g_szBackupAnnotation}
g_szRestoreAnnotation = g_aszRestoreAnnotation;
{$EXTERNALSYM g_szRestoreAnnotation}
{$ENDIF}
// Type of Backup passed to DsBackupPrepare()
// BACKUP_TYPE_FULL: Requesting backup of the complete DS (DIT, Log files, and Patch files)
// BACKUP_TYPE_LOGS_ONLY: Requesting backup of only the log files
// BACKUP_TYPE_INCREMENTAL: Requesting incremental backup i.e. backing up only changes that happened since last backup
BACKUP_TYPE_FULL = $01;
{$EXTERNALSYM BACKUP_TYPE_FULL}
BACKUP_TYPE_LOGS_ONLY = $02;
{$EXTERNALSYM BACKUP_TYPE_LOGS_ONLY}
BACKUP_TYPE_INCREMENTAL = $04; // not supported in product1
{$EXTERNALSYM BACKUP_TYPE_INCREMENTAL}
// Type of Restore passed to DsRestorePrepare()
// RESTORE_TYPE_AUTHORATATIVE: The restored version wins throughout the enterprise
// RESTORE_TYPE_ONLINE: Restoration is done when NTDS is online.
// RESTORE_TYPE_CATCHUP: The restored version is reconciled through the standard reconciliation logic so that the
// restored DIT can catchup with the rest of the enterprise.
RESTORE_TYPE_AUTHORATATIVE = $01;
{$EXTERNALSYM RESTORE_TYPE_AUTHORATATIVE}
RESTORE_TYPE_ONLINE = $02; // not supported in product1
{$EXTERNALSYM RESTORE_TYPE_ONLINE}
RESTORE_TYPE_CATCHUP = $04; // this is the default restore mode
{$EXTERNALSYM RESTORE_TYPE_CATCHUP}
// Setting the current log # to this value would disable incremental/differential backup
BACKUP_DISABLE_INCREMENTAL = DWORD($ffffffff);
{$EXTERNALSYM BACKUP_DISABLE_INCREMENTAL}
// BFT is the bit flag used to represent file types (directory/dit/logfile/etc.)
// We keep them as a character so that we can append/prepend them to the actual file
// path. The code in the Backup API's rely on the fact that values 0-256 in 8 bit ascii
// map to the values 0-256 in unicode.
type
{$IFDEF UNICODE}
BFT = WCHAR;
{$EXTERNALSYM BFT}
{$ELSE}
BFT = CHAR;
{$EXTERNALSYM BFT}
{$ENDIF}
// Bit flags:
// BFT_DIRECTORY - indicates path specified is a directory
// BFT_DATABASE_DIRECTORY - indicates that file goes into database directory
// BFT_LOG_DIRECTORY - indicates that the file goes into log directory
const
BFT_DIRECTORY = $80;
{$EXTERNALSYM BFT_DIRECTORY}
BFT_DATABASE_DIRECTORY = $40;
{$EXTERNALSYM BFT_DATABASE_DIRECTORY}
BFT_LOG_DIRECTORY = $20;
{$EXTERNALSYM BFT_LOG_DIRECTORY}
// Following combinations are defined for easy use of the filetype and the directory into
// into which it goes
BFT_LOG = BFT($01 or BFT_LOG_DIRECTORY);
BFT_LOG_DIR = BFT($02 or BFT_DIRECTORY);
BFT_CHECKPOINT_DIR = BFT($03 or BFT_DIRECTORY);
BFT_NTDS_DATABASE = BFT($04 or BFT_DATABASE_DIRECTORY);
BFT_PATCH_FILE = BFT($05 or BFT_LOG_DIRECTORY);
BFT_UNKNOWN = BFT($0F);
// #include <ntdsbmsg.h>
// Backup Context Handle
type
HBC = Pointer;
{$EXTERNALSYM HBC}
PEDB_RSTMAPA = ^EDB_RSTMAPA;
{$EXTERNALSYM PEDB_RSTMAPA}
tagEDB_RSTMAPA = record
szDatabaseName: PChar;
szNewDtabaseName: PChar;
end;
{$EXTERNALSYM tagEDB_RSTMAPA}
EDB_RSTMAPA = tagEDB_RSTMAPA;
{$EXTERNALSYM EDB_RSTMAPA}
TEdbRstMapA = EDB_RSTMAPA;
PEdbRstMapA = PEDB_RSTMAPA;
// required for NTDS unicode support.
// UNDONE: NYI
PEDB_RSTMAPW = ^EDB_RSTMAPW;
{$EXTERNALSYM PEDB_RSTMAPW}
tagEDB_RSTMAPW = record
wszDatabaseName: PWCHAR;
wszNewDatabaseName: PWCHAR;
end;
{$EXTERNALSYM tagEDB_RSTMAPW}
EDB_RSTMAPW = tagEDB_RSTMAPW;
{$EXTERNALSYM EDB_RSTMAPW}
TEdbRstMapW = EDB_RSTMAPW;
PEdbRstMapW = PEDB_RSTMAPW;
{$IFDEF UNICODE}
EDB_RSTMAP = EDB_RSTMAPW;
{$EXTERNALSYM EDB_RSTMAP}
PEDB_RSTMAP = PEDB_RSTMAPW;
{$EXTERNALSYM PEDB_RSTMAP}
TEdbRstMap = TEdbRstMapW;
PEdbRstMap = PEdbRstMapW;
{$ELSE}
EDB_RSTMAP = EDB_RSTMAPA;
{$EXTERNALSYM EDB_RSTMAP}
PEDB_RSTMAP = PEDB_RSTMAPA;
{$EXTERNALSYM PEDB_RSTMAP}
TEdbRstMap = TEdbRstMapA;
PEdbRstMap = PEdbRstMapA;
{$ENDIF}
{*************************************************************************************
Routine Description:
DsIsNTDSOnline
Checks to see if the NTDS is Online on the given server. This call is
guaranteed to return quickly.
Arguments:
[in] szServerName - UNC name of the server to check
[out] pfNTDSOnline - pointer to receive the bool result (TRUE if NTDS is
online; FALSE, otherwise)
Return Value:
ERROR_SUCCESS if the call executed successfully;
Failure code otherwise.
**************************************************************************************}
function DsIsNTDSOnlineA(szServerName: LPCSTR; var pfNTDSOnline: BOOL): HRESULT; stdcall;
{$EXTERNALSYM DsIsNTDSOnlineA}
function DsIsNTDSOnlineW(szServerName: LPCWSTR; var pfNTDSOnline: BOOL): HRESULT; stdcall;
{$EXTERNALSYM DsIsNTDSOnlineW}
{$IFDEF UNICODE}
function DsIsNTDSOnline(szServerName: LPCWSTR; var pfNTDSOnline: BOOL): HRESULT; stdcall;
{$EXTERNALSYM DsIsNTDSOnline}
{$ELSE}
function DsIsNTDSOnline(szServerName: LPCSTR; var pfNTDSOnline: BOOL): HRESULT; stdcall;
{$EXTERNALSYM DsIsNTDSOnline}
{$ENDIF}
{*************************************************************************************
Routine Description:
DsBackupPrepare
Prepares the DS for the online backup and returns a Backup Context Handle
which should be used in the subsequent calls to other backup functions.
Arguments:
[in] szBackupServer - UNC name of the server to be prepared for online backup
[in] grbit - flag to be passed to jet while backing up dbs
[in] btFlag - BACKUP_TYPE_FULL or BACKUP_TYPE_LOGS_ONLY
[out] ppvExpiryToken - pointer that will receive the pointer to the
Expiry Token associated with this backup; Client should save
this token and send it back through DsRestorePrepare() when
attempting a restore; allocated memory should be freed using
DsBackupFree() API by the caller when it is no longer needed.
[out] pcbExpiryTokenSize - pointer to receive the size of the expiry token
returned.
[out] phbc - pointer that will receive the backup context handle
Return Value:
One of the standard HRESULT success codes;
Failure code otherwise.
**************************************************************************************}
function DsBackupPrepareA(szBackupServer: LPCSTR; grbit: ULONG; btFlag: ULONG;
var ppvExpiryToken: PVOID; var pcbExpiryTokenSize: DWORD; var phbc: HBC): HRESULT; stdcall;
{$EXTERNALSYM DsBackupPrepareA}
function DsBackupPrepareW(szBackupServer: LPCWSTR; grbit: ULONG; btFlag: ULONG;
var ppvExpiryToken: PVOID; var pcbExpiryTokenSize: DWORD; var phbc: HBC): HRESULT; stdcall;
{$EXTERNALSYM DsBackupPrepareW}
{$IFDEF UNICODE}
function DsBackupPrepare(szBackupServer: LPCWSTR; grbit: ULONG; btFlag: ULONG;
var ppvExpiryToken: PVOID; var pcbExpiryTokenSize: DWORD; var phbc: HBC): HRESULT; stdcall;
{$EXTERNALSYM DsBackupPrepare}
{$ELSE}
function DsBackupPrepare(szBackupServer: LPCSTR; grbit: ULONG; btFlag: ULONG;
var ppvExpiryToken: PVOID; var pcbExpiryTokenSize: DWORD; var phbc: HBC): HRESULT; stdcall;
{$EXTERNALSYM DsBackupPrepare}
{$ENDIF}
{*************************************************************************************
Routine Description:
DsBackupGetDatabaseNames
Gives the list of data bases that need to be backed up for the given
backup context
Arguments:
[in] hbc - backup context handle
[out] pszAttachmentInfo - pointer that will receive the pointer to the attachment
info; allocated memory should be freed using DsBackupFree() API by the
caller when it is no longer needed; Attachment info is an array of
null-terminated filenames and and the list is terminated by two-nulls.
[out] pcbSize - will receive the number of bytes returned
Return Value:
One of the standard HRESULT success codes;
Failure code otherwise.
**************************************************************************************}
function DsBackupGetDatabaseNamesA(hbc: HBC; var pszAttachmentInfo: LPSTR;
var pcbSize: DWORD): HRESULT; stdcall;
{$EXTERNALSYM DsBackupGetDatabaseNamesA}
function DsBackupGetDatabaseNamesW(hbc: HBC; var pszAttachmentInfo: LPWSTR;
var pcbSize: DWORD): HRESULT; stdcall;
{$EXTERNALSYM DsBackupGetDatabaseNamesW}
{$IFDEF UNICODE}
function DsBackupGetDatabaseNames(hbc: HBC; var pszAttachmentInfo: LPWSTR;
var pcbSize: DWORD): HRESULT; stdcall;
{$EXTERNALSYM DsBackupGetDatabaseNames}
{$ELSE}
function DsBackupGetDatabaseNames(hbc: HBC; var pszAttachmentInfo: LPSTR;
var pcbSize: DWORD): HRESULT; stdcall;
{$EXTERNALSYM DsBackupGetDatabaseNames}
{$ENDIF}
{*************************************************************************************
Routine Description:
DsBackupOpenFile
Opens the given attachment for read.
Arguments:
[in] hbc - backup context handle
[in] szAttachmentName - name of the attachment to be opened for read
[in] cbReadHintSize - suggested size in bytes that might be used during the
subsequent reads on this attachement
[out] pliFileSize - pointer to a large integer that would receive the size in
bytes of the given attachment
Return Value:
One of the standard HRESULT success codes;
Failure code otherwise.
**************************************************************************************}
function DsBackupOpenFileA(hbc: HBC; szAttachmentName: LPCSTR; cbReadHintSize: DWORD;
var pliFileSize: LARGE_INTEGER): HRESULT; stdcall;
{$EXTERNALSYM DsBackupOpenFileA}
function DsBackupOpenFileW(hbc: HBC; szAttachmentName: LPCWSTR; cbReadHintSize: DWORD;
var pliFileSize: LARGE_INTEGER): HRESULT; stdcall;
{$EXTERNALSYM DsBackupOpenFileW}
{$IFDEF UNICODE}
function DsBackupOpenFile(hbc: HBC; szAttachmentName: LPCWSTR; cbReadHintSize: DWORD;
var pliFileSize: LARGE_INTEGER): HRESULT; stdcall;
{$EXTERNALSYM DsBackupOpenFile}
{$ELSE}
function DsBackupOpenFile(hbc: HBC; szAttachmentName: LPCSTR; cbReadHintSize: DWORD;
var pliFileSize: LARGE_INTEGER): HRESULT; stdcall;
{$EXTERNALSYM DsBackupOpenFile}
{$ENDIF}
{*************************************************************************************
Routine Description:
DsBackupRead
Reads the currently open attachment bytes into the given buffer. The client
application is expected to call this function repeatedly until it gets the
entire file (the application would have received the file size through the
DsBackupOpenFile() call before.
Arguments:
[in] hbc - backup context handle
[in] pvBuffer - pointer to the buffer that would receive the read data.
[in] cbBuffer - specifies the size of the above buffer
[out] pcbRead - pointer to receive the actual number of bytes read.
Return Value:
One of the standard HRESULT success codes;
Failure code otherwise.
**************************************************************************************}
function DsBackupRead(hbc: HBC; pvBuffer: PVOID; cbBuffer: DWORD; var pcbRead: DWORD): HRESULT; stdcall;
{$EXTERNALSYM DsBackupRead}
{*************************************************************************************
Routine Description:
DsBackupClose
To be called by the application after it completes reading all the data in
the currently opened attachement.
Arguments:
[in] hbc - backup context handle
Return Value:
One of the standard HRESULT success codes;
Failure code otherwise.
**************************************************************************************}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -