|
|
@@ -23,7 +23,6 @@ JITManager JITManager::s_jitManager = JITManager();
|
|
|
JITManager::JITManager() :
|
|
|
m_rpcBindingHandle(nullptr),
|
|
|
m_rpcServerProcessHandle(nullptr),
|
|
|
- m_jitProcessId(0),
|
|
|
m_oopJitEnabled(false),
|
|
|
m_jitConnectionId()
|
|
|
{
|
|
|
@@ -46,24 +45,35 @@ JITManager::GetJITManager()
|
|
|
HRESULT
|
|
|
JITManager::CreateBinding(
|
|
|
__in HANDLE serverProcessHandle,
|
|
|
+ __in void * serverSecurityDescriptor,
|
|
|
__in UUID * connectionUuid,
|
|
|
__out RPC_BINDING_HANDLE * bindingHandle)
|
|
|
{
|
|
|
Assert(JITManager::IsOOPJITEnabled());
|
|
|
|
|
|
RPC_STATUS status;
|
|
|
- RPC_SECURITY_QOS_V4 securityQOS; // TODO: V5???
|
|
|
DWORD attemptCount = 0;
|
|
|
DWORD sleepInterval = 100; // in milliseconds
|
|
|
RPC_BINDING_HANDLE localBindingHandle;
|
|
|
RPC_BINDING_HANDLE_TEMPLATE_V1 bindingTemplate;
|
|
|
RPC_BINDING_HANDLE_SECURITY_V1_W bindingSecurity;
|
|
|
|
|
|
+#ifndef NTBUILD
|
|
|
+ RPC_SECURITY_QOS_V4 securityQOS;
|
|
|
ZeroMemory(&securityQOS, sizeof(RPC_SECURITY_QOS_V4));
|
|
|
securityQOS.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;
|
|
|
securityQOS.IdentityTracking = RPC_C_QOS_IDENTITY_DYNAMIC;
|
|
|
securityQOS.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY;
|
|
|
securityQOS.Version = 4;
|
|
|
+#else
|
|
|
+ RPC_SECURITY_QOS_V5 securityQOS;
|
|
|
+ ZeroMemory(&securityQOS, sizeof(RPC_SECURITY_QOS_V5));
|
|
|
+ securityQOS.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;
|
|
|
+ securityQOS.IdentityTracking = RPC_C_QOS_IDENTITY_DYNAMIC;
|
|
|
+ securityQOS.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY;
|
|
|
+ securityQOS.Version = 5;
|
|
|
+ securityQOS.ServerSecurityDescriptor = serverSecurityDescriptor;
|
|
|
+#endif // NTBUILD
|
|
|
|
|
|
ZeroMemory(&bindingTemplate, sizeof(bindingTemplate));
|
|
|
bindingTemplate.Version = 1;
|
|
|
@@ -183,7 +193,7 @@ JITManager::GetJITTargetHandle() const
|
|
|
}
|
|
|
|
|
|
HRESULT
|
|
|
-JITManager::ConnectRpcServer(DWORD proccessId, UUID connectionUuid)
|
|
|
+JITManager::ConnectRpcServer(__in HANDLE jitProcessHandle, __in_opt void* serverSecurityDescriptor, __in UUID connectionUuid)
|
|
|
{
|
|
|
Assert(JITManager::IsOOPJITEnabled());
|
|
|
|
|
|
@@ -192,7 +202,7 @@ JITManager::ConnectRpcServer(DWORD proccessId, UUID connectionUuid)
|
|
|
WCHAR* connectionUuidString = nullptr;
|
|
|
RPC_BINDING_HANDLE localBindingHandle;
|
|
|
|
|
|
- if (IsConnected() && (proccessId != m_jitProcessId || connectionUuid != m_jitConnectionId))
|
|
|
+ if (IsConnected() && (connectionUuid != m_jitConnectionId))
|
|
|
{
|
|
|
return E_FAIL;
|
|
|
}
|
|
|
@@ -203,9 +213,7 @@ JITManager::ConnectRpcServer(DWORD proccessId, UUID connectionUuid)
|
|
|
return hr;
|
|
|
}
|
|
|
|
|
|
- localServerProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccessId);
|
|
|
-
|
|
|
- hr = CreateBinding(localServerProcessHandle, &connectionUuid, &localBindingHandle);
|
|
|
+ hr = CreateBinding(jitProcessHandle, serverSecurityDescriptor, &connectionUuid, &localBindingHandle);
|
|
|
if (FAILED(hr))
|
|
|
{
|
|
|
CloseHandle(localServerProcessHandle);
|
|
|
@@ -213,10 +221,9 @@ JITManager::ConnectRpcServer(DWORD proccessId, UUID connectionUuid)
|
|
|
}
|
|
|
|
|
|
HANDLE targetHandle;
|
|
|
- HANDLE jitProcHandle = OpenProcess(PROCESS_DUP_HANDLE, FALSE, proccessId);
|
|
|
BOOL succeeded = DuplicateHandle(
|
|
|
GetCurrentProcess(), GetCurrentProcess(),
|
|
|
- jitProcHandle, &targetHandle,
|
|
|
+ jitProcessHandle, &targetHandle,
|
|
|
NULL, FALSE, DUPLICATE_SAME_ACCESS);
|
|
|
|
|
|
if (!succeeded)
|
|
|
@@ -224,14 +231,13 @@ JITManager::ConnectRpcServer(DWORD proccessId, UUID connectionUuid)
|
|
|
CloseHandle(localServerProcessHandle);
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
}
|
|
|
- if (!CloseHandle(jitProcHandle))
|
|
|
+ if (!CloseHandle(jitProcessHandle))
|
|
|
{
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
}
|
|
|
m_targetHandle = targetHandle;
|
|
|
m_rpcBindingHandle = localBindingHandle;
|
|
|
m_rpcServerProcessHandle = localServerProcessHandle;
|
|
|
- m_jitProcessId = proccessId;
|
|
|
m_jitConnectionId = connectionUuid;
|
|
|
|
|
|
return hr;
|
|
|
@@ -279,7 +285,6 @@ JITManager::DisconnectRpcServer()
|
|
|
m_targetHandle = nullptr;
|
|
|
m_rpcBindingHandle = nullptr;
|
|
|
m_rpcServerProcessHandle = nullptr;
|
|
|
- m_jitProcessId = 0;
|
|
|
m_jitConnectionId = {0};
|
|
|
|
|
|
return hr;
|