2 Bacula® - The Network Backup Solution
4 Copyright (C) 2003-2008 Free Software Foundation Europe e.V.
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 two of the GNU General Public
10 License as published by the Free Software Foundation and included
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.
18 You should have received a copy of the GNU 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
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.
29 * Windows APIs that are different for each system.
30 * We use pointers to the entry points so that a
31 * single binary will run on all Windows systems.
38 // init with win9x, but maybe set to NT in InitWinAPI
39 DWORD g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
40 DWORD g_MinorVersion = 0;
41 DWORD g_MajorVersion = 0;
45 t_OpenProcessToken p_OpenProcessToken = NULL;
46 t_AdjustTokenPrivileges p_AdjustTokenPrivileges = NULL;
47 t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL;
49 t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL;
51 t_CreateFileA p_CreateFileA = NULL;
52 t_CreateFileW p_CreateFileW = NULL;
53 t_CreateDirectoryA p_CreateDirectoryA;
54 t_CreateDirectoryW p_CreateDirectoryW;
56 t_wunlink p_wunlink = NULL;
57 t_wmkdir p_wmkdir = NULL;
59 t_GetFileAttributesA p_GetFileAttributesA = NULL;
60 t_GetFileAttributesW p_GetFileAttributesW = NULL;
62 t_GetFileAttributesExA p_GetFileAttributesExA = NULL;
63 t_GetFileAttributesExW p_GetFileAttributesExW = NULL;
65 t_SetFileAttributesA p_SetFileAttributesA = NULL;
66 t_SetFileAttributesW p_SetFileAttributesW = NULL;
67 t_BackupRead p_BackupRead = NULL;
68 t_BackupWrite p_BackupWrite = NULL;
69 t_WideCharToMultiByte p_WideCharToMultiByte = NULL;
70 t_MultiByteToWideChar p_MultiByteToWideChar = NULL;
72 t_AttachConsole p_AttachConsole = NULL;
74 t_FindFirstFileA p_FindFirstFileA = NULL;
75 t_FindFirstFileW p_FindFirstFileW = NULL;
77 t_FindNextFileA p_FindNextFileA = NULL;
78 t_FindNextFileW p_FindNextFileW = NULL;
80 t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL;
81 t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL;
83 t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL;
84 t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL;
86 t_GetVolumePathNameW p_GetVolumePathNameW = NULL;
87 t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL;
89 t_SHGetFolderPath p_SHGetFolderPath = NULL;
91 t_CreateProcessA p_CreateProcessA = NULL;
92 t_CreateProcessW p_CreateProcessW = NULL;
97 OSVERSIONINFO osversioninfo = { sizeof(OSVERSIONINFO) };
99 // Get the current OS version
100 if (!GetVersionEx(&osversioninfo)) {
103 g_platform_id = osversioninfo.dwPlatformId;
104 g_MinorVersion = osversioninfo.dwMinorVersion;
105 g_MajorVersion = osversioninfo.dwMajorVersion;
108 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
110 /* create process calls */
111 p_CreateProcessA = (t_CreateProcessA)
112 GetProcAddress(hLib, "CreateProcessA");
113 p_CreateProcessW = (t_CreateProcessW)
114 GetProcAddress(hLib, "CreateProcessW");
116 /* create file calls */
117 p_CreateFileA = (t_CreateFileA)GetProcAddress(hLib, "CreateFileA");
118 p_CreateDirectoryA = (t_CreateDirectoryA)GetProcAddress(hLib, "CreateDirectoryA");
120 /* attribute calls */
121 p_GetFileAttributesA = (t_GetFileAttributesA)GetProcAddress(hLib, "GetFileAttributesA");
122 p_GetFileAttributesExA = (t_GetFileAttributesExA)GetProcAddress(hLib, "GetFileAttributesExA");
123 p_SetFileAttributesA = (t_SetFileAttributesA)GetProcAddress(hLib, "SetFileAttributesA");
126 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
127 GetProcAddress(hLib, "SetProcessShutdownParameters");
129 /* char conversion calls */
130 p_WideCharToMultiByte = (t_WideCharToMultiByte)
131 GetProcAddress(hLib, "WideCharToMultiByte");
132 p_MultiByteToWideChar = (t_MultiByteToWideChar)
133 GetProcAddress(hLib, "MultiByteToWideChar");
136 p_FindFirstFileA = (t_FindFirstFileA)GetProcAddress(hLib, "FindFirstFileA");
137 p_FindNextFileA = (t_FindNextFileA)GetProcAddress(hLib, "FindNextFileA");
139 /* get and set directory */
140 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
141 GetProcAddress(hLib, "GetCurrentDirectoryA");
142 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
143 GetProcAddress(hLib, "SetCurrentDirectoryA");
145 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
146 p_CreateFileW = (t_CreateFileW)
147 GetProcAddress(hLib, "CreateFileW");
148 p_CreateDirectoryW = (t_CreateDirectoryW)
149 GetProcAddress(hLib, "CreateDirectoryW");
152 p_BackupRead = (t_BackupRead)GetProcAddress(hLib, "BackupRead");
153 p_BackupWrite = (t_BackupWrite)GetProcAddress(hLib, "BackupWrite");
155 p_GetFileAttributesW = (t_GetFileAttributesW)
156 GetProcAddress(hLib, "GetFileAttributesW");
157 p_GetFileAttributesExW = (t_GetFileAttributesExW)
158 GetProcAddress(hLib, "GetFileAttributesExW");
159 p_SetFileAttributesW = (t_SetFileAttributesW)
160 GetProcAddress(hLib, "SetFileAttributesW");
161 p_FindFirstFileW = (t_FindFirstFileW)
162 GetProcAddress(hLib, "FindFirstFileW");
163 p_FindNextFileW = (t_FindNextFileW)
164 GetProcAddress(hLib, "FindNextFileW");
165 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
166 GetProcAddress(hLib, "GetCurrentDirectoryW");
167 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
168 GetProcAddress(hLib, "SetCurrentDirectoryW");
170 /* some special stuff we need for VSS
171 but static linkage doesn't work on Win 9x */
172 p_GetVolumePathNameW = (t_GetVolumePathNameW)
173 GetProcAddress(hLib, "GetVolumePathNameW");
174 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
175 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
177 p_AttachConsole = (t_AttachConsole)
178 GetProcAddress(hLib, "AttachConsole");
182 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
183 hLib = LoadLibraryA("MSVCRT.DLL");
186 p_wunlink = (t_wunlink)
187 GetProcAddress(hLib, "_wunlink");
189 p_wmkdir = (t_wmkdir)
190 GetProcAddress(hLib, "_wmkdir");
193 hLib = LoadLibraryA("ADVAPI32.DLL");
195 p_OpenProcessToken = (t_OpenProcessToken)
196 GetProcAddress(hLib, "OpenProcessToken");
197 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
198 GetProcAddress(hLib, "AdjustTokenPrivileges");
199 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
200 GetProcAddress(hLib, "LookupPrivilegeValueA");
204 hLib = LoadLibraryA("SHELL32.DLL");
206 p_SHGetFolderPath = (t_SHGetFolderPath)
207 GetProcAddress(hLib, "SHGetFolderPathA");
209 /* If SHELL32 isn't found try SHFOLDER for older systems */
210 hLib = LoadLibraryA("SHFOLDER.DLL");
212 p_SHGetFolderPath = (t_SHGetFolderPath)
213 GetProcAddress(hLib, "SHGetFolderPathA");
216 atexit(Win32ConvCleanupCache);