1 // Copyright (c) 2016 Ryan Prichard
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 #ifndef WINPTY_WINDOWS_SECURITY_H
22 #define WINPTY_WINDOWS_SECURITY_H
32 // PSID and PSECURITY_DESCRIPTOR are both pointers to void, but we want
33 // Sid and SecurityDescriptor to be different types.
34 struct SidTag { typedef PSID type; };
35 struct AclTag { typedef PACL type; };
36 struct SecurityDescriptorTag { typedef PSECURITY_DESCRIPTOR type; };
46 typedef typename T::type P;
48 std::unique_ptr<Impl> m_pimpl;
51 P get() const { return m_v; }
52 operator bool() const { return m_v != nullptr; }
54 SecurityItem() : m_v(nullptr) {}
55 SecurityItem(P v, std::unique_ptr<Impl> &&pimpl) :
56 m_v(v), m_pimpl(std::move(pimpl)) {}
57 SecurityItem(SecurityItem &&other) :
58 m_v(other.m_v), m_pimpl(std::move(other.m_pimpl)) {
61 SecurityItem &operator=(SecurityItem &&other) {
64 m_pimpl = std::move(other.m_pimpl);
69 typedef SecurityItem<SidTag> Sid;
70 typedef SecurityItem<AclTag> Acl;
71 typedef SecurityItem<SecurityDescriptorTag> SecurityDescriptor;
75 const wchar_t *debuggingName,
76 SID_IDENTIFIER_AUTHORITY authority,
78 DWORD subAuthority0=0,
79 DWORD subAuthority1=0);
80 Sid builtinAdminsSid();
84 SecurityDescriptor createPipeSecurityDescriptorOwnerFullControl();
85 SecurityDescriptor createPipeSecurityDescriptorOwnerFullControlEveryoneWrite();
86 SecurityDescriptor getObjectSecurityDescriptor(HANDLE handle);
88 std::wstring sidToString(PSID sid);
89 Sid stringToSid(const std::wstring &str);
90 SecurityDescriptor stringToSd(const std::wstring &str);
91 std::wstring sdToString(PSECURITY_DESCRIPTOR sd);
93 DWORD rejectRemoteClientsPipeFlag();
95 enum class GetNamedPipeClientProcessId_Result {
101 std::tuple<GetNamedPipeClientProcessId_Result, DWORD, DWORD>
102 getNamedPipeClientProcessId(HANDLE serverPipe);
104 #endif // WINPTY_WINDOWS_SECURITY_H