2 * Windows APIs that are different for each system.
3 * We use pointers to the entry points so that a
4 * single binary will run on all Windows systems.
9 Bacula® - The Network Backup Solution
11 Copyright (C) 2003-2006 Free Software Foundation Europe e.V.
13 The main author of Bacula is Kern Sibbald, with contributions from
14 many others, a complete list can be found in the file AUTHORS.
15 This program is Free Software; you can redistribute it and/or
16 modify it under the terms of version two of the GNU General Public
17 License as published by the Free Software Foundation plus additions
18 that are listed in the file LICENSE.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 Bacula® is a registered trademark of John Walker.
31 The licensor of Bacula is the Free Software Foundation Europe
32 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
33 Switzerland, email:ftf@fsfeurope.org.
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;
44 t_OpenProcessToken p_OpenProcessToken = NULL;
45 t_AdjustTokenPrivileges p_AdjustTokenPrivileges = NULL;
46 t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL;
48 t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL;
50 t_CreateFileA p_CreateFileA = NULL;
51 t_CreateFileW p_CreateFileW = NULL;
52 t_CreateDirectoryA p_CreateDirectoryA;
53 t_CreateDirectoryW p_CreateDirectoryW;
55 t_wunlink p_wunlink = NULL;
56 t_wmkdir p_wmkdir = NULL;
58 t_GetFileAttributesA p_GetFileAttributesA = NULL;
59 t_GetFileAttributesW p_GetFileAttributesW = NULL;
61 t_GetFileAttributesExA p_GetFileAttributesExA = NULL;
62 t_GetFileAttributesExW p_GetFileAttributesExW = NULL;
64 t_SetFileAttributesA p_SetFileAttributesA = NULL;
65 t_SetFileAttributesW p_SetFileAttributesW = NULL;
66 t_BackupRead p_BackupRead = NULL;
67 t_BackupWrite p_BackupWrite = NULL;
68 t_WideCharToMultiByte p_WideCharToMultiByte = NULL;
69 t_MultiByteToWideChar p_MultiByteToWideChar = NULL;
71 t_AttachConsole p_AttachConsole = NULL;
73 t_FindFirstFileA p_FindFirstFileA = NULL;
74 t_FindFirstFileW p_FindFirstFileW = NULL;
76 t_FindNextFileA p_FindNextFileA = NULL;
77 t_FindNextFileW p_FindNextFileW = NULL;
79 t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL;
80 t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL;
82 t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL;
83 t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL;
85 t_GetVolumePathNameW p_GetVolumePathNameW = NULL;
86 t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL;
91 OSVERSIONINFO osversioninfo = { sizeof(OSVERSIONINFO) };
93 // Get the current OS version
94 if (!GetVersionEx(&osversioninfo)) {
98 g_platform_id = osversioninfo.dwPlatformId;
99 g_MinorVersion = osversioninfo.dwMinorVersion;
102 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
104 /* create file calls */
105 p_CreateFileA = (t_CreateFileA)
106 GetProcAddress(hLib, "CreateFileA");
107 p_CreateDirectoryA = (t_CreateDirectoryA)
108 GetProcAddress(hLib, "CreateDirectoryA");
110 /* attribute calls */
111 p_GetFileAttributesA = (t_GetFileAttributesA)
112 GetProcAddress(hLib, "GetFileAttributesA");
113 p_GetFileAttributesExA = (t_GetFileAttributesExA)
114 GetProcAddress(hLib, "GetFileAttributesExA");
115 p_SetFileAttributesA = (t_SetFileAttributesA)
116 GetProcAddress(hLib, "SetFileAttributesA");
119 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
120 GetProcAddress(hLib, "SetProcessShutdownParameters");
122 /* char conversion calls */
123 p_WideCharToMultiByte = (t_WideCharToMultiByte)
124 GetProcAddress(hLib, "WideCharToMultiByte");
125 p_MultiByteToWideChar = (t_MultiByteToWideChar)
126 GetProcAddress(hLib, "MultiByteToWideChar");
129 p_FindFirstFileA = (t_FindFirstFileA)
130 GetProcAddress(hLib, "FindFirstFileA");
131 p_FindNextFileA = (t_FindNextFileA)
132 GetProcAddress(hLib, "FindNextFileA");
134 /* get and set directory */
135 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
136 GetProcAddress(hLib, "GetCurrentDirectoryA");
137 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
138 GetProcAddress(hLib, "SetCurrentDirectoryA");
140 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
141 p_CreateFileW = (t_CreateFileW)
142 GetProcAddress(hLib, "CreateFileW");
143 p_CreateDirectoryW = (t_CreateDirectoryW)
144 GetProcAddress(hLib, "CreateDirectoryW");
147 p_BackupRead = (t_BackupRead)
148 GetProcAddress(hLib, "BackupRead");
149 p_BackupWrite = (t_BackupWrite)
150 GetProcAddress(hLib, "BackupWrite");
152 p_GetFileAttributesW = (t_GetFileAttributesW)
153 GetProcAddress(hLib, "GetFileAttributesW");
154 p_GetFileAttributesExW = (t_GetFileAttributesExW)
155 GetProcAddress(hLib, "GetFileAttributesExW");
156 p_SetFileAttributesW = (t_SetFileAttributesW)
157 GetProcAddress(hLib, "SetFileAttributesW");
158 p_FindFirstFileW = (t_FindFirstFileW)
159 GetProcAddress(hLib, "FindFirstFileW");
160 p_FindNextFileW = (t_FindNextFileW)
161 GetProcAddress(hLib, "FindNextFileW");
162 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
163 GetProcAddress(hLib, "GetCurrentDirectoryW");
164 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
165 GetProcAddress(hLib, "SetCurrentDirectoryW");
167 /* some special stuff we need for VSS
168 but statically linkage doesn't work on Win 9x */
169 p_GetVolumePathNameW = (t_GetVolumePathNameW)
170 GetProcAddress(hLib, "GetVolumePathNameW");
171 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
172 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
174 p_AttachConsole = (t_AttachConsole)
175 GetProcAddress(hLib, "AttachConsole");
181 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
182 hLib = LoadLibraryA("MSVCRT.DLL");
185 p_wunlink = (t_wunlink)
186 GetProcAddress(hLib, "_wunlink");
188 p_wmkdir = (t_wmkdir)
189 GetProcAddress(hLib, "_wmkdir");
194 hLib = LoadLibraryA("ADVAPI32.DLL");
196 p_OpenProcessToken = (t_OpenProcessToken)
197 GetProcAddress(hLib, "OpenProcessToken");
198 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
199 GetProcAddress(hLib, "AdjustTokenPrivileges");
200 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
201 GetProcAddress(hLib, "LookupPrivilegeValueA");
206 atexit(Win32ConvCleanupCache);