Some code clean-up. Also removed some obsolete compatibility code.

This commit is contained in:
LoRd_MuldeR 2013-12-17 22:36:16 +01:00
parent 0b1644e287
commit df5aaee581
5 changed files with 85 additions and 37 deletions

View File

@ -3310,22 +3310,22 @@
<context>
<name>QApplication</name>
<message>
<location filename="../../src/Global_Win32.cpp" line="1063"/>
<location filename="../../src/Global_Win32.cpp" line="1064"/>
<source>Executable &apos;%1&apos; doesn&apos;t support Windows compatibility mode.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1005"/>
<location filename="../../src/Global_Win32.cpp" line="1006"/>
<source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1010"/>
<location filename="../../src/Global_Win32.cpp" line="1011"/>
<source>Executable &apos;%1&apos; was built for Qt &apos;%2&apos;, but found Qt &apos;%3&apos;.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1022"/>
<location filename="../../src/Global_Win32.cpp" line="1023"/>
<source>Executable &apos;%1&apos; requires Windows XP or later.</source>
<translation type="unfinished"></translation>
</message>

View File

@ -3347,22 +3347,22 @@
<context>
<name>QApplication</name>
<message>
<location filename="../../src/Global_Win32.cpp" line="1063"/>
<location filename="../../src/Global_Win32.cpp" line="1064"/>
<source>Executable &apos;%1&apos; doesn&apos;t support Windows compatibility mode.</source>
<translation type="unfinished">Plik wykonywalny &apos;%1&apos; nie działa w trybie kompatybilności z Windows.</translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1005"/>
<location filename="../../src/Global_Win32.cpp" line="1006"/>
<source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source>
<translation type="unfinished">Plik wykonywalny &apos;%1&apos; wymaga Qt v%2, znaleziono jednak Qt v%3.</translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1010"/>
<location filename="../../src/Global_Win32.cpp" line="1011"/>
<source>Executable &apos;%1&apos; was built for Qt &apos;%2&apos;, but found Qt &apos;%3&apos;.</source>
<translation type="unfinished">Plik wykonywalny &quot;%1&quot; został skompilowany dla Qt &quot;%2&quot;, znaleziono &quot;%3&quot;.</translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1022"/>
<location filename="../../src/Global_Win32.cpp" line="1023"/>
<source>Executable &apos;%1&apos; requires Windows XP or later.</source>
<translation type="unfinished">Plik wykonywalny &quot;%1&quot; wymaga Windows XP lub nowszego.</translation>
</message>

View File

@ -3330,22 +3330,22 @@
<context>
<name>QApplication</name>
<message>
<location filename="../../src/Global_Win32.cpp" line="1063"/>
<location filename="../../src/Global_Win32.cpp" line="1064"/>
<source>Executable &apos;%1&apos; doesn&apos;t support Windows compatibility mode.</source>
<translation>EXE-filen &apos;%1&apos; stöder inte Windows kompatibilitetsläge.</translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1005"/>
<location filename="../../src/Global_Win32.cpp" line="1006"/>
<source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source>
<translation>EXE-filen &apos;%1&apos; kräver Qt v%2, du har Qt v%3.</translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1010"/>
<location filename="../../src/Global_Win32.cpp" line="1011"/>
<source>Executable &apos;%1&apos; was built for Qt &apos;%2&apos;, but found Qt &apos;%3&apos;.</source>
<translation>EXE-filen &apos;%1&apos; är byggd för Qt &apos;%2&apos;, du har Qt &apos;%3&apos;.</translation>
</message>
<message>
<location filename="../../src/Global_Win32.cpp" line="1022"/>
<location filename="../../src/Global_Win32.cpp" line="1023"/>
<source>Executable &apos;%1&apos; requires Windows XP or later.</source>
<translation type="unfinished"></translation>
</message>

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 9
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 10
#define VER_LAMEXP_BUILD 1511
#define VER_LAMEXP_BUILD 1512
#define VER_LAMEXP_CONFG 1348
///////////////////////////////////////////////////////////////////////////////

View File

