mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 10:43:03 +01:00
Make compilation possible in VC6.
Simplify code.
This commit is contained in:
parent
36e7e04d42
commit
7feced9cd9
@ -345,6 +345,34 @@ void prefix_kernel_object_name(char* name, size_t bufsize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Simply handle guardian.
|
||||||
|
class DynLibHandle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit DynLibHandle(HMODULE mod)
|
||||||
|
: m_handle(mod)
|
||||||
|
{}
|
||||||
|
~DynLibHandle()
|
||||||
|
{
|
||||||
|
if (m_handle)
|
||||||
|
FreeLibrary(m_handle);
|
||||||
|
}
|
||||||
|
operator HMODULE() const
|
||||||
|
{
|
||||||
|
return m_handle;
|
||||||
|
}
|
||||||
|
/* The previous conversion is invoked with !object so this is enough.
|
||||||
|
bool operator!() const
|
||||||
|
{
|
||||||
|
return !m_handle;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
private:
|
||||||
|
HMODULE m_handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// hvlad: two functions below got from
|
// hvlad: two functions below got from
|
||||||
// http://msdn2.microsoft.com/en-us/library/aa380797.aspx
|
// http://msdn2.microsoft.com/en-us/library/aa380797.aspx
|
||||||
// and slightly adapted for our coding style
|
// and slightly adapted for our coding style
|
||||||
@ -361,83 +389,78 @@ bool isGlobalKernelPrefix()
|
|||||||
// for engine objects if we can. This can be prevented by either lack of OS support
|
// for engine objects if we can. This can be prevented by either lack of OS support
|
||||||
// for the feature (Win9X) or lack of privileges (Vista, Windows 2000/XP restricted accounts)
|
// for the feature (Win9X) or lack of privileges (Vista, Windows 2000/XP restricted accounts)
|
||||||
|
|
||||||
DWORD dwVersion = GetVersion();
|
#if (defined(_MSC_VER) && (_MSC_VER <= 1200)) // || defined(MINGW)
|
||||||
|
const char* SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const DWORD dwVersion = GetVersion();
|
||||||
|
|
||||||
// Is Windows NT running?
|
// Is Windows NT running?
|
||||||
if (!(dwVersion & 0x80000000))
|
if (!(dwVersion & 0x80000000))
|
||||||
{
|
{
|
||||||
|
if (LOBYTE(LOWORD(dwVersion)) <= 4) // This is Windows NT 4.0 or earlier.
|
||||||
|
return validateProductSuite("Terminal Server");
|
||||||
|
|
||||||
// Is it Windows 2000 or greater? It is possible to use Global\ prefix on any
|
// Is it Windows 2000 or greater? It is possible to use Global\ prefix on any
|
||||||
// version of Windows from Windows 2000 and up
|
// version of Windows from Windows 2000 and up
|
||||||
if (LOBYTE(LOWORD(dwVersion)) > 4)
|
// Check if we have enough privileges to create global handles.
|
||||||
{
|
// If not fall back to creating local ones.
|
||||||
// Check if we have enough privileges to create global handles.
|
// The API for that is the NT thing, so we have to get addresses of the
|
||||||
// If not fall back to creating local ones.
|
// functions dynamically to avoid troubles on Windows 9X platforms
|
||||||
// The API for that is the NT thing, so we have to get addresses of the
|
|
||||||
// functions dynamically to avoid troubles on Windows 9X platforms
|
|
||||||
|
|
||||||
HANDLE hProcess = GetCurrentProcess();
|
HANDLE hProcess = GetCurrentProcess();
|
||||||
|
|
||||||
HMODULE hmodAdvApi = LoadLibrary("advapi32.dll");
|
DynLibHandle hmodAdvApi(LoadLibrary("advapi32.dll"));
|
||||||
|
|
||||||
if (!hmodAdvApi) {
|
if (!hmodAdvApi) {
|
||||||
gds__log("LoadLibrary failed for advapi32.dll. Error code: %lu", GetLastError());
|
gds__log("LoadLibrary failed for advapi32.dll. Error code: %lu", GetLastError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef BOOL (WINAPI *PFnOpenProcessToken) (HANDLE, DWORD, PHANDLE);
|
||||||
|
typedef BOOL (WINAPI *PFnLookupPrivilegeValue) (LPCSTR, LPCSTR, PLUID);
|
||||||
|
typedef BOOL (WINAPI *PFnPrivilegeCheck) (HANDLE, PPRIVILEGE_SET, LPBOOL);
|
||||||
|
|
||||||
typedef BOOL (WINAPI *PFnOpenProcessToken) (HANDLE, DWORD, PHANDLE);
|
PFnOpenProcessToken pfnOpenProcessToken =
|
||||||
typedef BOOL (WINAPI *PFnLookupPrivilegeValue) (LPCSTR, LPCSTR, PLUID);
|
(PFnOpenProcessToken) GetProcAddress(hmodAdvApi, "OpenProcessToken");
|
||||||
typedef BOOL (WINAPI *PFnPrivilegeCheck) (HANDLE, PPRIVILEGE_SET, LPBOOL);
|
PFnLookupPrivilegeValue pfnLookupPrivilegeValue =
|
||||||
|
(PFnLookupPrivilegeValue) GetProcAddress(hmodAdvApi, "LookupPrivilegeValueA");
|
||||||
|
PFnPrivilegeCheck pfnPrivilegeCheck =
|
||||||
|
(PFnPrivilegeCheck) GetProcAddress(hmodAdvApi, "PrivilegeCheck");
|
||||||
|
|
||||||
PFnOpenProcessToken pfnOpenProcessToken =
|
if (!pfnOpenProcessToken || !pfnLookupPrivilegeValue || !pfnPrivilegeCheck) {
|
||||||
(PFnOpenProcessToken) GetProcAddress(hmodAdvApi, "OpenProcessToken");
|
// Should never happen, really
|
||||||
PFnLookupPrivilegeValue pfnLookupPrivilegeValue =
|
gds__log("Cannot access privilege management API");
|
||||||
(PFnLookupPrivilegeValue) GetProcAddress(hmodAdvApi, "LookupPrivilegeValueA");
|
return false;
|
||||||
PFnPrivilegeCheck pfnPrivilegeCheck =
|
}
|
||||||
(PFnPrivilegeCheck) GetProcAddress(hmodAdvApi, "PrivilegeCheck");
|
|
||||||
|
|
||||||
if (!pfnOpenProcessToken || !pfnLookupPrivilegeValue || !pfnPrivilegeCheck) {
|
HANDLE hToken;
|
||||||
// Should never happen, really
|
if (pfnOpenProcessToken(hProcess, TOKEN_QUERY, &hToken) == 0) {
|
||||||
gds__log("Cannot access privilege management API");
|
gds__log("OpenProcessToken failed. Error code: %lu", GetLastError());
|
||||||
FreeLibrary(hmodAdvApi);
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE hToken;
|
|
||||||
if (pfnOpenProcessToken(hProcess, TOKEN_QUERY, &hToken) == 0) {
|
|
||||||
gds__log("OpenProcessToken failed. Error code: %lu", GetLastError());
|
|
||||||
FreeLibrary(hmodAdvApi);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRIVILEGE_SET ps;
|
|
||||||
memset(&ps, 0, sizeof(ps));
|
|
||||||
ps.Control = PRIVILEGE_SET_ALL_NECESSARY;
|
|
||||||
ps.PrivilegeCount = 1;
|
|
||||||
if (pfnLookupPrivilegeValue(NULL, SE_CREATE_GLOBAL_NAME, &ps.Privilege[0].Luid) == 0) {
|
|
||||||
// Failure here means we're running on old version of Windows 2000 or XP
|
|
||||||
// which always allow creating global handles
|
|
||||||
CloseHandle(hToken);
|
|
||||||
FreeLibrary(hmodAdvApi);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL checkResult;
|
|
||||||
if (pfnPrivilegeCheck(hToken, &ps, &checkResult) == 0) {
|
|
||||||
gds__log("PrivilegeCheck failed. Error code: %lu", GetLastError());
|
|
||||||
CloseHandle(hToken);
|
|
||||||
FreeLibrary(hmodAdvApi);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
PRIVILEGE_SET ps;
|
||||||
|
memset(&ps, 0, sizeof(ps));
|
||||||
|
ps.Control = PRIVILEGE_SET_ALL_NECESSARY;
|
||||||
|
ps.PrivilegeCount = 1;
|
||||||
|
if (pfnLookupPrivilegeValue(NULL, SE_CREATE_GLOBAL_NAME, &ps.Privilege[0].Luid) == 0) {
|
||||||
|
// Failure here means we're running on old version of Windows 2000 or XP
|
||||||
|
// which always allow creating global handles
|
||||||
CloseHandle(hToken);
|
CloseHandle(hToken);
|
||||||
FreeLibrary(hmodAdvApi);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return checkResult;
|
BOOL checkResult;
|
||||||
}
|
if (pfnPrivilegeCheck(hToken, &ps, &checkResult) == 0) {
|
||||||
else // This is Windows NT 4.0 or earlier.
|
gds__log("PrivilegeCheck failed. Error code: %lu", GetLastError());
|
||||||
{
|
CloseHandle(hToken);
|
||||||
return validateProductSuite("Terminal Server");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CloseHandle(hToken);
|
||||||
|
|
||||||
|
return checkResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user