mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 10:03: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
|
||||
// http://msdn2.microsoft.com/en-us/library/aa380797.aspx
|
||||
// and slightly adapted for our coding style
|
||||
@ -361,15 +389,20 @@ bool isGlobalKernelPrefix()
|
||||
// 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)
|
||||
|
||||
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?
|
||||
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
|
||||
// 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.
|
||||
// The API for that is the NT thing, so we have to get addresses of the
|
||||
@ -377,7 +410,7 @@ bool isGlobalKernelPrefix()
|
||||
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
HMODULE hmodAdvApi = LoadLibrary("advapi32.dll");
|
||||
DynLibHandle hmodAdvApi(LoadLibrary("advapi32.dll"));
|
||||
|
||||
if (!hmodAdvApi) {
|
||||
gds__log("LoadLibrary failed for advapi32.dll. Error code: %lu", GetLastError());
|
||||
@ -398,14 +431,12 @@ bool isGlobalKernelPrefix()
|
||||
if (!pfnOpenProcessToken || !pfnLookupPrivilegeValue || !pfnPrivilegeCheck) {
|
||||
// Should never happen, really
|
||||
gds__log("Cannot access privilege management API");
|
||||
FreeLibrary(hmodAdvApi);
|
||||
return false;
|
||||
}
|
||||
|
||||
HANDLE hToken;
|
||||
if (pfnOpenProcessToken(hProcess, TOKEN_QUERY, &hToken) == 0) {
|
||||
gds__log("OpenProcessToken failed. Error code: %lu", GetLastError());
|
||||
FreeLibrary(hmodAdvApi);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -417,7 +448,6 @@ bool isGlobalKernelPrefix()
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -425,20 +455,13 @@ bool isGlobalKernelPrefix()
|
||||
if (pfnPrivilegeCheck(hToken, &ps, &checkResult) == 0) {
|
||||
gds__log("PrivilegeCheck failed. Error code: %lu", GetLastError());
|
||||
CloseHandle(hToken);
|
||||
FreeLibrary(hmodAdvApi);
|
||||
return false;
|
||||
}
|
||||
|
||||
CloseHandle(hToken);
|
||||
FreeLibrary(hmodAdvApi);
|
||||
|
||||
return checkResult;
|
||||
}
|
||||
else // This is Windows NT 4.0 or earlier.
|
||||
{
|
||||
return validateProductSuite("Terminal Server");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user