aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/sid.hpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-14 00:00:22 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-14 00:00:22 +0300
commit69905917cf2c46fa0093df7323e5326450d1246b (patch)
tree2ec12ee6f588f7bcefab713c976ed64aa1e729ec /src/sid.hpp
parentrename the project (diff)
downloadprivilege-check-69905917cf2c46fa0093df7323e5326450d1246b.tar.gz
privilege-check-69905917cf2c46fa0093df7323e5326450d1246b.zip
move code from headers to .cpp files
Diffstat (limited to 'src/sid.hpp')
-rw-r--r--src/sid.hpp56
1 files changed, 4 insertions, 52 deletions
diff --git a/src/sid.hpp b/src/sid.hpp
index cf905a4..c84b725 100644
--- a/src/sid.hpp
+++ b/src/sid.hpp
@@ -5,69 +5,21 @@
#pragma once
-#include "error.hpp"
-
#include <Windows.h>
#include <sddl.h>
#include <array>
-#include <memory>
#include <string>
constexpr DWORD max_sid_size = SECURITY_MAX_SID_SIZE;
+
typedef std::array<unsigned char, max_sid_size> SidBuffer;
namespace sid
{
- SidBuffer well_known(WELL_KNOWN_SID_TYPE type)
- {
- SidBuffer buffer;
- DWORD cb = static_cast<DWORD>(buffer.size());
-
- if (!CreateWellKnownSid(type, NULL, buffer.data(), &cb))
- error::raise("CreateWellKnownSid");
-
- return buffer;
- }
-
- SidBuffer builtin_administrators()
- {
- /*
- void* sid = nullptr;
- SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY;
-
- if (!AllocateAndInitializeSid(
- &authority,
- 2,
- SECURITY_BUILTIN_DOMAIN_RID,
- DOMAIN_ALIAS_RID_ADMINS,
- 0, 0, 0, 0, 0, 0,
- &sid))
- {
- error::raise("AllocateAndInitializeSid");
- }
-
- return std::unique_ptr<void, FreeSid>{sid};
- */
-
- return well_known(WinBuiltinAdministratorsSid);
- }
-
- struct DeleteSidString
- {
- void operator()(wchar_t* s) const
- {
- LocalFree(s);
- }
- };
-
- std::wstring to_string(const SidBuffer& sid)
- {
- wchar_t* s = nullptr;
+ SidBuffer well_known(WELL_KNOWN_SID_TYPE type);
- if (!ConvertSidToStringSidW(const_cast<unsigned char*>(sid.data()), &s))
- error::raise("ConvertSidToStringSidW");
+ SidBuffer builtin_administrators();
- return std::unique_ptr<wchar_t, DeleteSidString>{s}.get();
- }
+ std::wstring to_string(const SidBuffer&);
}