aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cmd_line.cpp5
-rw-r--r--src/handle.cpp2
-rw-r--r--src/sid.cpp48
3 files changed, 50 insertions, 5 deletions
diff --git a/src/cmd_line.cpp b/src/cmd_line.cpp
index eaf505f..d3dc781 100644
--- a/src/cmd_line.cpp
+++ b/src/cmd_line.cpp
@@ -6,6 +6,7 @@
#include <winapi/cmd_line.hpp>
#include <winapi/error.hpp>
#include <winapi/utf8.hpp>
+#include <winapi/utils.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/config.hpp>
@@ -34,10 +35,6 @@ std::vector<std::string> narrow_all(int argc, wchar_t** argv) {
return utf;
}
-struct LocalDelete {
- void operator()(wchar_t* argv[]) const { ::LocalFree(argv); }
-};
-
CommandLine do_parse(std::wstring src) {
boost::trim(src);
if (src.empty()) {
diff --git a/src/handle.cpp b/src/handle.cpp
index 1147cf6..c94cb16 100644
--- a/src/handle.cpp
+++ b/src/handle.cpp
@@ -6,7 +6,7 @@
#include <winapi/buffer.hpp>
#include <winapi/error.hpp>
#include <winapi/handle.hpp>
-#include <winapi/workarounds.hpp>
+#include <winapi/utils.hpp>
#include <boost/config.hpp>
diff --git a/src/sid.cpp b/src/sid.cpp
new file mode 100644
index 0000000..23be61a
--- /dev/null
+++ b/src/sid.cpp
@@ -0,0 +1,48 @@
+// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+// 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 <winapi/buffer.hpp>
+#include <winapi/error.hpp>
+#include <winapi/sid.hpp>
+#include <winapi/utf8.hpp>
+#include <winapi/utils.hpp>
+
+// clang-format off
+#include <windows.h>
+#include <sddl.h>
+// clang-format on
+
+#include <memory>
+#include <string>
+
+namespace winapi {
+
+Sid Sid::well_known(WELL_KNOWN_SID_TYPE type) {
+ Buffer buffer;
+ buffer.resize(MAX_SID_SIZE);
+
+ DWORD cb = static_cast<DWORD>(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<Impl*>(&get_impl()), &s))
+ throw error::windows(GetLastError(), "ConvertSidToStringSidW");
+
+ return narrow(std::unique_ptr<wchar_t, LocalDelete>{s}.get());
+}
+
+} // namespace winapi