2 Bacula® - The Network Backup Solution
4 Copyright (C) 2003-2007 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 John Walker.
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;
94 OSVERSIONINFO osversioninfo = { sizeof(OSVERSIONINFO) };
96 // Get the current OS version
97 if (!GetVersionEx(&osversioninfo)) {
100 g_platform_id = osversioninfo.dwPlatformId;
101 g_MinorVersion = osversioninfo.dwMinorVersion;
102 g_MajorVersion = osversioninfo.dwMajorVersion;
105 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
107 /* create file calls */
108 p_CreateFileA = (t_CreateFileA)
109 GetProcAddress(hLib, "CreateFileA");
110 p_CreateDirectoryA = (t_CreateDirectoryA)
111 GetProcAddress(hLib, "CreateDirectoryA");
113 /* attribute calls */
114 p_GetFileAttributesA = (t_GetFileAttributesA)
115 GetProcAddress(hLib, "GetFileAttributesA");
116 p_GetFileAttributesExA = (t_GetFileAttributesExA)
117 GetProcAddress(hLib, "GetFileAttributesExA");
118 p_SetFileAttributesA = (t_SetFileAttributesA)
119 GetProcAddress(hLib, "SetFileAttributesA");
122 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
123 GetProcAddress(hLib, "SetProcessShutdownParameters");
125 /* char conversion calls */
126 p_WideCharToMultiByte = (t_WideCharToMultiByte)
127 GetProcAddress(hLib, "WideCharToMultiByte");
128 p_MultiByteToWideChar = (t_MultiByteToWideChar)
129 GetProcAddress(hLib, "MultiByteToWideChar");
132 p_FindFirstFileA = (t_FindFirstFileA)
133 GetProcAddress(hLib, "FindFirstFileA");
134 p_FindNextFileA = (t_FindNextFileA)
135 GetProcAddress(hLib, "FindNextFileA");
137 /* get and set directory */
138 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
139 GetProcAddress(hLib, "GetCurrentDirectoryA");
140 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
141 GetProcAddress(hLib, "SetCurrentDirectoryA");
143 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
144 p_CreateFileW = (t_CreateFileW)
145 GetProcAddress(hLib, "CreateFileW");
146 p_CreateDirectoryW = (t_CreateDirectoryW)
147 GetProcAddress(hLib, "CreateDirectoryW");
150 p_BackupRead = (t_BackupRead)
151 GetProcAddress(hLib, "BackupRead");
152 p_BackupWrite = (t_BackupWrite)
153 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 statically 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);