]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/filed/plugins/api.c
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / filed / plugins / api.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2008-2010 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation, which is 
11    listed in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /* 
29  *  Written by James Harper, October 2008
30  */
31
32 #include "exchange-fd.h"
33
34 HrESEBackupRestoreGetNodes_t HrESEBackupRestoreGetNodes;
35 HrESEBackupPrepare_t HrESEBackupPrepare;
36 HrESEBackupGetLogAndPatchFiles_t HrESEBackupGetLogAndPatchFiles;
37 HrESEBackupTruncateLogs_t HrESEBackupTruncateLogs;
38 HrESEBackupEnd_t HrESEBackupEnd;
39 HrESEBackupSetup_t HrESEBackupSetup;
40 HrESEBackupInstanceEnd_t HrESEBackupInstanceEnd;
41 HrESEBackupOpenFile_t HrESEBackupOpenFile;
42 HrESEBackupReadFile_t HrESEBackupReadFile;
43 HrESEBackupCloseFile_t HrESEBackupCloseFile;
44
45 HrESERestoreOpen_t HrESERestoreOpen;
46 HrESERestoreReopen_t HrESERestoreReopen;
47 HrESERestoreComplete_t HrESERestoreComplete;
48 HrESERestoreClose_t HrESERestoreClose;
49 HrESERestoreGetEnvironment_t HrESERestoreGetEnvironment;
50 HrESERestoreSaveEnvironment_t HrESERestoreSaveEnvironment;
51 HrESERestoreAddDatabase_t HrESERestoreAddDatabase;
52 HrESERestoreOpenFile_t HrESERestoreOpenFile;
53
54 bRC
55 loadExchangeApi()
56 {
57    HMODULE h;
58    LONG status;
59    HKEY key_handle;
60    WCHAR *buf;
61    DWORD buf_len;
62    DWORD type;
63
64    status = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\BackupRestore\\DLLPaths", &key_handle);
65    if (status != ERROR_SUCCESS)
66    {
67       _JobMessageNull(M_FATAL, "Cannot get key for Exchange DLL path, result = %08x\n", status);
68       return bRC_Error;
69    }
70    
71    type = REG_EXPAND_SZ;
72    status = RegQueryValueExW(key_handle, L"esebcli2", NULL, &type, NULL, &buf_len);
73    if (status != ERROR_SUCCESS)
74    {
75       _JobMessageNull(M_FATAL, "Cannot get key for Exchange DLL path, result = %08x\n", status);
76       return bRC_Error;
77    }
78    buf_len += 2;
79    buf = new WCHAR[buf_len];
80
81    type = REG_EXPAND_SZ;
82    status = RegQueryValueExW(key_handle, L"esebcli2", NULL, &type, (LPBYTE)buf, &buf_len);
83    if (status != ERROR_SUCCESS)
84    {
85       _JobMessageNull(M_FATAL, "Cannot get key for Exchange DLL path, result = %08x\n", status);
86       delete buf;
87       return bRC_Error;
88    }
89
90 printf("Got value %S\n", buf);
91
92    // strictly speaking, a REG_EXPAND_SZ should be run through ExpandEnvironmentStrings
93
94    h = LoadLibraryW(buf);
95    delete buf;
96    if (!h) {
97       _JobMessageNull(M_FATAL, "Cannot load Exchange DLL\n");
98       return bRC_Error;
99    }
100    HrESEBackupRestoreGetNodes = (HrESEBackupRestoreGetNodes_t)GetProcAddress(h, "HrESEBackupRestoreGetNodes");
101    HrESEBackupPrepare = (HrESEBackupPrepare_t)GetProcAddress(h, "HrESEBackupPrepare");
102    HrESEBackupEnd = (HrESEBackupEnd_t)GetProcAddress(h, "HrESEBackupEnd");
103    HrESEBackupSetup = (HrESEBackupSetup_t)GetProcAddress(h, "HrESEBackupSetup");
104    HrESEBackupGetLogAndPatchFiles = (HrESEBackupGetLogAndPatchFiles_t)GetProcAddress(h, "HrESEBackupGetLogAndPatchFiles");
105    HrESEBackupTruncateLogs = (HrESEBackupTruncateLogs_t)GetProcAddress(h, "HrESEBackupTruncateLogs");
106    HrESEBackupInstanceEnd = (HrESEBackupInstanceEnd_t)GetProcAddress(h, "HrESEBackupInstanceEnd");
107    HrESEBackupOpenFile = (HrESEBackupOpenFile_t)GetProcAddress(h, "HrESEBackupOpenFile");
108    HrESEBackupReadFile = (HrESEBackupReadFile_t)GetProcAddress(h, "HrESEBackupReadFile");
109    HrESEBackupCloseFile = (HrESEBackupCloseFile_t)GetProcAddress(h, "HrESEBackupCloseFile");
110    HrESERestoreOpen = (HrESERestoreOpen_t)GetProcAddress(h, "HrESERestoreOpen");
111    HrESERestoreReopen = (HrESERestoreReopen_t)GetProcAddress(h, "HrESERestoreReopen");
112    HrESERestoreComplete = (HrESERestoreComplete_t)GetProcAddress(h, "HrESERestoreComplete");
113    HrESERestoreClose = (HrESERestoreClose_t)GetProcAddress(h, "HrESERestoreClose");
114    HrESERestoreSaveEnvironment = (HrESERestoreSaveEnvironment_t)GetProcAddress(h, "HrESERestoreSaveEnvironment");
115    HrESERestoreGetEnvironment = (HrESERestoreGetEnvironment_t)GetProcAddress(h, "HrESERestoreGetEnvironment");
116    HrESERestoreAddDatabase = (HrESERestoreAddDatabase_t)GetProcAddress(h, "HrESERestoreAddDatabase");
117    HrESERestoreOpenFile = (HrESERestoreOpenFile_t)GetProcAddress(h, "HrESERestoreOpenFile");
118    return bRC_OK;
119 }
120
121 const char *
122 ESEErrorMessage(HRESULT result)
123 {
124    switch (result) {
125    case 0:
126       return "No error.";
127    case hrLogfileHasBadSignature:
128       return "Log file has bad signature. Check that no stale files are left in the Exchange data/log directories.";
129    case hrCBDatabaseInUse:
130       return "Database in use. Make sure database is dismounted.";
131    case hrRestoreAtFileLevel:
132       return "File must be restored using Windows file I/O calls.";
133    case hrMissingFullBackup:
134       return "Exchange reports that no previous full backup has been done.";
135    case hrBackupInProgress:
136       return "Exchange backup already in progress.";
137    case hrLogfileNotContiguous:
138       return "Existing log file is not contiguous. Check that no stale files are left in the Exchange data/log directories.";
139    case hrErrorFromESECall:
140       return "Error returned from ESE function call. Check the Windows Event Logs for more information.";
141    case hrCBDatabaseNotFound:
142       return "Database not found. Check that the Database you are trying to restore actually exists in the Storage Group you are restoring to.";
143    default:
144       return "Unknown error.";
145    }
146 }