35 if (!::ImpersonateNamedPipeClient(pipe))
38 OPENVPN_THROW(named_pipe_impersonate,
"ImpersonateNamedPipeClient failed: " << err.message());
44 if (!::RevertToSelf())
46 OPENVPN_LOG(
"NamedPipeImpersonate: RevertToSelf failed, must abort");
61 limited ? (PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE) : PROCESS_ALL_ACCESS,
67 OPENVPN_THROW(npinfo_error,
"OpenProcess failed: " << err.message());
80 "(A;OICI;0x101000;;;S-1-1-0)"
86 BOOL bDaclPresent, bDaclDefaulted;
87 if (!::GetSecurityDescriptorDacl(sa.
sa.lpSecurityDescriptor,
93 OPENVPN_THROW(npinfo_error,
"allow_client_query: GetSecurityDescriptorDacl failed: " << err.message());
96 OPENVPN_THROW(npinfo_error,
"allow_client_query: missing DACL");
97 const DWORD ssi_status = ::SetSecurityInfo(
98 ::GetCurrentProcess(),
100 DACL_SECURITY_INFORMATION,
105 if (ssi_status != ERROR_SUCCESS)
108 OPENVPN_THROW(npinfo_error,
"allow_client_query: SetSecurityInfo failed: " << err.message());
113 static ULONG
get_pid(
const HANDLE np_handle,
const bool client)
118 if (!::GetNamedPipeClientProcessId(np_handle, &pid))
121 OPENVPN_THROW(npinfo_error,
"GetNamedPipeClientProcessId failed: " << err.message());
126 if (!::GetNamedPipeServerProcessId(np_handle, &pid))
129 OPENVPN_THROW(npinfo_error,
"GetNamedPipeServerProcessId failed: " << err.message());
139 const size_t exe_cap = 256;
140 wchar_t exe[exe_cap];
141 DWORD exe_size = exe_cap;
142 if (!::QueryFullProcessImageNameW(proc, 0, exe, &exe_size))
145 OPENVPN_THROW(npinfo_error,
"QueryFullProcessImageNameW failed: " << err.message());
147 return std::wstring(exe, exe_size);
155 const ULONG pid =
get_pid(handle, client);
#define OPENVPN_THROW(exc, stuff)
#define OPENVPN_LOG(args)
NamedPipeImpersonate(const HANDLE pipe)
OPENVPN_EXCEPTION(named_pipe_impersonate)
NamedPipePeerInfoCS(const HANDLE handle, const bool client)
NamedPipePeerInfoClient(const HANDLE handle)
NamedPipePeerInfoServer(const HANDLE handle)
static std::wstring get_exe_path(const HANDLE proc)
static Win::ScopedHANDLE get_process(const ULONG pid, const bool limited)
static ULONG get_pid(const HANDLE np_handle, const bool client)
OPENVPN_EXCEPTION(npinfo_error)
static void allow_client_query()