]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/filed/plugins/exch_api.c
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / filed / plugins / exch_api.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2018 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /* 
20  *  Written by James Harper, July 2010
21  *  
22  *  Used only in "old Exchange plugin" now deprecated.
23  */
24
25 #include "exchange-fd.h"
26
27 HrESEBackupRestoreGetNodes_t HrESEBackupRestoreGetNodes;
28 HrESEBackupPrepare_t HrESEBackupPrepare;
29 HrESEBackupGetLogAndPatchFiles_t HrESEBackupGetLogAndPatchFiles;
30 HrESEBackupTruncateLogs_t HrESEBackupTruncateLogs;
31 HrESEBackupEnd_t HrESEBackupEnd;
32 HrESEBackupSetup_t HrESEBackupSetup;
33 HrESEBackupInstanceEnd_t HrESEBackupInstanceEnd;
34 HrESEBackupOpenFile_t HrESEBackupOpenFile;
35 HrESEBackupReadFile_t HrESEBackupReadFile;
36 HrESEBackupCloseFile_t HrESEBackupCloseFile;
37
38 HrESERestoreOpen_t HrESERestoreOpen;
39 HrESERestoreReopen_t HrESERestoreReopen;
40 HrESERestoreComplete_t HrESERestoreComplete;
41 HrESERestoreClose_t HrESERestoreClose;
42 HrESERestoreGetEnvironment_t HrESERestoreGetEnvironment;
43 HrESERestoreSaveEnvironment_t HrESERestoreSaveEnvironment;
44 HrESERestoreAddDatabase_t HrESERestoreAddDatabase;
45 HrESERestoreOpenFile_t HrESERestoreOpenFile;
46
47 bRC
48 loadExchangeApi()
49 {
50    HMODULE h;
51    LONG status;
52    HKEY key_handle;
53    WCHAR *buf;
54    DWORD buf_len;
55    DWORD type;
56
57    status = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\BackupRestore\\DLLPaths", &key_handle);
58    if (status != ERROR_SUCCESS)
59    {
60       _JobMessageNull(M_FATAL, "Cannot get key for Exchange DLL path, result = %08x\n", status);
61       return bRC_Error;
62    }
63    
64    type = REG_EXPAND_SZ;
65    status = RegQueryValueExW(key_handle, L"esebcli2", NULL, &type, NULL, &buf_len);
66    if (status != ERROR_SUCCESS)
67    {
68       _JobMessageNull(M_FATAL, "Cannot get key for Exchange DLL path, result = %08x\n", status);
69       return bRC_Error;
70    }
71    buf_len += 2;
72    buf = new WCHAR[buf_len];
73
74    type = REG_EXPAND_SZ;
75    status = RegQueryValueExW(key_handle, L"esebcli2", NULL, &type, (LPBYTE)buf, &buf_len);
76    if (status != ERROR_SUCCESS)
77    {
78       _JobMessageNull(M_FATAL, "Cannot get key for Exchange DLL path, result = %08x\n", status);
79       delete buf;
80       return bRC_Error;
81    }
82
83 printf("Got value %S\n", buf);
84
85    // strictly speaking, a REG_EXPAND_SZ should be run through ExpandEnvironmentStrings
86
87    h = LoadLibraryW(buf);
88    delete buf;
89    if (!h) {
90       _JobMessageNull(M_FATAL, "Cannot load Exchange DLL\n");
91       return bRC_Error;
92    }
93    HrESEBackupRestoreGetNodes = (HrESEBackupRestoreGetNodes_t)GetProcAddress(h, "HrESEBackupRestoreGetNodes");
94    HrESEBackupPrepare = (HrESEBackupPrepare_t)GetProcAddress(h, "HrESEBackupPrepare");
95    HrESEBackupEnd = (HrESEBackupEnd_t)GetProcAddress(h, "HrESEBackupEnd");
96    HrESEBackupSetup = (HrESEBackupSetup_t)GetProcAddress(h, "HrESEBackupSetup");
97    HrESEBackupGetLogAndPatchFiles = (HrESEBackupGetLogAndPatchFiles_t)GetProcAddress(h, "HrESEBackupGetLogAndPatchFiles");
98    HrESEBackupTruncateLogs = (HrESEBackupTruncateLogs_t)GetProcAddress(h, "HrESEBackupTruncateLogs");
99    HrESEBackupInstanceEnd = (HrESEBackupInstanceEnd_t)GetProcAddress(h, "HrESEBackupInstanceEnd");
100    HrESEBackupOpenFile = (HrESEBackupOpenFile_t)GetProcAddress(h, "HrESEBackupOpenFile");
101    HrESEBackupReadFile = (HrESEBackupReadFile_t)GetProcAddress(h, "HrESEBackupReadFile");
102    HrESEBackupCloseFile = (HrESEBackupCloseFile_t)GetProcAddress(h, "HrESEBackupCloseFile");
103    HrESERestoreOpen = (HrESERestoreOpen_t)GetProcAddress(h, "HrESERestoreOpen");
104    HrESERestoreReopen = (HrESERestoreReopen_t)GetProcAddress(h, "HrESERestoreReopen");
105    HrESERestoreComplete = (HrESERestoreComplete_t)GetProcAddress(h, "HrESERestoreComplete");
106    HrESERestoreClose = (HrESERestoreClose_t)GetProcAddress(h, "HrESERestoreClose");
107    HrESERestoreSaveEnvironment = (HrESERestoreSaveEnvironment_t)GetProcAddress(h, "HrESERestoreSaveEnvironment");
108    HrESERestoreGetEnvironment = (HrESERestoreGetEnvironment_t)GetProcAddress(h, "HrESERestoreGetEnvironment");
109    HrESERestoreAddDatabase = (HrESERestoreAddDatabase_t)GetProcAddress(h, "HrESERestoreAddDatabase");
110    HrESERestoreOpenFile = (HrESERestoreOpenFile_t)GetProcAddress(h, "HrESERestoreOpenFile");
111    return bRC_OK;
112 }
113
114 const char *
115 ESEErrorMessage(HRESULT result)
116 {
117    switch (result) {
118    case 0:
119       return "No error.";
120    case hrLogfileHasBadSignature:
121       return "Log file has bad signature. Check that no stale files are left in the Exchange data/log directories.";
122    case hrCBDatabaseInUse:
123       return "Database in use. Make sure database is dismounted.";
124    case hrRestoreAtFileLevel:
125       return "File must be restored using Windows file I/O calls.";
126    case hrMissingFullBackup:
127       return "Exchange reports that no previous full backup has been done.";
128    case hrBackupInProgress:
129       return "Exchange backup already in progress.";
130    case hrLogfileNotContiguous:
131       return "Existing log file is not contiguous. Check that no stale files are left in the Exchange data/log directories.";
132    case hrErrorFromESECall:
133       return "Error returned from ESE function call. Check the Windows Event Logs for more information.";
134    case hrCBDatabaseNotFound:
135       return "Database not found. Check that the Database you are trying to restore actually exists in the Storage Group you are restoring to.";
136    default:
137       return "Unknown error.";
138    }
139 }