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;
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)GetProcAddress(hLib, "CreateFileA");
109 p_CreateDirectoryA = (t_CreateDirectoryA)GetProcAddress(hLib, "CreateDirectoryA");
111 /* attribute calls */
112 p_GetFileAttributesA = (t_GetFileAttributesA)GetProcAddress(hLib, "GetFileAttributesA");
113 p_GetFileAttributesExA = (t_GetFileAttributesExA)GetProcAddress(hLib, "GetFileAttributesExA");
114 p_SetFileAttributesA = (t_SetFileAttributesA)GetProcAddress(hLib, "SetFileAttributesA");
117 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
118 GetProcAddress(hLib, "SetProcessShutdownParameters");
120 /* char conversion calls */
121 p_WideCharToMultiByte = (t_WideCharToMultiByte)
122 GetProcAddress(hLib, "WideCharToMultiByte");
123 p_MultiByteToWideChar = (t_MultiByteToWideChar)
124 GetProcAddress(hLib, "MultiByteToWideChar");
127 p_FindFirstFileA = (t_FindFirstFileA)GetProcAddress(hLib, "FindFirstFileA");
128 p_FindNextFileA = (t_FindNextFileA)GetProcAddress(hLib, "FindNextFileA");
130 /* get and set directory */
131 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
132 GetProcAddress(hLib, "GetCurrentDirectoryA");
133 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
134 GetProcAddress(hLib, "SetCurrentDirectoryA");
136 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
137 p_CreateFileW = (t_CreateFileW)
138 GetProcAddress(hLib, "CreateFileW");
139 p_CreateDirectoryW = (t_CreateDirectoryW)
140 GetProcAddress(hLib, "CreateDirectoryW");
143 p_BackupRead = (t_BackupRead)GetProcAddress(hLib, "BackupRead");
144 p_BackupWrite = (t_BackupWrite)GetProcAddress(hLib, "BackupWrite");
146 p_GetFileAttributesW = (t_GetFileAttributesW)
147 GetProcAddress(hLib, "GetFileAttributesW");
148 p_GetFileAttributesExW = (t_GetFileAttributesExW)
149 GetProcAddress(hLib, "GetFileAttributesExW");
150 p_SetFileAttributesW = (t_SetFileAttributesW)
151 GetProcAddress(hLib, "SetFileAttributesW");
152 p_FindFirstFileW = (t_FindFirstFileW)
153 GetProcAddress(hLib, "FindFirstFileW");
154 p_FindNextFileW = (t_FindNextFileW)
155 GetProcAddress(hLib, "FindNextFileW");
156 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
157 GetProcAddress(hLib, "GetCurrentDirectoryW");
158 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
159 GetProcAddress(hLib, "SetCurrentDirectoryW");
161 /* some special stuff we need for VSS
162 but static linkage doesn't work on Win 9x */
163 p_GetVolumePathNameW = (t_GetVolumePathNameW)
164 GetProcAddress(hLib, "GetVolumePathNameW");
165 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
166 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
168 p_AttachConsole = (t_AttachConsole)
169 GetProcAddress(hLib, "AttachConsole");
173 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
174 hLib = LoadLibraryA("MSVCRT.DLL");
177 p_wunlink = (t_wunlink)
178 GetProcAddress(hLib, "_wunlink");
180 p_wmkdir = (t_wmkdir)
181 GetProcAddress(hLib, "_wmkdir");
184 hLib = LoadLibraryA("ADVAPI32.DLL");
186 p_OpenProcessToken = (t_OpenProcessToken)
187 GetProcAddress(hLib, "OpenProcessToken");
188 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
189 GetProcAddress(hLib, "AdjustTokenPrivileges");
190 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
191 GetProcAddress(hLib, "LookupPrivilegeValueA");
195 hLib = LoadLibraryA("SHELL32.DLL");
197 p_SHGetFolderPath = (t_SHGetFolderPath)
198 GetProcAddress(hLib, "SHGetFolderPathA");
200 /* If SHELL32 isn't found try SHFOLDER for older systems */
201 hLib = LoadLibraryA("SHFOLDER.DLL");
203 p_SHGetFolderPath = (t_SHGetFolderPath)
204 GetProcAddress(hLib, "SHGetFolderPathA");
207 atexit(Win32ConvCleanupCache);