aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/sid.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/sid.cpp90
1 files changed, 45 insertions, 45 deletions
diff --git a/src/sid.cpp b/src/sid.cpp
index 7a0e252..1a69763 100644
--- a/src/sid.cpp
+++ b/src/sid.cpp
@@ -3,69 +3,69 @@
// For details, see https://github.com/egor-tensin/privilege-check.
// Distributed under the MIT License.
-#include "error.hpp"
#include "sid.hpp"
+#include "error.hpp"
+
+/* clang-format off */
#include <windows.h>
#include <sddl.h>
+/* clang-format on */
#include <memory>
#include <string>
-namespace sid
-{
- SidBuffer well_known(WELL_KNOWN_SID_TYPE type)
- {
- SidBuffer buffer;
- DWORD cb = static_cast<DWORD>(buffer.size());
+namespace sid {
- if (!CreateWellKnownSid(type, NULL, buffer.data(), &cb))
- error::raise("CreateWellKnownSid");
+SidBuffer well_known(WELL_KNOWN_SID_TYPE type) {
+ SidBuffer buffer;
+ DWORD cb = static_cast<DWORD>(buffer.size());
- return buffer;
- }
+ 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;
- SidBuffer builtin_administrators()
+ if (!AllocateAndInitializeSid(
+ &authority,
+ 2,
+ SECURITY_BUILTIN_DOMAIN_RID,
+ DOMAIN_ALIAS_RID_ADMINS,
+ 0, 0, 0, 0, 0, 0,
+ &sid))
{
- /*
- void* sid = nullptr;
- SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY;
+ error::raise("AllocateAndInitializeSid");
+ }
- 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 std::unique_ptr<void, FreeSid>{sid};
- */
+ return well_known(WinBuiltinAdministratorsSid);
+}
- return well_known(WinBuiltinAdministratorsSid);
- }
+namespace {
- namespace
- {
- struct LocalDelete
- {
- void operator()(wchar_t* s) const
- {
- LocalFree(s);
- }
- };
+struct LocalDelete {
+ void operator()(wchar_t* s) const {
+ LocalFree(s);
}
+};
- std::wstring to_string(const SidBuffer& sid)
- {
- wchar_t* s = nullptr;
+} // namespace
- if (!ConvertSidToStringSidW(const_cast<unsigned char*>(sid.data()), &s))
- error::raise("ConvertSidToStringSidW");
+std::wstring to_string(const SidBuffer& sid) {
+ wchar_t* s = nullptr;
- return std::unique_ptr<wchar_t, LocalDelete>{s}.get();
- }
+ if (!ConvertSidToStringSidW(const_cast<unsigned char*>(sid.data()), &s))
+ error::raise("ConvertSidToStringSidW");
+
+ return std::unique_ptr<wchar_t, LocalDelete>{s}.get();
}
+
+} // namespace sid