Bug 1572788 - Make nsXULAppInfo::GetUserCanElevate reuse GetElevationType. r=aklotz

`nsXULAppInfo::GetUserCanElevate` can reuse `GetElevationType` and we can remove
`VistaTokenElevationType` definition.

Differential Revision: https://phabricator.services.mozilla.com/D49691

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Toshihito Kikuchi 2019-10-28 14:53:42 +00:00
Родитель 0b04fad1ae
Коммит 99c8b1c9ac
3 изменённых файлов: 32 добавлений и 44 удалений

Просмотреть файл

@ -11,22 +11,11 @@
#include "mozilla/mscom/ProcessRuntime.h"
#include "mozilla/RefPtr.h"
#include "mozilla/ShellHeaderOnlyUtils.h"
#include "mozilla/WinHeaderOnlyUtils.h"
#include "nsWindowsHelpers.h"
#include <windows.h>
static mozilla::LauncherResult<TOKEN_ELEVATION_TYPE> GetElevationType(
const nsAutoHandle& aToken) {
DWORD retLen;
TOKEN_ELEVATION_TYPE elevationType;
if (!::GetTokenInformation(aToken.get(), TokenElevationType, &elevationType,
sizeof(elevationType), &retLen)) {
return LAUNCHER_ERROR_FROM_LAST();
}
return elevationType;
}
static mozilla::LauncherResult<bool> IsHighIntegrity(
const nsAutoHandle& aToken) {
DWORD reqdLen;

Просмотреть файл

@ -904,44 +904,31 @@ nsXULAppInfo::GetLauncherProcessState(uint32_t* aResult) {
}
#ifdef XP_WIN
// Matches the enum in WinNT.h for the Vista SDK but renamed so that we can
// safely build with the Vista SDK and without it.
typedef enum {
VistaTokenElevationTypeDefault = 1,
VistaTokenElevationTypeFull,
VistaTokenElevationTypeLimited
} VISTA_TOKEN_ELEVATION_TYPE;
// avoid collision with TokeElevationType enum in WinNT.h
// of the Vista SDK
# define VistaTokenElevationType static_cast<TOKEN_INFORMATION_CLASS>(18)
NS_IMETHODIMP
nsXULAppInfo::GetUserCanElevate(bool* aUserCanElevate) {
HANDLE hToken;
VISTA_TOKEN_ELEVATION_TYPE elevationType;
DWORD dwSize;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken) ||
!GetTokenInformation(hToken, VistaTokenElevationType, &elevationType,
sizeof(elevationType), &dwSize)) {
HANDLE rawToken;
if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &rawToken)) {
*aUserCanElevate = false;
} else {
// The possible values returned for elevationType and their meanings are:
// TokenElevationTypeDefault: The token does not have a linked token
// (e.g. UAC disabled or a standard user, so they can't be elevated)
// TokenElevationTypeFull: The token is linked to an elevated token
// (e.g. UAC is enabled and the user is already elevated so they can't
// be elevated again)
// TokenElevationTypeLimited: The token is linked to a limited token
// (e.g. UAC is enabled and the user is not elevated, so they can be
// elevated)
*aUserCanElevate = (elevationType == VistaTokenElevationTypeLimited);
return NS_OK;
}
if (hToken) CloseHandle(hToken);
nsAutoHandle token(rawToken);
LauncherResult<TOKEN_ELEVATION_TYPE> elevationType = GetElevationType(token);
if (elevationType.isErr()) {
*aUserCanElevate = false;
return NS_OK;
}
// The possible values returned for elevationType and their meanings are:
// TokenElevationTypeDefault: The token does not have a linked token
// (e.g. UAC disabled or a standard user, so they can't be elevated)
// TokenElevationTypeFull: The token is linked to an elevated token
// (e.g. UAC is enabled and the user is already elevated so they can't
// be elevated again)
// TokenElevationTypeLimited: The token is linked to a limited token
// (e.g. UAC is enabled and the user is not elevated, so they can be
// elevated)
*aUserCanElevate = (elevationType.inspect() == TokenElevationTypeLimited);
return NS_OK;
}
#endif

Просмотреть файл

@ -613,6 +613,18 @@ struct CoTaskMemFreeDeleter {
void operator()(void* aPtr) { ::CoTaskMemFree(aPtr); }
};
inline LauncherResult<TOKEN_ELEVATION_TYPE> GetElevationType(
const nsAutoHandle& aToken) {
DWORD retLen;
TOKEN_ELEVATION_TYPE elevationType;
if (!::GetTokenInformation(aToken.get(), TokenElevationType, &elevationType,
sizeof(elevationType), &retLen)) {
return LAUNCHER_ERROR_FROM_LAST();
}
return elevationType;
}
} // namespace mozilla
#endif // mozilla_WinHeaderOnlyUtils_h