Sha256: d161771c6673d82b6f1fe5814d6f24eb9a5de97dd2c8d4dc65b99f7ab4a1f17d

Contents?: true

Size: 1.67 KB

Versions: 16

Compression:

Stored size: 1.67 KB

Contents

#include <leatherman/windows/system_error.hpp>
#include <leatherman/windows/windows.hpp>
#include <leatherman/util/scoped_resource.hpp>
#include <leatherman/logging/logging.hpp>

using namespace std;

namespace leatherman { namespace windows { namespace process {

    bool supports_elevated_security()
    {
        // In the future this can use IsWindowsVistaOrGreater, but as of the initial work versionhelpers.h is only in
        // the master branch of MinGW-w64.
        OSVERSIONINFOEXW vi = {sizeof(vi), HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 0, 0, {0}, 0};

        return VerifyVersionInfoW(&vi, VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR,
            VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0,
                VER_MAJORVERSION, VER_GREATER_EQUAL),
                VER_MINORVERSION, VER_GREATER_EQUAL),
                VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL));
    }

    bool has_elevated_security()
    {
        HANDLE temp_token = INVALID_HANDLE_VALUE;
        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &temp_token)) {
            LOG_DEBUG("OpenProcessToken call failed: {1}", system_error());
            return false;
        }
        util::scoped_resource<HANDLE> token(temp_token, CloseHandle);

        TOKEN_ELEVATION token_elevation;
        DWORD token_elevation_length;
        if (!GetTokenInformation(token, TokenElevation, &token_elevation, sizeof(TOKEN_ELEVATION), &token_elevation_length)) {
            LOG_DEBUG("GetTokenInformation call failed: {1}", system_error());
            return false;
        }

        return token_elevation.TokenIsElevated;
    }

}}}  // namespace leatherman::windows::process

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/leatherman/windows/src/process.cc
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/windows/src/process.cc
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/windows/src/process.cc
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/windows/src/process.cc
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/windows/src/process.cc
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/windows/src/process.cc
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/windows/src/process.cc
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/windows/src/process.cc
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/windows/src/process.cc
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/windows/src/process.cc
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/windows/src/process.cc
facter-3.9.6.cfacter.20180612 ext/facter/leatherman/windows/src/process.cc
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/windows/src/process.cc
facter-3.9.6.cfacter.20180606 ext/facter/leatherman/windows/src/process.cc
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/windows/src/process.cc
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/windows/src/process.cc