@ -894,32 +894,29 @@ static bool lamexp_event_filter(void *message, long *result)
*/
static bool lamexp_process_is_elevated(bool *bIsUacEnabled = NULL)
{
typedef enum { lamexp_token_elevationType_class = 18, lamexp_token_elevation_class = 20 } LAMEXP_TOKEN_INFORMATION_CLASS;
typedef enum { lamexp_elevationType_default = 1, lamexp_elevationType_full, lamexp_elevationType_limited } LAMEXP_TOKEN_ELEVATION_TYPE;
bool bIsProcessElevated = false;
if(bIsUacEnabled) *bIsUacEnabled = false;
HANDLE hToken = NULL;
if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
LAMEXP_TOKEN_ELEVATION_TYPE tokenElevationType;
TOKEN_ELEVATION_TYPE tokenElevationType;
DWORD returnLength;
if(GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS) lamexp_token_elevationType_class, &tokenElevationType, sizeof(LAMEXP_TOKEN_ELEVATION_TYPE), &returnLength))
if(GetTokenInformation(hToken, TokenElevationType, &tokenElevationType, sizeof(TOKEN_ELEVATION_TYPE), &returnLength))
{
if(returnLength == sizeof(LAMEXP_TOKEN_ELEVATION_TYPE))
if(returnLength == sizeof(TOKEN_ELEVATION_TYPE))
{
switch(tokenElevationType)
{
case lamexp_elevationType_default:
case TokenElevationTypeDefault:
qDebug("Process token elevation type: Default -> UAC is disabled.\n");
break;
case lamexp_elevationType_full:
case TokenElevationTypeFull:
qWarning("Process token elevation type: Full -> potential security risk!\n");
bIsProcessElevated = true;
if(bIsUacEnabled) *bIsUacEnabled = true;
break;
case lamexp_elevationType_limited:
case TokenElevationTypeLimited:
qDebug("Process token elevation type: Limited -> not elevated.\n");
if(bIsUacEnabled) *bIsUacEnabled = true;
break;
@ -928,6 +925,10 @@ static bool lamexp_process_is_elevated(bool *bIsUacEnabled = NULL)
break;
}
}
else
{
qWarning("GetTokenInformation() return an unexpected size!");
}
}
CloseHandle(hToken);
}
@ -2170,13 +2171,72 @@ QColor lamexp_system_color(const int color_id)
}
/*
* Check if the current user is in the "admin" group (up to and including Windows XP only)
* Check if the current user is an administartor (helper function)
*/
static bool lamexp_user_is_admin_helper(void)
{
HANDLE hToken = NULL;
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
return false;
}
DWORD dwSize = 0;
if(!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
{
if(GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
CloseHandle(hToken);
return false;
}
}
PTOKEN_GROUPS lpGroups = (PTOKEN_GROUPS) malloc(dwSize);
if(!lpGroups)
{
CloseHandle(hToken);
return false;
}
if(!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
{
free(lpGroups);
CloseHandle(hToken);
return false;
}
PSID lpSid = NULL; SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
if(!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &lpSid))
{
free(lpGroups);
CloseHandle(hToken);
return false;
}
bool bResult = false;
for(DWORD i = 0; i < lpGroups->GroupCount; i++)
{
if(EqualSid(lpSid, lpGroups->Groups[i].Sid))
{
bResult = true;
break;
}
}
FreeSid(lpSid);
free(lpGroups);
CloseHandle(hToken);
return bResult;
}
/*
* Check if the current user is an administartor
*/
bool lamexp_user_is_admin(void)
{
bool isAdmin = false;
//Check for process elevation and UAC first!
//Check for process elevation and UAC support first!
if(lamexp_process_is_elevated(&isAdmin))
{
qWarning("Process is elevated -> user is admin!");
@ -2187,19 +2247,7 @@ bool lamexp_user_is_admin(void)
if(!isAdmin)
{
qDebug("UAC is disabled/unavailable -> checking for Administrators group");
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
if(AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup))
{
BOOL b = FALSE;
if(CheckTokenMembership(NULL, AdministratorsGroup, &b))
{
if(b) isAdmin = true;
}
FreeSid(AdministratorsGroup);
}
isAdmin = lamexp_user_is_admin_helper();
}
return isAdmin;