Sha256: fdd986ec05f5673159249e4d22d1575469e0cb80849c88b0592677ee7a28449f

Contents?: true

Size: 1.69 KB

Versions: 16

Compression:

Stored size: 1.69 KB

Contents

#include <internal/facts/windows/identity_resolver.hpp>
#include <leatherman/windows/system_error.hpp>
#include <leatherman/windows/user.hpp>
#include <leatherman/windows/windows.hpp>
#include <leatherman/logging/logging.hpp>
#include <boost/nowide/convert.hpp>
#include <security.h>

using namespace std;
using namespace leatherman::windows;

namespace facter { namespace facts { namespace windows {

    identity_resolver::data identity_resolver::collect_data(collection& facts)
    {
        data result;

        // Groups are a lot more flexible on Windows than Linux. We only support
        // identifying the user right now.
        ULONG size = 0ul;
        auto nameformat = NameSamCompatible;
        GetUserNameExW(nameformat, nullptr, &size);
        if (GetLastError() != ERROR_MORE_DATA) {
            LOG_DEBUG("failure resolving identity facts: {1}", leatherman::windows::system_error());
            return result;
        }

        // Use the string as a raw buffer that supports move and ref operations.
        wstring buffer(size, '\0');
        if (!GetUserNameExW(nameformat, &buffer[0], &size)) {
            LOG_DEBUG("failure resolving identity facts: {1}", leatherman::windows::system_error());
            return result;
        }

        // Resize the buffer to the returned string size.
        buffer.resize(size);
        result.user_name = boost::nowide::narrow(buffer);

        // Check whether this thread is running with elevated privileges
        // (or with the privileges of the local Administrators group on
        // older versions of Windows not supporting privileges elevation).
        result.privileged = user::is_admin();

        return result;
    }
}}}  // facter::facts::windows

Version data entries

16 entries across 16 versions & 2 rubygems

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