6 #include <winapi/buffer.hpp>
8 #include <winapi/sid.hpp>
9 #include <winapi/utf8.hpp>
10 #include <winapi/utils.hpp>
22 Sid Sid::well_known(WELL_KNOWN_SID_TYPE type) {
24 buffer.resize(MAX_SID_SIZE);
26 auto cb =
static_cast<DWORD
>(buffer.size());
28 if (!::CreateWellKnownSid(type, NULL, buffer.data(), &cb))
29 throw error::windows(GetLastError(),
"CreateWellKnownSid");
35 Sid Sid::builtin_administrators() {
36 return well_known(WinBuiltinAdministratorsSid);
39 std::string Sid::to_string()
const {
42 if (!::ConvertSidToStringSidW(
const_cast<Impl*
>(&get_impl()), &s))
43 throw error::windows(GetLastError(),
"ConvertSidToStringSidW");
45 return narrow(std::unique_ptr<wchar_t, LocalDelete>{s}.get());
Make std::system_error work with GetLastError().