// Copyright (c) 2020 Egor Tensin // This file is part of the "winapi-common" project. // For details, see https://github.com/egor-tensin/winapi-common. // Distributed under the MIT License. #include #include #include #include #include // clang-format off #include #include // clang-format on #include #include namespace winapi { Sid Sid::well_known(WELL_KNOWN_SID_TYPE type) { Buffer buffer; buffer.resize(MAX_SID_SIZE); auto cb = static_cast(buffer.size()); if (!::CreateWellKnownSid(type, NULL, buffer.data(), &cb)) throw error::windows(GetLastError(), "CreateWellKnownSid"); buffer.resize(cb); return Sid{buffer}; } Sid Sid::builtin_administrators() { return well_known(WinBuiltinAdministratorsSid); } std::string Sid::to_string() const { wchar_t* s = nullptr; if (!::ConvertSidToStringSidW(const_cast(&get_impl()), &s)) throw error::windows(GetLastError(), "ConvertSidToStringSidW"); return narrow(std::unique_ptr{s}.get()); } } // namespace winapi