MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / isGlobalKernelPrefix

Function isGlobalKernelPrefix

src/common/utils.cpp:479–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477// -------------------------------------------------------------
478
479bool isGlobalKernelPrefix()
480{
481 // The strategy of this function is as follows: use Global\ kernel namespace
482 // for engine objects if we can. This can be prevented by either lack of OS support
483 // for the feature (Win9X) or lack of privileges (Vista, Windows 2000/XP restricted accounts)
484
485 const DWORD dwVersion = GetVersion();
486
487 // Is Windows NT running?
488 if (!(dwVersion & 0x80000000))
489 {
490 if (LOBYTE(LOWORD(dwVersion)) <= 4) // This is Windows NT 4.0 or earlier.
491 return validateProductSuite("Terminal Server");
492
493 // Is it Windows 2000 or greater? It is possible to use Global\ prefix on any
494 // version of Windows from Windows 2000 and up
495 // Check if we have enough privileges to create global handles.
496 // If not fall back to creating local ones.
497 // The API for that is the NT thing, so we have to get addresses of the
498 // functions dynamically to avoid troubles on Windows 9X platforms
499
500 DynLibHandle hmodAdvApi(LoadLibrary("advapi32.dll"));
501
502 if (!hmodAdvApi)
503 {
504 gds__log("LoadLibrary failed for advapi32.dll. Error code: %lu", GetLastError());
505 return false;
506 }
507
508 typedef BOOL (WINAPI *PFnOpenProcessToken) (HANDLE, DWORD, PHANDLE);
509 typedef BOOL (WINAPI *PFnLookupPrivilegeValue) (LPCSTR, LPCSTR, PLUID);
510 typedef BOOL (WINAPI *PFnPrivilegeCheck) (HANDLE, PPRIVILEGE_SET, LPBOOL);
511
512 PFnOpenProcessToken pfnOpenProcessToken =
513 (PFnOpenProcessToken) GetProcAddress(hmodAdvApi, "OpenProcessToken");
514 PFnLookupPrivilegeValue pfnLookupPrivilegeValue =
515 (PFnLookupPrivilegeValue) GetProcAddress(hmodAdvApi, "LookupPrivilegeValueA");
516 PFnPrivilegeCheck pfnPrivilegeCheck =
517 (PFnPrivilegeCheck) GetProcAddress(hmodAdvApi, "PrivilegeCheck");
518
519 if (!pfnOpenProcessToken || !pfnLookupPrivilegeValue || !pfnPrivilegeCheck)
520 {
521 // Should never happen, really
522 gds__log("Cannot access privilege management API");
523 return false;
524 }
525
526 HANDLE hProcess = GetCurrentProcess();
527 HANDLE hToken;
528 if (pfnOpenProcessToken(hProcess, TOKEN_QUERY, &hToken) == 0)
529 {
530 gds__log("OpenProcessToken failed. Error code: %lu", GetLastError());
531 return false;
532 }
533
534 PRIVILEGE_SET ps;
535 memset(&ps, 0, sizeof(ps));
536 ps.Control = PRIVILEGE_SET_ALL_NECESSARY;

Callers 2

ConfigStorageMethod · 0.85

Calls 2

GetVersionFunction · 0.85
validateProductSuiteFunction · 0.85

Tested by

no test coverage detected