2012-03-26 10:45:01 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-03-26 20:20:38 +04:00
|
|
|
* Terminal Server Gateway (TSG)
|
2012-03-26 10:45:01 +04:00
|
|
|
*
|
2012-03-26 20:20:38 +04:00
|
|
|
* Copyright 2012 Fujitsu Technology Solutions GmbH
|
|
|
|
* Copyright 2012 Dmitrij Jasnov <dmitrij.jasnov@ts.fujitsu.com>
|
2015-05-29 14:46:50 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2012-03-26 10:45:01 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-03-26 10:45:01 +04:00
|
|
|
#include "config.h"
|
2012-08-15 01:09:01 +04:00
|
|
|
#endif
|
2012-03-26 20:20:38 +04:00
|
|
|
|
2012-10-30 04:54:49 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-05-05 02:32:34 +04:00
|
|
|
#include <winpr/ndr.h>
|
2012-11-12 02:23:57 +04:00
|
|
|
#include <winpr/error.h>
|
2012-12-14 05:23:37 +04:00
|
|
|
#include <winpr/print.h>
|
|
|
|
#include <winpr/stream.h>
|
2015-02-01 23:58:32 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
#include <freerdp/log.h>
|
2015-02-01 23:58:32 +03:00
|
|
|
|
|
|
|
#include "rpc_bind.h"
|
2012-11-29 07:03:18 +04:00
|
|
|
#include "rpc_client.h"
|
2012-03-26 10:45:01 +04:00
|
|
|
#include "tsg.h"
|
2016-11-21 19:28:54 +03:00
|
|
|
#include "../../crypto/opensslcompat.h"
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.gateway.tsg")
|
2014-05-21 19:32:14 +04:00
|
|
|
|
2012-04-01 10:11:07 +04:00
|
|
|
/**
|
|
|
|
* RPC Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378623/
|
|
|
|
* Remote Procedure Call: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378651/
|
|
|
|
* RPC NDR Interface Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/hh802752/
|
|
|
|
*/
|
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
/**
|
|
|
|
* call sequence with silent reauth:
|
|
|
|
*
|
|
|
|
* TsProxyCreateTunnelRequest()
|
|
|
|
* TsProxyCreateTunnelResponse(TunnelContext)
|
|
|
|
* TsProxyAuthorizeTunnelRequest(TunnelContext)
|
|
|
|
* TsProxyAuthorizeTunnelResponse()
|
|
|
|
* TsProxyMakeTunnelCallRequest(TunnelContext)
|
|
|
|
* TsProxyCreateChannelRequest(TunnelContext)
|
|
|
|
* TsProxyCreateChannelResponse(ChannelContext)
|
|
|
|
* TsProxySetupReceivePipeRequest(ChannelContext)
|
|
|
|
* TsProxySendToServerRequest(ChannelContext)
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* TsProxyMakeTunnelCallResponse(reauth)
|
|
|
|
* TsProxyCreateTunnelRequest()
|
|
|
|
* TsProxyMakeTunnelCallRequest(TunnelContext)
|
|
|
|
* TsProxyCreateTunnelResponse(NewTunnelContext)
|
|
|
|
* TsProxyAuthorizeTunnelRequest(NewTunnelContext)
|
|
|
|
* TsProxyAuthorizeTunnelResponse()
|
|
|
|
* TsProxyCreateChannelRequest(NewTunnelContext)
|
|
|
|
* TsProxyCreateChannelResponse(NewChannelContext)
|
|
|
|
* TsProxyCloseChannelRequest(NewChannelContext)
|
|
|
|
* TsProxyCloseTunnelRequest(NewTunnelContext)
|
|
|
|
* TsProxyCloseChannelResponse(NullChannelContext)
|
|
|
|
* TsProxyCloseTunnelResponse(NullTunnelContext)
|
|
|
|
* TsProxySendToServerRequest(ChannelContext)
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
DWORD TsProxySendToServer(handle_t IDL_handle, byte pRpcMessage[], UINT32 count, UINT32* lengths)
|
2012-04-01 05:32:13 +04:00
|
|
|
{
|
2012-12-14 05:23:37 +04:00
|
|
|
wStream* s;
|
2012-04-24 04:13:06 +04:00
|
|
|
int status;
|
|
|
|
rdpTsg* tsg;
|
2012-12-14 05:23:37 +04:00
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
2012-10-31 11:43:21 +04:00
|
|
|
byte* buffer1 = NULL;
|
|
|
|
byte* buffer2 = NULL;
|
|
|
|
byte* buffer3 = NULL;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 buffer1Length;
|
|
|
|
UINT32 buffer2Length;
|
|
|
|
UINT32 buffer3Length;
|
|
|
|
UINT32 numBuffers = 0;
|
|
|
|
UINT32 totalDataBytes = 0;
|
2012-04-24 04:13:06 +04:00
|
|
|
tsg = (rdpTsg*) IDL_handle;
|
|
|
|
buffer1Length = buffer2Length = buffer3Length = 0;
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
numBuffers++;
|
|
|
|
buffer1 = &pRpcMessage[0];
|
|
|
|
buffer1Length = lengths[0];
|
|
|
|
totalDataBytes += lengths[0] + 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
numBuffers++;
|
|
|
|
buffer2 = &pRpcMessage[1];
|
|
|
|
buffer2Length = lengths[1];
|
|
|
|
totalDataBytes += lengths[1] + 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 2)
|
|
|
|
{
|
|
|
|
numBuffers++;
|
|
|
|
buffer3 = &pRpcMessage[2];
|
|
|
|
buffer3Length = lengths[2];
|
|
|
|
totalDataBytes += lengths[2] + 4;
|
|
|
|
}
|
|
|
|
|
2012-12-14 05:23:37 +04:00
|
|
|
length = 28 + totalDataBytes;
|
2014-05-21 19:32:14 +04:00
|
|
|
buffer = (BYTE*) calloc(1, length);
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2012-12-14 05:23:37 +04:00
|
|
|
|
|
|
|
s = Stream_New(buffer, length);
|
2015-05-29 14:46:50 +03:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
free(buffer);
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-20 16:12:39 +03:00
|
|
|
|
2012-04-24 04:13:06 +04:00
|
|
|
/* PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE_NR (20 bytes) */
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Write(s, &tsg->ChannelContext.ContextType, 4); /* ContextType (4 bytes) */
|
|
|
|
Stream_Write(s, tsg->ChannelContext.ContextUuid, 16); /* ContextUuid (16 bytes) */
|
|
|
|
Stream_Write_UINT32_BE(s, totalDataBytes); /* totalDataBytes (4 bytes) */
|
|
|
|
Stream_Write_UINT32_BE(s, numBuffers); /* numBuffers (4 bytes) */
|
2012-04-24 04:13:06 +04:00
|
|
|
|
|
|
|
if (buffer1Length > 0)
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Write_UINT32_BE(s, buffer1Length); /* buffer1Length (4 bytes) */
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2012-04-24 04:13:06 +04:00
|
|
|
if (buffer2Length > 0)
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Write_UINT32_BE(s, buffer2Length); /* buffer2Length (4 bytes) */
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2012-04-24 04:13:06 +04:00
|
|
|
if (buffer3Length > 0)
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Write_UINT32_BE(s, buffer3Length); /* buffer3Length (4 bytes) */
|
2012-04-24 04:13:06 +04:00
|
|
|
|
|
|
|
if (buffer1Length > 0)
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Write(s, buffer1, buffer1Length); /* buffer1 (variable) */
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2012-04-24 04:13:06 +04:00
|
|
|
if (buffer2Length > 0)
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Write(s, buffer2, buffer2Length); /* buffer2 (variable) */
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2012-04-24 04:13:06 +04:00
|
|
|
if (buffer3Length > 0)
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Write(s, buffer3, buffer3Length); /* buffer3 (variable) */
|
2012-04-24 04:13:06 +04:00
|
|
|
|
2015-02-12 22:08:38 +03:00
|
|
|
Stream_SealLength(s);
|
2017-02-20 16:12:39 +03:00
|
|
|
status = rpc_client_write_call(tsg->rpc, Stream_Buffer(s), Stream_Length(s),
|
|
|
|
TsProxySendToServerOpnum);
|
2012-12-14 05:23:37 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2012-04-24 04:13:06 +04:00
|
|
|
|
|
|
|
if (status <= 0)
|
|
|
|
{
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_ERR(TAG, "rpc_write failed!");
|
2012-04-24 04:13:06 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
2012-04-01 05:32:13 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 1
|
|
|
|
*
|
|
|
|
* HRESULT TsProxyCreateTunnel(
|
|
|
|
* [in, ref] PTSG_PACKET tsgPacket,
|
|
|
|
* [out, ref] PTSG_PACKET* tsgPacketResponse,
|
|
|
|
* [out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* tunnelContext,
|
|
|
|
* [out] unsigned long* tunnelId
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg, PTSG_PACKET tsgPacket)
|
2012-03-26 10:45:01 +04:00
|
|
|
{
|
2012-10-30 04:54:49 +04:00
|
|
|
int status;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 length;
|
2015-02-16 02:22:49 +03:00
|
|
|
UINT32 offset = 0;
|
|
|
|
BYTE* buffer = NULL;
|
2012-04-19 19:29:53 +04:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCreateTunnelWriteRequest");
|
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
if (tsgPacket->packetId == TSG_PACKET_TYPE_VERSIONCAPS)
|
|
|
|
{
|
|
|
|
PTSG_PACKET_VERSIONCAPS packetVersionCaps = tsgPacket->tsgPacket.packetVersionCaps;
|
|
|
|
PTSG_CAPABILITY_NAP tsgCapNap = &packetVersionCaps->tsgCaps->tsgPacket.tsgCapNap;
|
|
|
|
length = 108;
|
|
|
|
buffer = (BYTE*) malloc(length);
|
2015-02-01 23:58:32 +03:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
2015-02-01 23:58:32 +03:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
*((UINT32*) &buffer[0]) = tsgPacket->packetId; /* PacketId (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = tsgPacket->packetId; /* SwitchValue (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[8]) = 0x00020000; /* PacketVersionCapsPtr (4 bytes) */
|
|
|
|
*((UINT16*) &buffer[12]) = packetVersionCaps->tsgHeader.ComponentId; /* ComponentId (2 bytes) */
|
|
|
|
*((UINT16*) &buffer[14]) = packetVersionCaps->tsgHeader.PacketId; /* PacketId (2 bytes) */
|
|
|
|
*((UINT32*) &buffer[16]) = 0x00020004; /* TsgCapsPtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[20]) = packetVersionCaps->numCapabilities; /* NumCapabilities (4 bytes) */
|
|
|
|
*((UINT16*) &buffer[24]) = packetVersionCaps->majorVersion; /* MajorVersion (2 bytes) */
|
|
|
|
*((UINT16*) &buffer[26]) = packetVersionCaps->minorVersion; /* MinorVersion (2 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
*((UINT16*) &buffer[28]) =
|
|
|
|
packetVersionCaps->quarantineCapabilities; /* QuarantineCapabilities (2 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
/* 4-byte alignment (30 + 2) */
|
|
|
|
*((UINT16*) &buffer[30]) = 0x0000; /* pad (2 bytes) */
|
|
|
|
*((UINT32*) &buffer[32]) = packetVersionCaps->numCapabilities; /* MaxCount (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
*((UINT32*) &buffer[36]) =
|
|
|
|
packetVersionCaps->tsgCaps->capabilityType; /* CapabilityType (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
*((UINT32*) &buffer[40]) = packetVersionCaps->tsgCaps->capabilityType; /* SwitchValue (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[44]) = tsgCapNap->capabilities; /* capabilities (4 bytes) */
|
|
|
|
offset = 48;
|
|
|
|
/**
|
|
|
|
* The following 60-byte structure is apparently undocumented,
|
|
|
|
* but parts of it can be matched to known C706 data structures.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* 8-byte constant (8A E3 13 71 02 F4 36 71) also observed here:
|
|
|
|
* http://lists.samba.org/archive/cifs-protocol/2010-July/001543.html
|
|
|
|
*/
|
|
|
|
buffer[offset + 0] = 0x8A;
|
|
|
|
buffer[offset + 1] = 0xE3;
|
|
|
|
buffer[offset + 2] = 0x13;
|
|
|
|
buffer[offset + 3] = 0x71;
|
|
|
|
buffer[offset + 4] = 0x02;
|
|
|
|
buffer[offset + 5] = 0xF4;
|
|
|
|
buffer[offset + 6] = 0x36;
|
|
|
|
buffer[offset + 7] = 0x71;
|
|
|
|
*((UINT32*) &buffer[offset + 8]) = 0x00040001; /* 1.4 (version?) */
|
|
|
|
*((UINT32*) &buffer[offset + 12]) = 0x00000001; /* 1 (element count?) */
|
|
|
|
/* p_cont_list_t */
|
|
|
|
buffer[offset + 16] = 2; /* ncontext_elem */
|
|
|
|
buffer[offset + 17] = 0x40; /* reserved1 */
|
|
|
|
*((UINT16*) &buffer[offset + 18]) = 0x0028; /* reserved2 */
|
|
|
|
/* p_syntax_id_t */
|
|
|
|
CopyMemory(&buffer[offset + 20], &TSGU_UUID, sizeof(p_uuid_t));
|
|
|
|
*((UINT32*) &buffer[offset + 36]) = TSGU_SYNTAX_IF_VERSION;
|
|
|
|
/* p_syntax_id_t */
|
|
|
|
CopyMemory(&buffer[offset + 40], &NDR_UUID, sizeof(p_uuid_t));
|
|
|
|
*((UINT32*) &buffer[offset + 56]) = NDR_SYNTAX_IF_VERSION;
|
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxyCreateTunnelOpnum);
|
2015-02-16 23:35:51 +03:00
|
|
|
free(buffer);
|
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
if (status <= 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-16 23:35:51 +03:00
|
|
|
else if (tsgPacket->packetId == TSG_PACKET_TYPE_REAUTH)
|
2015-02-16 02:22:49 +03:00
|
|
|
{
|
|
|
|
PTSG_PACKET_REAUTH packetReauth = tsgPacket->tsgPacket.packetReauth;
|
2015-02-16 23:35:51 +03:00
|
|
|
PTSG_PACKET_VERSIONCAPS packetVersionCaps = packetReauth->tsgInitialPacket.packetVersionCaps;
|
2015-02-16 02:22:49 +03:00
|
|
|
PTSG_CAPABILITY_NAP tsgCapNap = &packetVersionCaps->tsgCaps->tsgPacket.tsgCapNap;
|
|
|
|
length = 72;
|
|
|
|
buffer = (BYTE*) malloc(length);
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
*((UINT32*) &buffer[0]) = tsgPacket->packetId; /* PacketId (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[4]) = tsgPacket->packetId; /* SwitchValue (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[8]) = 0x00020000; /* PacketReauthPtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[12]) = 0; /* ??? (4 bytes) */
|
|
|
|
*((UINT64*) &buffer[16]) = packetReauth->tunnelContext; /* TunnelContext (8 bytes) */
|
|
|
|
offset = 24;
|
2015-02-16 23:35:51 +03:00
|
|
|
*((UINT32*) &buffer[offset + 0]) = TSG_PACKET_TYPE_VERSIONCAPS; /* PacketId (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[offset + 4]) = TSG_PACKET_TYPE_VERSIONCAPS; /* SwitchValue (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[offset + 8]) = 0x00020004; /* PacketVersionCapsPtr (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
*((UINT16*) &buffer[offset + 12]) =
|
|
|
|
packetVersionCaps->tsgHeader.ComponentId; /* ComponentId (2 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
*((UINT16*) &buffer[offset + 14]) = packetVersionCaps->tsgHeader.PacketId; /* PacketId (2 bytes) */
|
2015-02-16 23:35:51 +03:00
|
|
|
*((UINT32*) &buffer[offset + 16]) = 0x00020008; /* TsgCapsPtr (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
*((UINT32*) &buffer[offset + 20]) =
|
|
|
|
packetVersionCaps->numCapabilities; /* NumCapabilities (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
*((UINT16*) &buffer[offset + 24]) = packetVersionCaps->majorVersion; /* MajorVersion (2 bytes) */
|
|
|
|
*((UINT16*) &buffer[offset + 26]) = packetVersionCaps->minorVersion; /* MinorVersion (2 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
*((UINT16*) &buffer[offset + 28]) =
|
|
|
|
packetVersionCaps->quarantineCapabilities; /* QuarantineCapabilities (2 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
/* 4-byte alignment (30 + 2) */
|
|
|
|
*((UINT16*) &buffer[offset + 30]) = 0x0000; /* pad (2 bytes) */
|
|
|
|
*((UINT32*) &buffer[offset + 32]) = packetVersionCaps->numCapabilities; /* MaxCount (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
*((UINT32*) &buffer[offset + 36]) =
|
|
|
|
packetVersionCaps->tsgCaps->capabilityType; /* CapabilityType (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[offset + 40]) =
|
|
|
|
packetVersionCaps->tsgCaps->capabilityType; /* SwitchValue (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
*((UINT32*) &buffer[offset + 44]) = tsgCapNap->capabilities; /* capabilities (4 bytes) */
|
2015-02-16 23:35:51 +03:00
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxyCreateTunnelOpnum);
|
2015-02-16 02:22:49 +03:00
|
|
|
free(buffer);
|
2015-02-16 23:35:51 +03:00
|
|
|
|
|
|
|
if (status <= 0)
|
|
|
|
return FALSE;
|
2015-02-16 02:22:49 +03:00
|
|
|
}
|
2015-02-02 02:50:21 +03:00
|
|
|
|
2012-11-09 08:45:29 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
|
|
|
CONTEXT_HANDLE* tunnelContext,
|
|
|
|
UINT32* tunnelId)
|
2012-11-09 08:45:29 +04:00
|
|
|
{
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 count;
|
|
|
|
UINT32 length;
|
|
|
|
UINT32 offset;
|
|
|
|
UINT32 Pointer;
|
|
|
|
PTSG_PACKET packet;
|
|
|
|
UINT32 SwitchValue;
|
2013-11-01 18:24:19 +04:00
|
|
|
UINT32 MessageSwitchValue = 0;
|
2013-10-18 00:51:04 +04:00
|
|
|
UINT32 IsMessagePresent;
|
|
|
|
UINT32 MsgBytes;
|
2012-11-09 08:45:29 +04:00
|
|
|
PTSG_PACKET_CAPABILITIES tsgCaps;
|
|
|
|
PTSG_PACKET_VERSIONCAPS versionCaps;
|
|
|
|
PTSG_PACKET_CAPS_RESPONSE packetCapsResponse;
|
2012-11-09 12:04:47 +04:00
|
|
|
PTSG_PACKET_QUARENC_RESPONSE packetQuarEncResponse;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCreateTunnelReadResponse");
|
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
if (!pdu)
|
2012-11-09 08:45:29 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2012-12-13 00:55:42 +04:00
|
|
|
length = Stream_Length(pdu->s);
|
|
|
|
buffer = Stream_Buffer(pdu->s);
|
2012-11-09 08:45:29 +04:00
|
|
|
|
2012-12-08 02:41:12 +04:00
|
|
|
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
|
|
|
buffer = &buffer[24];
|
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
packet = (PTSG_PACKET) calloc(1, sizeof(TSG_PACKET));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!packet)
|
|
|
|
return FALSE;
|
2012-11-09 08:45:29 +04:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
offset = 4; /* PacketPtr (4 bytes) */
|
|
|
|
packet->packetId = *((UINT32*) &buffer[offset]); /* PacketId (4 bytes) */
|
|
|
|
SwitchValue = *((UINT32*) &buffer[offset + 4]); /* SwitchValue (4 bytes) */
|
2012-11-09 08:45:29 +04:00
|
|
|
|
2017-02-20 16:12:39 +03:00
|
|
|
if ((packet->packetId == TSG_PACKET_TYPE_CAPS_RESPONSE) &&
|
|
|
|
(SwitchValue == TSG_PACKET_TYPE_CAPS_RESPONSE))
|
2012-11-09 08:45:29 +04:00
|
|
|
{
|
2014-05-21 19:32:14 +04:00
|
|
|
packetCapsResponse = (PTSG_PACKET_CAPS_RESPONSE) calloc(1, sizeof(TSG_PACKET_CAPS_RESPONSE));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
if (!packetCapsResponse)
|
2014-11-17 03:00:55 +03:00
|
|
|
{
|
|
|
|
free(packet);
|
2014-05-21 19:32:14 +04:00
|
|
|
return FALSE;
|
2014-11-17 03:00:55 +03:00
|
|
|
}
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
packet->tsgPacket.packetCapsResponse = packetCapsResponse;
|
2012-11-09 12:04:47 +04:00
|
|
|
/* PacketQuarResponsePtr (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
packetCapsResponse->pktQuarEncResponse.flags = *((UINT32*) &buffer[offset +
|
|
|
|
12]); /* Flags (4 bytes) */
|
|
|
|
packetCapsResponse->pktQuarEncResponse.certChainLen = *((UINT32*) &buffer[offset +
|
|
|
|
16]); /* CertChainLength (4 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
/* CertChainDataPtr (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
CopyMemory(&packetCapsResponse->pktQuarEncResponse.nonce, &buffer[offset + 24],
|
|
|
|
16); /* Nonce (16 bytes) */
|
2012-11-27 12:04:25 +04:00
|
|
|
offset += 40;
|
2015-02-16 02:22:49 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset]); /* VersionCapsPtr (4 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 4;
|
|
|
|
|
2012-12-14 05:23:37 +04:00
|
|
|
if ((Pointer == 0x0002000C) || (Pointer == 0x00020008))
|
2012-11-09 12:04:47 +04:00
|
|
|
{
|
2015-02-16 02:22:49 +03:00
|
|
|
offset += 4; /* MsgId (4 bytes) */
|
|
|
|
offset += 4; /* MsgType (4 bytes) */
|
|
|
|
IsMessagePresent = *((UINT32*) &buffer[offset]); /* IsMessagePresent (4 bytes) */
|
2013-10-18 00:51:04 +04:00
|
|
|
offset += 4;
|
2015-02-16 02:22:49 +03:00
|
|
|
MessageSwitchValue = *((UINT32*) &buffer[offset]); /* MessageSwitchValue (4 bytes) */
|
2013-10-18 00:51:04 +04:00
|
|
|
offset += 4;
|
2012-11-09 12:04:47 +04:00
|
|
|
}
|
|
|
|
|
2012-12-14 05:23:37 +04:00
|
|
|
if (packetCapsResponse->pktQuarEncResponse.certChainLen > 0)
|
2012-11-17 03:30:53 +04:00
|
|
|
{
|
2013-10-18 00:51:04 +04:00
|
|
|
Pointer = *((UINT32*) &buffer[offset]); /* MsgPtr (4 bytes): 0x00020014 */
|
2012-11-17 03:30:53 +04:00
|
|
|
offset += 4;
|
|
|
|
offset += 4; /* MaxCount (4 bytes) */
|
|
|
|
offset += 4; /* Offset (4 bytes) */
|
|
|
|
count = *((UINT32*) &buffer[offset]); /* ActualCount (4 bytes) */
|
|
|
|
offset += 4;
|
|
|
|
/*
|
|
|
|
* CertChainData is a wide character string, and the count is
|
|
|
|
* given in characters excluding the null terminator, therefore:
|
2012-12-14 05:23:37 +04:00
|
|
|
* size = (count * 2)
|
2012-11-17 03:30:53 +04:00
|
|
|
*/
|
2012-11-27 13:05:41 +04:00
|
|
|
offset += (count * 2); /* CertChainData */
|
|
|
|
/* 4-byte alignment */
|
|
|
|
rpc_offset_align(&offset, 4);
|
2012-11-17 03:30:53 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pointer = *((UINT32*) &buffer[offset]); /* Ptr (4 bytes) */
|
|
|
|
offset += 4;
|
|
|
|
}
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
versionCaps = (PTSG_PACKET_VERSIONCAPS) calloc(1, sizeof(TSG_PACKET_VERSIONCAPS));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
if (!versionCaps)
|
2014-11-17 03:00:55 +03:00
|
|
|
{
|
|
|
|
free(packetCapsResponse);
|
|
|
|
free(packet);
|
2014-05-21 19:32:14 +04:00
|
|
|
return FALSE;
|
2014-11-17 03:00:55 +03:00
|
|
|
}
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
packetCapsResponse->pktQuarEncResponse.versionCaps = versionCaps;
|
2015-02-16 02:22:49 +03:00
|
|
|
versionCaps->tsgHeader.ComponentId = *((UINT16*) &buffer[offset]); /* ComponentId (2 bytes) */
|
|
|
|
versionCaps->tsgHeader.PacketId = *((UINT16*) &buffer[offset + 2]); /* PacketId (2 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
if (versionCaps->tsgHeader.ComponentId != TS_GATEWAY_TRANSPORT)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected ComponentId: 0x%04"PRIX16", Expected TS_GATEWAY_TRANSPORT",
|
2017-02-20 16:12:39 +03:00
|
|
|
versionCaps->tsgHeader.ComponentId);
|
2013-08-30 16:19:50 +04:00
|
|
|
free(packetCapsResponse);
|
|
|
|
free(versionCaps);
|
|
|
|
free(packet);
|
2012-11-09 12:04:47 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset]); /* TsgCapsPtr (4 bytes) */
|
|
|
|
versionCaps->numCapabilities = *((UINT32*) &buffer[offset + 4]); /* NumCapabilities (4 bytes) */
|
|
|
|
versionCaps->majorVersion = *((UINT16*) &buffer[offset + 8]); /* MajorVersion (2 bytes) */
|
|
|
|
versionCaps->minorVersion = *((UINT16*) &buffer[offset + 10]); /* MinorVersion (2 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
versionCaps->quarantineCapabilities = *((UINT16*) &buffer[offset +
|
|
|
|
12]); /* QuarantineCapabilities (2 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 14;
|
|
|
|
/* 4-byte alignment */
|
|
|
|
rpc_offset_align(&offset, 4);
|
2014-05-21 19:32:14 +04:00
|
|
|
tsgCaps = (PTSG_PACKET_CAPABILITIES) calloc(1, sizeof(TSG_PACKET_CAPABILITIES));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!tsgCaps)
|
2014-11-17 03:00:55 +03:00
|
|
|
{
|
|
|
|
free(packetCapsResponse);
|
|
|
|
free(versionCaps);
|
|
|
|
free(packet);
|
2014-05-21 19:32:14 +04:00
|
|
|
return FALSE;
|
2014-11-17 03:00:55 +03:00
|
|
|
}
|
2014-05-21 19:32:14 +04:00
|
|
|
|
2012-11-09 12:04:47 +04:00
|
|
|
versionCaps->tsgCaps = tsgCaps;
|
|
|
|
offset += 4; /* MaxCount (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
tsgCaps->capabilityType = *((UINT32*) &buffer[offset]); /* CapabilityType (4 bytes) */
|
|
|
|
SwitchValue = *((UINT32*) &buffer[offset + 4]); /* SwitchValue (4 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 8;
|
|
|
|
|
2017-02-20 16:12:39 +03:00
|
|
|
if ((SwitchValue != TSG_CAPABILITY_TYPE_NAP) ||
|
|
|
|
(tsgCaps->capabilityType != TSG_CAPABILITY_TYPE_NAP))
|
2012-11-09 12:04:47 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected CapabilityType: 0x%08"PRIX32", Expected TSG_CAPABILITY_TYPE_NAP",
|
2017-02-20 16:12:39 +03:00
|
|
|
tsgCaps->capabilityType);
|
2013-08-28 18:29:12 +04:00
|
|
|
free(tsgCaps);
|
|
|
|
free(versionCaps);
|
|
|
|
free(packetCapsResponse);
|
2013-08-30 16:19:50 +04:00
|
|
|
free(packet);
|
2012-11-09 12:04:47 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 16:12:39 +03:00
|
|
|
tsgCaps->tsgPacket.tsgCapNap.capabilities = *((UINT32*)
|
|
|
|
&buffer[offset]); /* Capabilities (4 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 4;
|
|
|
|
|
2013-11-01 18:24:19 +04:00
|
|
|
switch (MessageSwitchValue)
|
2013-10-18 00:51:04 +04:00
|
|
|
{
|
|
|
|
case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE:
|
|
|
|
case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE:
|
2015-02-16 02:22:49 +03:00
|
|
|
offset += 4; /* IsDisplayMandatory (4 bytes) */
|
|
|
|
offset += 4; /* IsConsent Mandatory (4 bytes) */
|
2013-10-18 00:51:04 +04:00
|
|
|
MsgBytes = *((UINT32*) &buffer[offset]);
|
|
|
|
offset += 4;
|
|
|
|
Pointer = *((UINT32*) &buffer[offset]);
|
|
|
|
offset += 4;
|
2013-11-01 05:12:06 +04:00
|
|
|
|
|
|
|
if (Pointer)
|
|
|
|
{
|
2015-02-16 02:22:49 +03:00
|
|
|
offset += 4; /* MaxCount (4 bytes) */
|
|
|
|
offset += 4; /* Offset (4 bytes) */
|
|
|
|
offset += 4; /* Length (4 bytes) */
|
2013-10-18 00:51:04 +04:00
|
|
|
}
|
2013-11-01 05:12:06 +04:00
|
|
|
|
|
|
|
if (MsgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Out of Spec Message Length %"PRIu32"", MsgBytes);
|
2014-04-26 09:44:28 +04:00
|
|
|
free(tsgCaps);
|
|
|
|
free(versionCaps);
|
|
|
|
free(packetCapsResponse);
|
|
|
|
free(packet);
|
2013-10-18 00:51:04 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2013-10-18 00:51:04 +04:00
|
|
|
offset += MsgBytes;
|
|
|
|
break;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2013-10-18 00:51:04 +04:00
|
|
|
case TSG_ASYNC_MESSAGE_REAUTH:
|
|
|
|
rpc_offset_align(&offset, 8);
|
2015-02-16 02:22:49 +03:00
|
|
|
offset += 8; /* TunnelContext (8 bytes) */
|
2013-10-18 00:51:04 +04:00
|
|
|
break;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2013-10-18 00:51:04 +04:00
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected Message Type: 0x%"PRIX32"", MessageSwitchValue);
|
2014-04-26 08:05:52 +04:00
|
|
|
free(tsgCaps);
|
|
|
|
free(versionCaps);
|
|
|
|
free(packetCapsResponse);
|
|
|
|
free(packet);
|
2013-10-18 00:51:04 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpc_offset_align(&offset, 4);
|
2012-11-09 21:52:34 +04:00
|
|
|
/* TunnelContext (20 bytes) */
|
2015-02-18 00:15:57 +03:00
|
|
|
CopyMemory(&tunnelContext->ContextType, &buffer[offset], 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&tunnelContext->ContextUuid, &buffer[offset + 4], 16); /* ContextUuid (16 bytes) */
|
2012-11-09 21:52:34 +04:00
|
|
|
offset += 20;
|
2015-02-18 00:15:57 +03:00
|
|
|
*tunnelId = *((UINT32*) &buffer[offset]); /* TunnelId (4 bytes) */
|
|
|
|
/* ReturnValue (4 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
free(tsgCaps);
|
|
|
|
free(versionCaps);
|
|
|
|
free(packetCapsResponse);
|
|
|
|
}
|
2017-02-20 16:12:39 +03:00
|
|
|
else if ((packet->packetId == TSG_PACKET_TYPE_QUARENC_RESPONSE) &&
|
|
|
|
(SwitchValue == TSG_PACKET_TYPE_QUARENC_RESPONSE))
|
2012-11-09 08:45:29 +04:00
|
|
|
{
|
2017-02-20 16:12:39 +03:00
|
|
|
packetQuarEncResponse = (PTSG_PACKET_QUARENC_RESPONSE) calloc(1,
|
|
|
|
sizeof(TSG_PACKET_QUARENC_RESPONSE));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
if (!packetQuarEncResponse)
|
2014-11-17 03:08:38 +03:00
|
|
|
{
|
|
|
|
free(packet);
|
2014-05-21 19:32:14 +04:00
|
|
|
return FALSE;
|
2014-11-17 03:08:38 +03:00
|
|
|
}
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
packet->tsgPacket.packetQuarEncResponse = packetQuarEncResponse;
|
2012-11-09 12:04:47 +04:00
|
|
|
/* PacketQuarResponsePtr (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
packetQuarEncResponse->flags = *((UINT32*) &buffer[offset + 12]); /* Flags (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
packetQuarEncResponse->certChainLen = *((UINT32*) &buffer[offset +
|
|
|
|
16]); /* CertChainLength (4 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
/* CertChainDataPtr (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
CopyMemory(&packetQuarEncResponse->nonce, &buffer[offset + 24], 16); /* Nonce (16 bytes) */
|
2012-11-27 12:04:25 +04:00
|
|
|
offset += 40;
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2012-11-17 03:30:53 +04:00
|
|
|
if (packetQuarEncResponse->certChainLen > 0)
|
|
|
|
{
|
|
|
|
Pointer = *((UINT32*) &buffer[offset]); /* Ptr (4 bytes): 0x0002000C */
|
|
|
|
offset += 4;
|
|
|
|
offset += 4; /* MaxCount (4 bytes) */
|
|
|
|
offset += 4; /* Offset (4 bytes) */
|
|
|
|
count = *((UINT32*) &buffer[offset]); /* ActualCount (4 bytes) */
|
|
|
|
offset += 4;
|
|
|
|
/*
|
|
|
|
* CertChainData is a wide character string, and the count is
|
|
|
|
* given in characters excluding the null terminator, therefore:
|
2012-12-14 05:23:37 +04:00
|
|
|
* size = (count * 2)
|
2012-11-17 03:30:53 +04:00
|
|
|
*/
|
2012-11-27 13:05:41 +04:00
|
|
|
offset += (count * 2); /* CertChainData */
|
|
|
|
/* 4-byte alignment */
|
|
|
|
rpc_offset_align(&offset, 4);
|
2012-11-17 03:30:53 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pointer = *((UINT32*) &buffer[offset]); /* Ptr (4 bytes): 0x00020008 */
|
|
|
|
offset += 4;
|
|
|
|
}
|
2013-10-11 13:07:33 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
versionCaps = (PTSG_PACKET_VERSIONCAPS) calloc(1, sizeof(TSG_PACKET_VERSIONCAPS));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
if (!versionCaps)
|
2014-11-17 03:08:38 +03:00
|
|
|
{
|
|
|
|
free(packetQuarEncResponse);
|
|
|
|
free(packet);
|
2014-05-21 19:32:14 +04:00
|
|
|
return FALSE;
|
2014-11-17 03:08:38 +03:00
|
|
|
}
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
packetQuarEncResponse->versionCaps = versionCaps;
|
2015-02-16 02:22:49 +03:00
|
|
|
versionCaps->tsgHeader.ComponentId = *((UINT16*) &buffer[offset]); /* ComponentId (2 bytes) */
|
|
|
|
versionCaps->tsgHeader.PacketId = *((UINT16*) &buffer[offset + 2]); /* PacketId (2 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
if (versionCaps->tsgHeader.ComponentId != TS_GATEWAY_TRANSPORT)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected ComponentId: 0x%04"PRIX16", Expected TS_GATEWAY_TRANSPORT",
|
2017-02-20 16:12:39 +03:00
|
|
|
versionCaps->tsgHeader.ComponentId);
|
2013-08-30 16:19:50 +04:00
|
|
|
free(versionCaps);
|
|
|
|
free(packetQuarEncResponse);
|
2013-08-29 17:30:22 +04:00
|
|
|
free(packet);
|
2012-11-09 12:04:47 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset]); /* TsgCapsPtr (4 bytes) */
|
|
|
|
versionCaps->numCapabilities = *((UINT32*) &buffer[offset + 4]); /* NumCapabilities (4 bytes) */
|
|
|
|
versionCaps->majorVersion = *((UINT16*) &buffer[offset + 8]); /* MajorVersion (2 bytes) */
|
|
|
|
versionCaps->majorVersion = *((UINT16*) &buffer[offset + 10]); /* MinorVersion (2 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
versionCaps->quarantineCapabilities = *((UINT16*) &buffer[offset +
|
|
|
|
12]); /* QuarantineCapabilities (2 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 14;
|
|
|
|
/* 4-byte alignment */
|
|
|
|
rpc_offset_align(&offset, 4);
|
2012-11-09 08:45:29 +04:00
|
|
|
/* Not sure exactly what this is */
|
|
|
|
offset += 4; /* 0x00000001 (4 bytes) */
|
|
|
|
offset += 4; /* 0x00000001 (4 bytes) */
|
|
|
|
offset += 4; /* 0x00000001 (4 bytes) */
|
2012-11-09 12:04:47 +04:00
|
|
|
offset += 4; /* 0x00000002 (4 bytes) */
|
2012-11-09 21:52:34 +04:00
|
|
|
/* TunnelContext (20 bytes) */
|
2015-02-18 00:15:57 +03:00
|
|
|
CopyMemory(&tunnelContext->ContextType, &buffer[offset], 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&tunnelContext->ContextUuid, &buffer[offset + 4], 16); /* ContextUuid (16 bytes) */
|
2012-11-09 21:52:34 +04:00
|
|
|
offset += 20;
|
2012-11-09 12:12:54 +04:00
|
|
|
free(versionCaps);
|
|
|
|
free(packetQuarEncResponse);
|
2012-03-26 10:45:01 +04:00
|
|
|
}
|
2012-11-09 12:04:47 +04:00
|
|
|
else
|
2012-11-09 08:45:29 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected PacketId: 0x%08"PRIX32", Expected TSG_PACKET_TYPE_CAPS_RESPONSE "
|
2017-02-20 16:12:39 +03:00
|
|
|
"or TSG_PACKET_TYPE_QUARENC_RESPONSE", packet->packetId);
|
2013-08-29 17:30:22 +04:00
|
|
|
free(packet);
|
2012-11-09 08:45:29 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(packet);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 2
|
|
|
|
*
|
|
|
|
* HRESULT TsProxyAuthorizeTunnel(
|
|
|
|
* [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
|
|
|
|
* [in, ref] PTSG_PACKET tsgPacket,
|
|
|
|
* [out, ref] PTSG_PACKET* tsgPacketResponse
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
*/
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyAuthorizeTunnelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunnelContext)
|
2012-10-30 04:54:49 +04:00
|
|
|
{
|
2012-10-31 17:22:32 +04:00
|
|
|
UINT32 pad;
|
2012-10-30 04:54:49 +04:00
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
2012-10-31 17:22:32 +04:00
|
|
|
UINT32 count;
|
2012-10-30 04:54:49 +04:00
|
|
|
UINT32 length;
|
2012-10-31 17:22:32 +04:00
|
|
|
UINT32 offset;
|
2012-10-30 04:54:49 +04:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyAuthorizeTunnelWriteRequest");
|
2012-10-31 17:22:32 +04:00
|
|
|
count = _wcslen(tsg->MachineName) + 1;
|
|
|
|
offset = 64 + (count * 2);
|
|
|
|
rpc_offset_align(&offset, 4);
|
|
|
|
offset += 4;
|
|
|
|
length = offset;
|
2012-10-30 04:54:49 +04:00
|
|
|
buffer = (BYTE*) malloc(length);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
|
|
|
CopyMemory(&buffer[0], &tunnelContext->ContextType, 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], &tunnelContext->ContextUuid, 16); /* ContextUuid (16 bytes) */
|
2012-10-31 17:22:32 +04:00
|
|
|
/* 4-byte alignment */
|
2015-02-17 22:34:42 +03:00
|
|
|
*((UINT32*) &buffer[20]) = TSG_PACKET_TYPE_QUARREQUEST; /* PacketId (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[24]) = TSG_PACKET_TYPE_QUARREQUEST; /* SwitchValue (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[28]) = 0x00020000; /* PacketQuarRequestPtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[32]) = 0x00000000; /* Flags (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[36]) = 0x00020004; /* MachineNamePtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[40]) = count; /* NameLength (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[44]) = 0x00020008; /* DataPtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[48]) = 0; /* DataLength (4 bytes) */
|
2012-10-31 17:22:32 +04:00
|
|
|
/* MachineName */
|
2015-02-17 22:34:42 +03:00
|
|
|
*((UINT32*) &buffer[52]) = count; /* MaxCount (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[56]) = 0; /* Offset (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[60]) = count; /* ActualCount (4 bytes) */
|
2012-10-31 17:22:32 +04:00
|
|
|
CopyMemory(&buffer[64], tsg->MachineName, count * 2); /* Array */
|
|
|
|
offset = 64 + (count * 2);
|
|
|
|
/* 4-byte alignment */
|
|
|
|
pad = rpc_offset_align(&offset, 4);
|
|
|
|
ZeroMemory(&buffer[offset - pad], pad);
|
2015-02-17 22:34:42 +03:00
|
|
|
*((UINT32*) &buffer[offset]) = 0x00000000; /* MaxCount (4 bytes) */
|
2012-10-31 17:22:32 +04:00
|
|
|
offset += 4;
|
2015-02-12 22:08:38 +03:00
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxyAuthorizeTunnelOpnum);
|
2015-02-17 22:34:42 +03:00
|
|
|
free(buffer);
|
|
|
|
|
2012-03-26 10:45:01 +04:00
|
|
|
if (status <= 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2012-11-09 11:31:22 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
UINT32 offset;
|
|
|
|
UINT32 Pointer;
|
|
|
|
UINT32 SizeValue;
|
|
|
|
UINT32 SwitchValue;
|
2015-01-15 00:49:21 +03:00
|
|
|
UINT32 idleTimeout;
|
2012-11-09 11:31:22 +04:00
|
|
|
PTSG_PACKET packet;
|
|
|
|
PTSG_PACKET_RESPONSE packetResponse;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyAuthorizeTunnelReadResponse");
|
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
if (!pdu)
|
2012-11-09 11:31:22 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2012-12-13 00:55:42 +04:00
|
|
|
length = Stream_Length(pdu->s);
|
|
|
|
buffer = Stream_Buffer(pdu->s);
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2012-12-08 02:41:12 +04:00
|
|
|
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
|
|
|
buffer = &buffer[24];
|
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
packet = (PTSG_PACKET) calloc(1, sizeof(TSG_PACKET));
|
|
|
|
|
|
|
|
if (!packet)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
offset = 4; /* PacketPtr (4 bytes) */
|
|
|
|
packet->packetId = *((UINT32*) &buffer[offset]); /* PacketId (4 bytes) */
|
|
|
|
SwitchValue = *((UINT32*) &buffer[offset + 4]); /* SwitchValue (4 bytes) */
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2014-03-04 20:39:39 +04:00
|
|
|
if (packet->packetId == E_PROXY_NAP_ACCESSDENIED)
|
|
|
|
{
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_ERR(TAG, "status: E_PROXY_NAP_ACCESSDENIED (0x%08X)", E_PROXY_NAP_ACCESSDENIED);
|
|
|
|
WLog_ERR(TAG, "Ensure that the Gateway Connection Authorization Policy is correct");
|
2014-04-26 08:05:52 +04:00
|
|
|
free(packet);
|
2014-03-04 20:39:39 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-02 02:52:19 +04:00
|
|
|
if ((packet->packetId != TSG_PACKET_TYPE_RESPONSE) || (SwitchValue != TSG_PACKET_TYPE_RESPONSE))
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected PacketId: 0x%08"PRIX32", Expected TSG_PACKET_TYPE_RESPONSE",
|
2017-02-20 16:12:39 +03:00
|
|
|
packet->packetId);
|
2013-08-29 17:30:22 +04:00
|
|
|
free(packet);
|
2012-11-09 11:31:22 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
packetResponse = (PTSG_PACKET_RESPONSE) calloc(1, sizeof(TSG_PACKET_RESPONSE));
|
|
|
|
|
|
|
|
if (!packetResponse)
|
2015-03-13 06:26:22 +03:00
|
|
|
{
|
|
|
|
free(packet);
|
2015-01-13 21:50:46 +03:00
|
|
|
return FALSE;
|
2015-03-13 06:26:22 +03:00
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2012-11-09 11:31:22 +04:00
|
|
|
packet->tsgPacket.packetResponse = packetResponse;
|
2015-02-17 22:34:42 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset + 8]); /* PacketResponsePtr (4 bytes) */
|
|
|
|
packetResponse->flags = *((UINT32*) &buffer[offset + 12]); /* Flags (4 bytes) */
|
2012-11-09 11:31:22 +04:00
|
|
|
|
|
|
|
if (packetResponse->flags != TSG_PACKET_TYPE_QUARREQUEST)
|
2012-03-26 10:45:01 +04:00
|
|
|
{
|
2017-02-20 16:12:39 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Unexpected Packet Response Flags: 0x%08"PRIX32", Expected TSG_PACKET_TYPE_QUARREQUEST",
|
|
|
|
packetResponse->flags);
|
2013-08-29 17:30:22 +04:00
|
|
|
free(packet);
|
|
|
|
free(packetResponse);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-26 10:45:01 +04:00
|
|
|
}
|
|
|
|
|
2012-11-09 11:31:22 +04:00
|
|
|
/* Reserved (4 bytes) */
|
2015-02-17 22:34:42 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset + 20]); /* ResponseDataPtr (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
packetResponse->responseDataLen = *((UINT32*) &buffer[offset +
|
|
|
|
24]); /* ResponseDataLength (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.enableAllRedirections = *((UINT32*) &buffer[offset +
|
|
|
|
28]); /* EnableAllRedirections (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.disableAllRedirections = *((UINT32*) &buffer[offset +
|
|
|
|
32]); /* DisableAllRedirections (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.driveRedirectionDisabled = *((UINT32*) &buffer[offset +
|
|
|
|
36]); /* DriveRedirectionDisabled (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.printerRedirectionDisabled = *((UINT32*) &buffer[offset +
|
|
|
|
40]); /* PrinterRedirectionDisabled (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.portRedirectionDisabled = *((UINT32*) &buffer[offset +
|
|
|
|
44]); /* PortRedirectionDisabled (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.reserved = *((UINT32*) &buffer[offset +
|
|
|
|
48]); /* Reserved (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.clipboardRedirectionDisabled = *((UINT32*) &buffer[offset +
|
|
|
|
52]); /* ClipboardRedirectionDisabled (4 bytes) */
|
|
|
|
packetResponse->redirectionFlags.pnpRedirectionDisabled = *((UINT32*) &buffer[offset +
|
|
|
|
56]); /* PnpRedirectionDisabled (4 bytes) */
|
2012-11-29 06:25:01 +04:00
|
|
|
offset += 60;
|
2015-02-17 22:34:42 +03:00
|
|
|
SizeValue = *((UINT32*) &buffer[offset]); /* (4 bytes) */
|
2012-11-09 11:31:22 +04:00
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
if (SizeValue != packetResponse->responseDataLen)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected size value: %"PRIu32", expected: %"PRIu32"",
|
2017-02-20 16:12:39 +03:00
|
|
|
SizeValue, packetResponse->responseDataLen);
|
2013-08-28 18:28:00 +04:00
|
|
|
free(packetResponse);
|
|
|
|
free(packet);
|
2012-11-09 11:31:22 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-02-20 16:12:39 +03:00
|
|
|
|
2015-01-15 00:49:21 +03:00
|
|
|
if (SizeValue == 4)
|
|
|
|
{
|
|
|
|
idleTimeout = *((UINT32*) &buffer[offset]);
|
|
|
|
offset += 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset += SizeValue; /* ResponseData */
|
|
|
|
}
|
2017-02-20 16:12:39 +03:00
|
|
|
|
2012-11-09 11:31:22 +04:00
|
|
|
free(packetResponse);
|
|
|
|
free(packet);
|
2012-10-30 04:54:49 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 3
|
|
|
|
*
|
|
|
|
* HRESULT TsProxyMakeTunnelCall(
|
|
|
|
* [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
|
|
|
|
* [in] unsigned long procId,
|
|
|
|
* [in, ref] PTSG_PACKET tsgPacket,
|
|
|
|
* [out, ref] PTSG_PACKET* tsgPacketResponse
|
|
|
|
* );
|
|
|
|
*/
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyMakeTunnelCallWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunnelContext,
|
|
|
|
UINT32 procId)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyMakeTunnelCallWriteRequest");
|
2012-10-31 18:52:04 +04:00
|
|
|
length = 40;
|
2012-10-30 04:54:49 +04:00
|
|
|
buffer = (BYTE*) malloc(length);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
|
|
|
CopyMemory(&buffer[0], &tunnelContext->ContextType, 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], &tunnelContext->ContextUuid, 16); /* ContextUuid (16 bytes) */
|
2015-02-17 22:34:42 +03:00
|
|
|
*((UINT32*) &buffer[20]) = procId; /* ProcId (4 bytes) */
|
2012-10-31 18:52:04 +04:00
|
|
|
/* 4-byte alignment */
|
2015-02-17 22:34:42 +03:00
|
|
|
*((UINT32*) &buffer[24]) = TSG_PACKET_TYPE_MSGREQUEST_PACKET; /* PacketId (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[28]) = TSG_PACKET_TYPE_MSGREQUEST_PACKET; /* SwitchValue (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[32]) = 0x00020000; /* PacketMsgRequestPtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[36]) = 0x00000001; /* MaxMessagesPerBatch (4 bytes) */
|
2015-02-12 22:08:38 +03:00
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxyMakeTunnelCallOpnum);
|
2015-02-17 22:34:42 +03:00
|
|
|
free(buffer);
|
|
|
|
|
2012-03-26 10:45:01 +04:00
|
|
|
if (status <= 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2012-10-30 04:54:49 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
2012-10-30 04:54:49 +04:00
|
|
|
{
|
2013-02-02 02:52:19 +04:00
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
UINT32 offset;
|
|
|
|
UINT32 Pointer;
|
|
|
|
UINT32 MaxCount;
|
|
|
|
UINT32 ActualCount;
|
|
|
|
UINT32 SwitchValue;
|
|
|
|
PTSG_PACKET packet;
|
2015-02-16 02:22:49 +03:00
|
|
|
BOOL status = TRUE;
|
2013-03-14 20:57:45 +04:00
|
|
|
char* messageText = NULL;
|
2015-02-16 23:35:51 +03:00
|
|
|
PTSG_PACKET_MSG_RESPONSE packetMsgResponse = NULL;
|
2013-02-02 02:52:19 +04:00
|
|
|
PTSG_PACKET_STRING_MESSAGE packetStringMessage = NULL;
|
|
|
|
PTSG_PACKET_REAUTH_MESSAGE packetReauthMessage = NULL;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyMakeTunnelCallReadResponse");
|
|
|
|
|
2013-02-02 02:52:19 +04:00
|
|
|
/* This is an asynchronous response */
|
|
|
|
|
|
|
|
if (!pdu)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
length = Stream_Length(pdu->s);
|
|
|
|
buffer = Stream_Buffer(pdu->s);
|
|
|
|
|
|
|
|
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
|
|
|
buffer = &buffer[24];
|
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
packet = (PTSG_PACKET) calloc(1, sizeof(TSG_PACKET));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!packet)
|
|
|
|
return FALSE;
|
2013-02-02 02:52:19 +04:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
offset = 4; /* PacketPtr (4 bytes) */
|
|
|
|
packet->packetId = *((UINT32*) &buffer[offset]); /* PacketId (4 bytes) */
|
|
|
|
SwitchValue = *((UINT32*) &buffer[offset + 4]); /* SwitchValue (4 bytes) */
|
2013-02-02 02:52:19 +04:00
|
|
|
|
2017-02-20 16:12:39 +03:00
|
|
|
if ((packet->packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) ||
|
|
|
|
(SwitchValue != TSG_PACKET_TYPE_MESSAGE_PACKET))
|
2013-02-02 02:52:19 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected PacketId: 0x%08"PRIX32", Expected TSG_PACKET_TYPE_MESSAGE_PACKET",
|
2017-02-20 16:12:39 +03:00
|
|
|
packet->packetId);
|
2013-08-29 17:30:22 +04:00
|
|
|
free(packet);
|
2013-02-02 02:52:19 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
packetMsgResponse = (PTSG_PACKET_MSG_RESPONSE) calloc(1, sizeof(TSG_PACKET_MSG_RESPONSE));
|
|
|
|
|
|
|
|
if (!packetMsgResponse)
|
2015-03-13 06:26:22 +03:00
|
|
|
{
|
|
|
|
free(packet);
|
2015-01-13 21:50:46 +03:00
|
|
|
return FALSE;
|
2015-03-13 06:26:22 +03:00
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2013-02-02 02:52:19 +04:00
|
|
|
packet->tsgPacket.packetMsgResponse = packetMsgResponse;
|
2015-02-16 02:22:49 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset + 8]); /* PacketMsgResponsePtr (4 bytes) */
|
|
|
|
packetMsgResponse->msgID = *((UINT32*) &buffer[offset + 12]); /* MsgId (4 bytes) */
|
|
|
|
packetMsgResponse->msgType = *((UINT32*) &buffer[offset + 16]); /* MsgType (4 bytes) */
|
|
|
|
packetMsgResponse->isMsgPresent = *((INT32*) &buffer[offset + 20]); /* IsMsgPresent (4 bytes) */
|
|
|
|
SwitchValue = *((UINT32*) &buffer[offset + 24]); /* SwitchValue (4 bytes) */
|
2013-02-02 02:52:19 +04:00
|
|
|
|
|
|
|
switch (SwitchValue)
|
|
|
|
{
|
2014-08-19 20:26:39 +04:00
|
|
|
case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE:
|
2015-01-13 21:50:46 +03:00
|
|
|
packetStringMessage = (PTSG_PACKET_STRING_MESSAGE) calloc(1, sizeof(TSG_PACKET_STRING_MESSAGE));
|
|
|
|
|
|
|
|
if (!packetStringMessage)
|
2015-03-13 06:26:22 +03:00
|
|
|
{
|
|
|
|
status = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
packetMsgResponse->messagePacket.consentMessage = packetStringMessage;
|
2015-02-17 22:34:42 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset + 28]); /* ConsentMessagePtr (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
packetStringMessage->isDisplayMandatory = *((INT32*) &buffer[offset +
|
|
|
|
32]); /* IsDisplayMandatory (4 bytes) */
|
|
|
|
packetStringMessage->isConsentMandatory = *((INT32*) &buffer[offset +
|
|
|
|
36]); /* IsConsentMandatory (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
packetStringMessage->msgBytes = *((UINT32*) &buffer[offset + 40]); /* MsgBytes (4 bytes) */
|
|
|
|
Pointer = *((UINT32*) &buffer[offset + 44]); /* MsgPtr (4 bytes) */
|
|
|
|
MaxCount = *((UINT32*) &buffer[offset + 48]); /* MaxCount (4 bytes) */
|
|
|
|
/* Offset (4 bytes) */
|
|
|
|
ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL,
|
|
|
|
NULL);
|
2015-02-16 02:22:49 +03:00
|
|
|
WLog_INFO(TAG, "Consent Message: %s", messageText);
|
2014-08-19 20:26:39 +04:00
|
|
|
free(messageText);
|
|
|
|
break;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE:
|
2015-01-13 21:50:46 +03:00
|
|
|
packetStringMessage = (PTSG_PACKET_STRING_MESSAGE) calloc(1, sizeof(TSG_PACKET_STRING_MESSAGE));
|
|
|
|
|
|
|
|
if (!packetStringMessage)
|
2015-03-13 06:26:22 +03:00
|
|
|
{
|
|
|
|
status = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
packetMsgResponse->messagePacket.serviceMessage = packetStringMessage;
|
2015-02-16 02:22:49 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset + 28]); /* ServiceMessagePtr (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
packetStringMessage->isDisplayMandatory = *((INT32*) &buffer[offset +
|
|
|
|
32]); /* IsDisplayMandatory (4 bytes) */
|
|
|
|
packetStringMessage->isConsentMandatory = *((INT32*) &buffer[offset +
|
|
|
|
36]); /* IsConsentMandatory (4 bytes) */
|
2015-02-16 02:22:49 +03:00
|
|
|
packetStringMessage->msgBytes = *((UINT32*) &buffer[offset + 40]); /* MsgBytes (4 bytes) */
|
|
|
|
Pointer = *((UINT32*) &buffer[offset + 44]); /* MsgPtr (4 bytes) */
|
|
|
|
MaxCount = *((UINT32*) &buffer[offset + 48]); /* MaxCount (4 bytes) */
|
|
|
|
/* Offset (4 bytes) */
|
|
|
|
ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL,
|
|
|
|
NULL);
|
2015-02-16 02:22:49 +03:00
|
|
|
WLog_INFO(TAG, "Service Message: %s", messageText);
|
2014-08-19 20:26:39 +04:00
|
|
|
free(messageText);
|
|
|
|
break;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
case TSG_ASYNC_MESSAGE_REAUTH:
|
2015-01-13 21:50:46 +03:00
|
|
|
packetReauthMessage = (PTSG_PACKET_REAUTH_MESSAGE) calloc(1, sizeof(TSG_PACKET_REAUTH_MESSAGE));
|
|
|
|
|
|
|
|
if (!packetReauthMessage)
|
2015-03-13 06:26:22 +03:00
|
|
|
{
|
|
|
|
status = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
packetMsgResponse->messagePacket.reauthMessage = packetReauthMessage;
|
2015-02-16 02:22:49 +03:00
|
|
|
Pointer = *((UINT32*) &buffer[offset + 28]); /* ReauthMessagePtr (4 bytes) */
|
2015-02-17 22:34:42 +03:00
|
|
|
/* alignment pad (4 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
packetReauthMessage->tunnelContext = *((UINT64*) &buffer[offset +
|
|
|
|
36]); /* TunnelContext (8 bytes) */
|
2015-02-16 23:35:51 +03:00
|
|
|
/* ReturnValue (4 bytes) */
|
|
|
|
tsg->ReauthTunnelContext = packetReauthMessage->tunnelContext;
|
2014-08-19 20:26:39 +04:00
|
|
|
break;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "unexpected message type: %"PRIu32"", SwitchValue);
|
2015-02-16 02:22:49 +03:00
|
|
|
status = FALSE;
|
2014-08-19 20:26:39 +04:00
|
|
|
break;
|
2013-02-02 02:52:19 +04:00
|
|
|
}
|
|
|
|
|
2015-03-13 06:26:22 +03:00
|
|
|
out:
|
2017-02-20 16:12:39 +03:00
|
|
|
|
2013-08-28 18:31:35 +04:00
|
|
|
if (packet)
|
2013-09-02 17:06:25 +04:00
|
|
|
{
|
|
|
|
if (packet->tsgPacket.packetMsgResponse)
|
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(packet->tsgPacket.packetMsgResponse->messagePacket.reauthMessage);
|
2013-09-02 17:06:25 +04:00
|
|
|
free(packet->tsgPacket.packetMsgResponse);
|
|
|
|
}
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2013-08-28 18:31:35 +04:00
|
|
|
free(packet);
|
2013-09-02 17:06:25 +04:00
|
|
|
}
|
2013-08-28 18:31:35 +04:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
return status;
|
2012-11-09 11:31:22 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 4
|
|
|
|
*
|
|
|
|
* HRESULT TsProxyCreateChannel(
|
|
|
|
* [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
|
|
|
|
* [in, ref] PTSENDPOINTINFO tsEndPointInfo,
|
|
|
|
* [out] PCHANNEL_CONTEXT_HANDLE_SERIALIZE* channelContext,
|
|
|
|
* [out] unsigned long* channelId
|
|
|
|
* );
|
|
|
|
*/
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCreateChannelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunnelContext)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
UINT32 count;
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2012-10-31 20:34:52 +04:00
|
|
|
count = _wcslen(tsg->Hostname) + 1;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCreateChannelWriteRequest");
|
2012-10-31 20:34:52 +04:00
|
|
|
length = 60 + (count * 2);
|
2012-10-30 21:01:54 +04:00
|
|
|
buffer = (BYTE*) malloc(length);
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
|
|
|
CopyMemory(&buffer[0], &tunnelContext->ContextType, 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], &tunnelContext->ContextUuid, 16); /* ContextUuid (16 bytes) */
|
2012-10-31 20:34:52 +04:00
|
|
|
/* TSENDPOINTINFO */
|
2015-02-17 22:34:42 +03:00
|
|
|
*((UINT32*) &buffer[20]) = 0x00020000; /* ResourceNamePtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[24]) = 0x00000001; /* NumResourceNames (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[28]) = 0x00000000; /* AlternateResourceNamesPtr (4 bytes) */
|
|
|
|
*((UINT16*) &buffer[32]) = 0x0000; /* NumAlternateResourceNames (2 bytes) */
|
2012-12-21 21:17:07 +04:00
|
|
|
*((UINT16*) &buffer[34]) = 0x0000; /* Pad (2 bytes) */
|
|
|
|
/* Port (4 bytes) */
|
2015-02-17 22:34:42 +03:00
|
|
|
*((UINT16*) &buffer[36]) = 0x0003; /* ProtocolId (RDP = 3) (2 bytes) */
|
|
|
|
*((UINT16*) &buffer[38]) = tsg->Port; /* PortNumber (0xD3D = 3389) (2 bytes) */
|
|
|
|
*((UINT32*) &buffer[40]) = 0x00000001; /* NumResourceNames (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[44]) = 0x00020004; /* ResourceNamePtr (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[48]) = count; /* MaxCount (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[52]) = 0; /* Offset (4 bytes) */
|
|
|
|
*((UINT32*) &buffer[56]) = count; /* ActualCount (4 bytes) */
|
2012-10-31 20:34:52 +04:00
|
|
|
CopyMemory(&buffer[60], tsg->Hostname, count * 2); /* Array */
|
2015-02-12 22:08:38 +03:00
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxyCreateChannelOpnum);
|
2015-02-17 22:34:42 +03:00
|
|
|
free(buffer);
|
|
|
|
|
2012-03-26 10:45:01 +04:00
|
|
|
if (status <= 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2012-11-09 11:31:22 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCreateChannelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
|
|
|
CONTEXT_HANDLE* channelContext,
|
|
|
|
UINT32* channelId)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
|
|
|
BYTE* buffer;
|
2012-12-08 02:41:12 +04:00
|
|
|
UINT32 offset;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCreateChannelReadResponse");
|
|
|
|
|
2012-11-29 06:25:01 +04:00
|
|
|
if (!pdu)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2012-12-13 00:55:42 +04:00
|
|
|
buffer = Stream_Buffer(pdu->s);
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2012-12-08 02:41:12 +04:00
|
|
|
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
|
|
|
buffer = &buffer[24];
|
|
|
|
|
|
|
|
offset = 0;
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
|
|
|
CopyMemory(&channelContext->ContextType, &buffer[offset], 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&channelContext->ContextUuid, &buffer[offset + 4], 16); /* ContextUuid (16 bytes) */
|
|
|
|
offset += 20;
|
|
|
|
*channelId = *((UINT32*) &buffer[offset]); /* ChannelId (4 bytes) */
|
|
|
|
/* ReturnValue (4 bytes) */
|
2012-11-09 11:31:22 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* HRESULT TsProxyCloseChannel(
|
|
|
|
* [in, out] PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE* context
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCloseChannelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* context)
|
2012-11-09 23:35:21 +04:00
|
|
|
{
|
2012-12-13 21:40:46 +04:00
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCloseChannelWriteRequest");
|
|
|
|
|
2015-08-28 11:59:48 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-12-13 21:40:46 +04:00
|
|
|
length = 20;
|
|
|
|
buffer = (BYTE*) malloc(length);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
|
|
|
CopyMemory(&buffer[0], &context->ContextType, 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], &context->ContextUuid, 16); /* ContextUuid (16 bytes) */
|
2015-02-12 22:08:38 +03:00
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxyCloseChannelOpnum);
|
2015-02-17 22:34:42 +03:00
|
|
|
free(buffer);
|
|
|
|
|
2012-12-13 21:40:46 +04:00
|
|
|
if (status <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-11-09 23:35:21 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCloseChannelReadResponse(rdpTsg* tsg, RPC_PDU* pdu, CONTEXT_HANDLE* context)
|
2012-11-09 23:35:21 +04:00
|
|
|
{
|
2012-12-13 21:40:46 +04:00
|
|
|
BYTE* buffer;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCloseChannelReadResponse");
|
|
|
|
|
2012-12-13 21:40:46 +04:00
|
|
|
if (!pdu)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
buffer = Stream_Buffer(pdu->s);
|
|
|
|
|
|
|
|
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
|
|
|
buffer = &buffer[24];
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
CopyMemory(&context->ContextType, &buffer[0], 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&context->ContextUuid, &buffer[4], 16); /* ContextUuid (16 bytes) */
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ReturnValue (4 bytes) */
|
2012-12-13 21:40:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* HRESULT TsProxyCloseTunnel(
|
|
|
|
* [in, out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* context
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCloseTunnelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* context)
|
2012-12-13 21:40:46 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCloseTunnelWriteRequest");
|
2012-12-13 21:40:46 +04:00
|
|
|
length = 20;
|
|
|
|
buffer = (BYTE*) malloc(length);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
|
|
|
CopyMemory(&buffer[0], &context->ContextType, 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], &context->ContextUuid, 16); /* ContextUuid (16 bytes) */
|
2015-02-12 22:08:38 +03:00
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxyCloseTunnelOpnum);
|
2015-02-17 22:34:42 +03:00
|
|
|
free(buffer);
|
|
|
|
|
2012-12-13 21:40:46 +04:00
|
|
|
if (status <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyCloseTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu, CONTEXT_HANDLE* context)
|
2012-12-13 21:40:46 +04:00
|
|
|
{
|
|
|
|
BYTE* buffer;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxyCloseTunnelReadResponse");
|
|
|
|
|
2012-12-13 21:40:46 +04:00
|
|
|
if (!pdu)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
buffer = Stream_Buffer(pdu->s);
|
|
|
|
|
|
|
|
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
|
|
|
buffer = &buffer[24];
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
2017-02-20 16:12:39 +03:00
|
|
|
CopyMemory(&context->ContextType, &buffer[0], 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&context->ContextUuid, &buffer[4], 16); /* ContextUuid (16 bytes) */
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ReturnValue (4 bytes) */
|
2012-12-13 21:40:46 +04:00
|
|
|
return TRUE;
|
2012-11-09 23:35:21 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 8
|
|
|
|
*
|
|
|
|
* DWORD TsProxySetupReceivePipe(
|
|
|
|
* [in, max_is(32767)] byte pRpcMessage[]
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxySetupReceivePipeWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* channelContext)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2015-02-17 22:34:42 +03:00
|
|
|
WLog_DBG(TAG, "TsProxySetupReceivePipeWriteRequest");
|
2012-10-31 20:34:52 +04:00
|
|
|
length = 20;
|
2012-10-30 04:54:49 +04:00
|
|
|
buffer = (BYTE*) malloc(length);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
|
|
|
CopyMemory(&buffer[0], &channelContext->ContextType, 4); /* ContextType (4 bytes) */
|
|
|
|
CopyMemory(&buffer[4], &channelContext->ContextUuid, 16); /* ContextUuid (16 bytes) */
|
2015-02-12 22:08:38 +03:00
|
|
|
status = rpc_client_write_call(rpc, buffer, length, TsProxySetupReceivePipeOpnum);
|
2015-02-17 22:34:42 +03:00
|
|
|
free(buffer);
|
|
|
|
|
2012-03-26 10:45:01 +04:00
|
|
|
if (status <= 0)
|
2012-10-30 04:54:49 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2012-11-09 11:31:22 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-03 02:50:26 +03:00
|
|
|
int tsg_transition_to_state(rdpTsg* tsg, TSG_STATE state)
|
|
|
|
{
|
|
|
|
const char* str = "TSG_STATE_UNKNOWN";
|
|
|
|
|
2015-02-04 01:17:17 +03:00
|
|
|
switch (state)
|
2015-02-03 02:50:26 +03:00
|
|
|
{
|
|
|
|
case TSG_STATE_INITIAL:
|
|
|
|
str = "TSG_STATE_INITIAL";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_CONNECTED:
|
|
|
|
str = "TSG_STATE_CONNECTED";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_AUTHORIZED:
|
|
|
|
str = "TSG_STATE_AUTHORIZED";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_CHANNEL_CREATED:
|
|
|
|
str = "TSG_STATE_CHANNEL_CREATED";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_PIPE_CREATED:
|
|
|
|
str = "TSG_STATE_PIPE_CREATED";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_TUNNEL_CLOSE_PENDING:
|
|
|
|
str = "TSG_STATE_TUNNEL_CLOSE_PENDING";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_CHANNEL_CLOSE_PENDING:
|
|
|
|
str = "TSG_STATE_CHANNEL_CLOSE_PENDING";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_FINAL:
|
|
|
|
str = "TSG_STATE_FINAL";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsg->state = state;
|
|
|
|
WLog_DBG(TAG, "%s", str);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-16 23:35:51 +03:00
|
|
|
int tsg_proxy_begin(rdpTsg* tsg)
|
|
|
|
{
|
|
|
|
TSG_PACKET tsgPacket;
|
|
|
|
PTSG_CAPABILITY_NAP tsgCapNap;
|
|
|
|
PTSG_PACKET_VERSIONCAPS packetVersionCaps;
|
|
|
|
packetVersionCaps = &tsg->packetVersionCaps;
|
|
|
|
packetVersionCaps->tsgCaps = &tsg->tsgCaps;
|
|
|
|
tsgCapNap = &tsg->tsgCaps.tsgPacket.tsgCapNap;
|
|
|
|
tsgPacket.packetId = TSG_PACKET_TYPE_VERSIONCAPS;
|
|
|
|
tsgPacket.tsgPacket.packetVersionCaps = packetVersionCaps;
|
|
|
|
packetVersionCaps->tsgHeader.ComponentId = TS_GATEWAY_TRANSPORT;
|
|
|
|
packetVersionCaps->tsgHeader.PacketId = TSG_PACKET_TYPE_VERSIONCAPS;
|
|
|
|
packetVersionCaps->numCapabilities = 1;
|
|
|
|
packetVersionCaps->majorVersion = 1;
|
|
|
|
packetVersionCaps->minorVersion = 1;
|
|
|
|
packetVersionCaps->quarantineCapabilities = 0;
|
|
|
|
packetVersionCaps->tsgCaps->capabilityType = TSG_CAPABILITY_TYPE_NAP;
|
|
|
|
/*
|
|
|
|
* Using reduced capabilities appears to trigger
|
|
|
|
* TSG_PACKET_TYPE_QUARENC_RESPONSE instead of TSG_PACKET_TYPE_CAPS_RESPONSE
|
|
|
|
*
|
|
|
|
* However, reduced capabilities may break connectivity with servers enforcing features, such as
|
|
|
|
* "Only allow connections from Remote Desktop Services clients that support RD Gateway messaging"
|
|
|
|
*/
|
|
|
|
tsgCapNap->capabilities =
|
2017-02-20 16:12:39 +03:00
|
|
|
TSG_NAP_CAPABILITY_QUAR_SOH |
|
|
|
|
TSG_NAP_CAPABILITY_IDLE_TIMEOUT |
|
|
|
|
TSG_MESSAGING_CAP_CONSENT_SIGN |
|
|
|
|
TSG_MESSAGING_CAP_SERVICE_MSG |
|
|
|
|
TSG_MESSAGING_CAP_REAUTH;
|
2015-02-16 23:35:51 +03:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxyCreateTunnelWriteRequest(tsg, &tsgPacket))
|
2015-02-16 23:35:51 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCreateTunnel failure");
|
|
|
|
tsg->state = TSG_STATE_FINAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_INITIAL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tsg_proxy_reauth(rdpTsg* tsg)
|
|
|
|
{
|
|
|
|
TSG_PACKET tsgPacket;
|
|
|
|
PTSG_PACKET_REAUTH packetReauth;
|
|
|
|
PTSG_PACKET_VERSIONCAPS packetVersionCaps;
|
2015-02-17 22:34:42 +03:00
|
|
|
tsg->reauthSequence = TRUE;
|
2015-02-16 23:35:51 +03:00
|
|
|
packetReauth = &tsg->packetReauth;
|
|
|
|
packetVersionCaps = &tsg->packetVersionCaps;
|
|
|
|
tsgPacket.packetId = TSG_PACKET_TYPE_REAUTH;
|
|
|
|
tsgPacket.tsgPacket.packetReauth = &tsg->packetReauth;
|
|
|
|
packetReauth->tunnelContext = tsg->ReauthTunnelContext;
|
|
|
|
packetReauth->packetId = TSG_PACKET_TYPE_VERSIONCAPS;
|
|
|
|
packetReauth->tsgInitialPacket.packetVersionCaps = packetVersionCaps;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxyCreateTunnelWriteRequest(tsg, &tsgPacket))
|
2015-02-16 23:35:51 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCreateTunnel failure");
|
|
|
|
tsg->state = TSG_STATE_FINAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxyMakeTunnelCallWriteRequest(tsg, &tsg->TunnelContext, TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST))
|
2015-02-17 22:34:42 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyMakeTunnelCall failure");
|
|
|
|
tsg->state = TSG_STATE_FINAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-16 23:35:51 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_INITIAL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-02 16:19:07 +03:00
|
|
|
int tsg_recv_pdu(rdpTsg* tsg, RPC_PDU* pdu)
|
2012-10-30 04:54:49 +04:00
|
|
|
{
|
2015-02-03 02:50:26 +03:00
|
|
|
int status = -1;
|
2013-03-14 20:57:45 +04:00
|
|
|
RpcClientCall* call;
|
2012-10-30 04:54:49 +04:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
2014-12-11 19:25:34 +03:00
|
|
|
|
2015-02-02 01:55:24 +03:00
|
|
|
switch (tsg->state)
|
|
|
|
{
|
|
|
|
case TSG_STATE_INITIAL:
|
|
|
|
{
|
2015-02-18 00:36:01 +03:00
|
|
|
CONTEXT_HANDLE* TunnelContext;
|
|
|
|
TunnelContext = (tsg->reauthSequence) ? &tsg->NewTunnelContext : &tsg->TunnelContext;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
if (!TsProxyCreateTunnelReadResponse(tsg, pdu, TunnelContext, &tsg->TunnelId))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCreateTunnelReadResponse failure");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-15 07:34:45 +04:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_CONNECTED);
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
if (!TsProxyAuthorizeTunnelWriteRequest(tsg, TunnelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyAuthorizeTunnel failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = 1;
|
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_CONNECTED:
|
2015-02-02 01:55:24 +03:00
|
|
|
{
|
2015-02-18 00:36:01 +03:00
|
|
|
CONTEXT_HANDLE* TunnelContext;
|
|
|
|
TunnelContext = (tsg->reauthSequence) ? &tsg->NewTunnelContext : &tsg->TunnelContext;
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
if (!TsProxyAuthorizeTunnelReadResponse(tsg, pdu))
|
2015-02-17 22:34:42 +03:00
|
|
|
{
|
2015-02-18 00:36:01 +03:00
|
|
|
WLog_ERR(TAG, "TsProxyAuthorizeTunnelReadResponse failure");
|
2015-02-17 22:34:42 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2013-03-13 23:43:44 +04:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_AUTHORIZED);
|
2013-03-13 23:43:44 +04:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
if (!tsg->reauthSequence)
|
|
|
|
{
|
|
|
|
if (!TsProxyMakeTunnelCallWriteRequest(tsg, TunnelContext, TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyMakeTunnelCall failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
if (!TsProxyCreateChannelWriteRequest(tsg, TunnelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCreateChannel failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = 1;
|
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
break;
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2015-02-02 16:19:07 +03:00
|
|
|
case TSG_STATE_AUTHORIZED:
|
2015-02-02 01:55:24 +03:00
|
|
|
call = rpc_client_call_find_by_id(rpc, pdu->CallId);
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
if (!call)
|
|
|
|
return -1;
|
|
|
|
|
2015-02-02 01:55:24 +03:00
|
|
|
if (call->OpNum == TsProxyMakeTunnelCallOpnum)
|
|
|
|
{
|
|
|
|
if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyMakeTunnelCallReadResponse failure");
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-03 02:50:26 +03:00
|
|
|
|
|
|
|
status = 1;
|
2015-02-02 01:55:24 +03:00
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
else if (call->OpNum == TsProxyCreateChannelOpnum)
|
2015-02-02 01:55:24 +03:00
|
|
|
{
|
2015-02-18 00:36:01 +03:00
|
|
|
CONTEXT_HANDLE ChannelContext;
|
|
|
|
|
|
|
|
if (!TsProxyCreateChannelReadResponse(tsg, pdu, &ChannelContext, &tsg->ChannelId))
|
2015-02-02 16:19:07 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCreateChannelReadResponse failure");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-18 21:59:53 +04:00
|
|
|
|
2015-02-18 00:36:01 +03:00
|
|
|
if (!tsg->reauthSequence)
|
|
|
|
CopyMemory(&tsg->ChannelContext, &ChannelContext, sizeof(CONTEXT_HANDLE));
|
|
|
|
else
|
|
|
|
CopyMemory(&tsg->NewChannelContext, &ChannelContext, sizeof(CONTEXT_HANDLE));
|
|
|
|
|
2015-02-03 02:50:26 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CREATED);
|
2013-03-14 20:57:45 +04:00
|
|
|
|
2015-02-17 22:34:42 +03:00
|
|
|
if (!tsg->reauthSequence)
|
2015-02-02 16:19:07 +03:00
|
|
|
{
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxySetupReceivePipeWriteRequest(tsg, &tsg->ChannelContext))
|
2015-02-17 22:34:42 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxySetupReceivePipe failure");
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
2015-02-18 00:36:01 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!TsProxyCloseChannelWriteRequest(tsg, &tsg->NewChannelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCloseChannelWriteRequest failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TsProxyCloseTunnelWriteRequest(tsg, &tsg->NewTunnelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCloseTunnelWriteRequest failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-03-14 20:57:45 +04:00
|
|
|
|
2015-02-03 02:50:26 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_PIPE_CREATED);
|
2015-02-17 22:34:42 +03:00
|
|
|
tsg->reauthSequence = FALSE;
|
2015-02-03 02:50:26 +03:00
|
|
|
status = 1;
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
|
|
|
else
|
2015-02-02 01:55:24 +03:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "TSG_STATE_AUTHORIZED unexpected OpNum: %"PRIu32"\n", call->OpNum);
|
2015-02-02 01:55:24 +03:00
|
|
|
}
|
2013-03-14 20:57:45 +04:00
|
|
|
|
2015-02-02 16:19:07 +03:00
|
|
|
break;
|
2015-02-02 01:55:24 +03:00
|
|
|
|
2015-02-02 16:19:07 +03:00
|
|
|
case TSG_STATE_CHANNEL_CREATED:
|
2015-02-02 01:55:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_PIPE_CREATED:
|
2015-02-16 02:22:49 +03:00
|
|
|
call = rpc_client_call_find_by_id(rpc, pdu->CallId);
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (call->OpNum == TsProxyMakeTunnelCallOpnum)
|
|
|
|
{
|
|
|
|
if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyMakeTunnelCallReadResponse failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-16 23:35:51 +03:00
|
|
|
if (tsg->ReauthTunnelContext)
|
|
|
|
tsg_proxy_reauth(tsg);
|
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
status = 1;
|
|
|
|
}
|
2015-02-18 00:36:01 +03:00
|
|
|
else if (call->OpNum == TsProxyCloseChannelOpnum)
|
|
|
|
{
|
|
|
|
CONTEXT_HANDLE ChannelContext;
|
|
|
|
|
|
|
|
if (!TsProxyCloseChannelReadResponse(tsg, pdu, &ChannelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCloseChannelReadResponse failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
else if (call->OpNum == TsProxyCloseTunnelOpnum)
|
|
|
|
{
|
|
|
|
CONTEXT_HANDLE TunnelContext;
|
|
|
|
|
|
|
|
if (!TsProxyCloseTunnelReadResponse(tsg, pdu, &TunnelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCloseTunnelReadResponse failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
|
2015-02-02 01:55:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_TUNNEL_CLOSE_PENDING:
|
2015-02-02 16:19:07 +03:00
|
|
|
{
|
2015-02-18 00:15:57 +03:00
|
|
|
CONTEXT_HANDLE ChannelContext;
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxyCloseChannelReadResponse(tsg, pdu, &ChannelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCloseChannelReadResponse failure");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CLOSE_PENDING);
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxyCloseChannelWriteRequest(tsg, NULL))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCloseChannelWriteRequest failure");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2017-02-20 16:12:39 +03:00
|
|
|
if (!TsProxyMakeTunnelCallWriteRequest(tsg, &tsg->TunnelContext,
|
|
|
|
TSG_TUNNEL_CANCEL_ASYNC_MSG_REQUEST))
|
2015-02-18 00:15:57 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyMakeTunnelCall failure");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
status = 1;
|
|
|
|
}
|
2015-02-02 01:55:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_CHANNEL_CLOSE_PENDING:
|
2015-02-02 16:19:07 +03:00
|
|
|
{
|
2015-02-18 00:15:57 +03:00
|
|
|
CONTEXT_HANDLE TunnelContext;
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxyCloseTunnelReadResponse(tsg, pdu, &TunnelContext))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "TsProxyCloseTunnelReadResponse failure");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_FINAL);
|
|
|
|
status = 1;
|
|
|
|
}
|
2015-02-02 01:55:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_FINAL:
|
|
|
|
break;
|
2013-03-13 23:43:44 +04:00
|
|
|
}
|
|
|
|
|
2015-02-03 02:50:26 +03:00
|
|
|
return status;
|
2015-02-02 01:55:24 +03:00
|
|
|
}
|
2012-11-15 07:34:45 +04:00
|
|
|
|
2015-02-15 18:06:17 +03:00
|
|
|
int tsg_check_event_handles(rdpTsg* tsg)
|
2015-02-02 19:50:56 +03:00
|
|
|
{
|
|
|
|
int status;
|
2015-02-04 01:17:17 +03:00
|
|
|
status = rpc_client_in_channel_recv(tsg->rpc);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
status = rpc_client_out_channel_recv(tsg->rpc);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
2015-02-02 19:50:56 +03:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-04-21 13:24:50 +03:00
|
|
|
DWORD tsg_get_event_handles(rdpTsg* tsg, HANDLE* events, DWORD count)
|
2015-02-15 18:06:17 +03:00
|
|
|
{
|
2015-02-18 21:50:03 +03:00
|
|
|
UINT32 nCount = 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
|
|
|
RpcVirtualConnection* connection = rpc->VirtualConnection;
|
|
|
|
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
events[nCount] = rpc->client->PipeEvent;
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
|
|
|
|
if (connection->DefaultInChannel && connection->DefaultInChannel->tls)
|
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
BIO_get_event(connection->DefaultInChannel->tls->bio, &events[nCount]);
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (connection->NonDefaultInChannel && connection->NonDefaultInChannel->tls)
|
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
BIO_get_event(connection->NonDefaultInChannel->tls->bio, &events[nCount]);
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (connection->DefaultOutChannel && connection->DefaultOutChannel->tls)
|
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
BIO_get_event(connection->DefaultOutChannel->tls->bio, &events[nCount]);
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (connection->NonDefaultOutChannel && connection->NonDefaultOutChannel->tls)
|
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
BIO_get_event(connection->NonDefaultOutChannel->tls->bio, &events[nCount]);
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nCount;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL tsg_set_hostname(rdpTsg* tsg, const char* hostname)
|
2015-02-12 22:40:26 +03:00
|
|
|
{
|
|
|
|
free(tsg->Hostname);
|
|
|
|
tsg->Hostname = NULL;
|
|
|
|
ConvertToUnicode(CP_UTF8, 0, hostname, -1, &tsg->Hostname, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL tsg_set_machine_name(rdpTsg* tsg, const char* machineName)
|
2015-02-12 22:40:26 +03:00
|
|
|
{
|
|
|
|
free(tsg->MachineName);
|
|
|
|
tsg->MachineName = NULL;
|
|
|
|
ConvertToUnicode(CP_UTF8, 0, machineName, -1, &tsg->MachineName, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:57:02 +03:00
|
|
|
BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, int timeout)
|
2015-02-02 01:55:24 +03:00
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
DWORD nCount;
|
|
|
|
HANDLE events[64];
|
2015-02-02 01:55:24 +03:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
|
|
|
rdpSettings* settings = rpc->settings;
|
2015-02-11 19:57:02 +03:00
|
|
|
rdpTransport* transport = rpc->transport;
|
2015-02-11 22:27:29 +03:00
|
|
|
tsg->Port = port;
|
|
|
|
tsg->transport = transport;
|
2015-02-11 19:57:02 +03:00
|
|
|
|
|
|
|
if (!settings->GatewayPort)
|
|
|
|
settings->GatewayPort = 443;
|
|
|
|
|
2015-02-12 22:40:26 +03:00
|
|
|
tsg_set_hostname(tsg, hostname);
|
|
|
|
tsg_set_machine_name(tsg, settings->ComputerName);
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2015-02-12 22:40:26 +03:00
|
|
|
if (!rpc_connect(rpc, timeout))
|
2015-02-02 16:19:07 +03:00
|
|
|
{
|
2015-02-04 19:18:27 +03:00
|
|
|
WLog_ERR(TAG, "rpc_connect error!");
|
2015-02-03 01:16:32 +03:00
|
|
|
return FALSE;
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
|
|
|
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount = tsg_get_event_handles(tsg, events, 64);
|
|
|
|
|
|
|
|
if (nCount == 0)
|
|
|
|
return FALSE;
|
2015-02-02 01:55:24 +03:00
|
|
|
|
|
|
|
while (tsg->state != TSG_STATE_PIPE_CREATED)
|
|
|
|
{
|
2015-03-19 18:44:47 +03:00
|
|
|
WaitForMultipleObjects(nCount, events, FALSE, 250);
|
2015-02-04 01:17:17 +03:00
|
|
|
|
2015-02-15 18:06:17 +03:00
|
|
|
if (tsg_check_event_handles(tsg) < 0)
|
2015-02-02 19:50:56 +03:00
|
|
|
{
|
2015-02-04 01:17:17 +03:00
|
|
|
WLog_ERR(TAG, "tsg_check failure");
|
2015-02-11 22:27:29 +03:00
|
|
|
transport->layer = TRANSPORT_LAYER_CLOSED;
|
2015-02-04 01:17:17 +03:00
|
|
|
return FALSE;
|
2015-02-02 19:50:56 +03:00
|
|
|
}
|
2015-02-02 01:55:24 +03:00
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2015-02-02 19:50:56 +03:00
|
|
|
WLog_INFO(TAG, "TS Gateway Connection Success");
|
2015-01-28 21:46:17 +03:00
|
|
|
tsg->bio = BIO_new(BIO_s_tsg());
|
2015-02-11 22:27:29 +03:00
|
|
|
|
|
|
|
if (!tsg->bio)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-11-21 19:28:54 +03:00
|
|
|
BIO_set_data(tsg->bio, (void*) tsg);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-26 10:45:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-13 05:02:56 +04:00
|
|
|
BOOL tsg_disconnect(rdpTsg* tsg)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Gateway Shutdown Phase
|
|
|
|
*
|
|
|
|
* Client Server
|
|
|
|
* | |
|
|
|
|
* |-------------TsProxyCloseChannel Request---------->|
|
|
|
|
* | |
|
|
|
|
* |<-------TsProxySetupReceivePipe Final Response-----|
|
|
|
|
* |<-----------TsProxyCloseChannel Response-----------|
|
|
|
|
* | |
|
|
|
|
* |----TsProxyMakeTunnelCall Request (cancel async)-->|
|
|
|
|
* | |
|
|
|
|
* |<---TsProxyMakeTunnelCall Response (call async)----|
|
|
|
|
* |<---TsProxyMakeTunnelCall Response (cancel async)--|
|
|
|
|
* | |
|
|
|
|
* |--------------TsProxyCloseTunnel Request---------->|
|
|
|
|
* |<-------------TsProxyCloseTunnel Response----------|
|
|
|
|
* | |
|
|
|
|
*/
|
2015-01-13 21:50:46 +03:00
|
|
|
if (!tsg)
|
2013-10-11 13:07:33 +04:00
|
|
|
return FALSE;
|
2013-07-04 22:42:40 +04:00
|
|
|
|
2013-10-11 13:07:33 +04:00
|
|
|
if (tsg->state != TSG_STATE_TUNNEL_CLOSE_PENDING)
|
|
|
|
{
|
2015-02-18 00:15:57 +03:00
|
|
|
if (!TsProxyCloseChannelWriteRequest(tsg, &tsg->ChannelContext))
|
2013-10-11 13:07:33 +04:00
|
|
|
return FALSE;
|
2012-12-13 21:40:46 +04:00
|
|
|
|
2015-02-02 16:19:07 +03:00
|
|
|
tsg->state = TSG_STATE_CHANNEL_CLOSE_PENDING;
|
|
|
|
}
|
2012-12-13 21:40:46 +04:00
|
|
|
|
2012-12-13 05:02:56 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-26 00:55:39 +03:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
*
|
|
|
|
* @param[in] tsg
|
|
|
|
* @param[in] data
|
|
|
|
* @param[in] length
|
|
|
|
* @return < 0 on error; 0 if not enough data is available (non blocking mode); > 0 bytes to read
|
|
|
|
*/
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
|
2012-04-24 00:33:18 +04:00
|
|
|
{
|
2013-10-11 13:07:33 +04:00
|
|
|
rdpRpc* rpc;
|
2015-02-01 21:09:28 +03:00
|
|
|
int status = 0;
|
2013-07-04 22:42:40 +04:00
|
|
|
|
2015-01-13 21:50:46 +03:00
|
|
|
if (!tsg)
|
2013-10-11 13:07:33 +04:00
|
|
|
return -1;
|
2013-07-04 22:42:40 +04:00
|
|
|
|
2013-10-11 13:07:33 +04:00
|
|
|
rpc = tsg->rpc;
|
2012-04-24 00:33:18 +04:00
|
|
|
|
2013-12-21 03:22:29 +04:00
|
|
|
if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
|
|
|
|
{
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_ERR(TAG, "tsg_read error: connection lost");
|
2013-12-21 03:22:29 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-25 23:25:26 +03:00
|
|
|
do
|
2014-05-21 19:32:14 +04:00
|
|
|
{
|
2015-02-01 21:09:28 +03:00
|
|
|
status = rpc_client_receive_pipe_read(rpc, data, (size_t) length);
|
2014-11-25 23:25:26 +03:00
|
|
|
|
2015-02-01 21:09:28 +03:00
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
2014-11-25 23:25:26 +03:00
|
|
|
|
2015-02-02 19:50:56 +03:00
|
|
|
if (!status && !rpc->transport->blocking)
|
2014-05-21 19:32:14 +04:00
|
|
|
return 0;
|
2012-11-15 04:51:45 +04:00
|
|
|
|
2014-11-25 23:25:26 +03:00
|
|
|
if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
|
|
|
|
{
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_ERR(TAG, "tsg_read error: connection lost");
|
2014-11-25 23:25:26 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-01 21:09:28 +03:00
|
|
|
if (status > 0)
|
|
|
|
break;
|
2014-05-21 19:32:14 +04:00
|
|
|
|
2015-02-02 19:50:56 +03:00
|
|
|
if (rpc->transport->blocking)
|
|
|
|
{
|
|
|
|
while (WaitForSingleObject(rpc->client->PipeEvent, 0) != WAIT_OBJECT_0)
|
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
if (tsg_check_event_handles(tsg) < 0)
|
2015-02-02 19:50:56 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
WaitForSingleObject(rpc->client->PipeEvent, 100);
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 22:49:18 +04:00
|
|
|
}
|
2015-02-02 19:50:56 +03:00
|
|
|
while (rpc->transport->blocking);
|
2014-05-21 19:32:14 +04:00
|
|
|
|
2015-02-01 21:09:28 +03:00
|
|
|
return status;
|
2012-04-24 00:33:18 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int tsg_write(rdpTsg* tsg, BYTE* data, UINT32 length)
|
2012-03-26 10:45:01 +04:00
|
|
|
{
|
2014-05-21 19:32:14 +04:00
|
|
|
int status;
|
|
|
|
|
2013-12-21 03:24:29 +04:00
|
|
|
if (tsg->rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
|
|
|
|
{
|
2015-01-13 21:50:46 +03:00
|
|
|
WLog_ERR(TAG, "error, connection lost");
|
2013-12-21 03:24:29 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
status = TsProxySendToServer((handle_t) tsg, data, 1, &length);
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
return length;
|
2012-03-26 10:45:01 +04:00
|
|
|
}
|
|
|
|
|
2012-04-24 00:33:18 +04:00
|
|
|
rdpTsg* tsg_new(rdpTransport* transport)
|
2012-03-26 10:45:01 +04:00
|
|
|
{
|
|
|
|
rdpTsg* tsg;
|
2014-05-21 19:32:14 +04:00
|
|
|
tsg = (rdpTsg*) calloc(1, sizeof(rdpTsg));
|
2014-05-30 22:53:10 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!tsg)
|
|
|
|
return NULL;
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
tsg->transport = transport;
|
|
|
|
tsg->settings = transport->settings;
|
|
|
|
tsg->rpc = rpc_new(tsg->transport);
|
2014-05-30 22:53:10 +04:00
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!tsg->rpc)
|
|
|
|
goto out_free;
|
2014-05-30 22:53:10 +04:00
|
|
|
|
2012-03-26 10:45:01 +04:00
|
|
|
return tsg;
|
2014-05-21 19:32:14 +04:00
|
|
|
out_free:
|
|
|
|
free(tsg);
|
|
|
|
return NULL;
|
2012-03-26 10:45:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void tsg_free(rdpTsg* tsg)
|
|
|
|
{
|
2014-05-30 22:53:10 +04:00
|
|
|
if (tsg)
|
2012-04-24 00:33:18 +04:00
|
|
|
{
|
2015-02-01 21:09:28 +03:00
|
|
|
if (tsg->rpc)
|
|
|
|
{
|
|
|
|
rpc_free(tsg->rpc);
|
|
|
|
tsg->rpc = NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-11 19:25:34 +03:00
|
|
|
free(tsg->Hostname);
|
2012-12-12 09:49:15 +04:00
|
|
|
free(tsg->MachineName);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(tsg);
|
2012-04-24 00:33:18 +04:00
|
|
|
}
|
2012-03-26 10:45:01 +04:00
|
|
|
}
|
2015-01-28 22:54:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
static int transport_bio_tsg_write(BIO* bio, const char* buf, int num)
|
|
|
|
{
|
|
|
|
int status;
|
2016-11-21 19:28:54 +03:00
|
|
|
rdpTsg* tsg = (rdpTsg*) BIO_get_data(bio);
|
2015-01-28 22:54:03 +03:00
|
|
|
BIO_clear_flags(bio, BIO_FLAGS_WRITE);
|
|
|
|
status = tsg_write(tsg, (BYTE*) buf, num);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
2015-03-19 18:44:47 +03:00
|
|
|
return -1;
|
2015-01-28 22:54:03 +03:00
|
|
|
}
|
|
|
|
else if (status == 0)
|
|
|
|
{
|
2015-03-19 18:44:47 +03:00
|
|
|
BIO_set_flags(bio, BIO_FLAGS_WRITE);
|
2015-01-28 22:54:03 +03:00
|
|
|
WSASetLastError(WSAEWOULDBLOCK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BIO_set_flags(bio, BIO_FLAGS_WRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status >= 0 ? status : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int transport_bio_tsg_read(BIO* bio, char* buf, int size)
|
|
|
|
{
|
|
|
|
int status;
|
2016-11-21 19:28:54 +03:00
|
|
|
rdpTsg* tsg = (rdpTsg*) BIO_get_data(bio);
|
2015-01-28 22:54:03 +03:00
|
|
|
BIO_clear_flags(bio, BIO_FLAGS_READ);
|
|
|
|
status = tsg_read(tsg, (BYTE*) buf, size);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
2015-03-19 18:44:47 +03:00
|
|
|
return -1;
|
2015-01-28 22:54:03 +03:00
|
|
|
}
|
|
|
|
else if (status == 0)
|
|
|
|
{
|
2015-03-19 18:44:47 +03:00
|
|
|
BIO_set_flags(bio, BIO_FLAGS_READ);
|
2015-01-28 22:54:03 +03:00
|
|
|
WSASetLastError(WSAEWOULDBLOCK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BIO_set_flags(bio, BIO_FLAGS_READ);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status > 0 ? status : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int transport_bio_tsg_puts(BIO* bio, const char* str)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int transport_bio_tsg_gets(BIO* bio, char* str, int size)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long transport_bio_tsg_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
|
|
|
{
|
2015-02-15 18:06:17 +03:00
|
|
|
int status = 0;
|
2016-11-21 19:28:54 +03:00
|
|
|
rdpTsg* tsg = (rdpTsg*) BIO_get_data(bio);
|
2015-02-15 18:06:17 +03:00
|
|
|
RpcVirtualConnection* connection = tsg->rpc->VirtualConnection;
|
|
|
|
RpcInChannel* inChannel = connection->DefaultInChannel;
|
|
|
|
RpcOutChannel* outChannel = connection->DefaultOutChannel;
|
|
|
|
|
2015-01-28 22:54:03 +03:00
|
|
|
if (cmd == BIO_CTRL_FLUSH)
|
|
|
|
{
|
2015-03-23 19:35:11 +03:00
|
|
|
(void)BIO_flush(inChannel->tls->bio);
|
|
|
|
(void)BIO_flush(outChannel->tls->bio);
|
2015-02-15 18:06:17 +03:00
|
|
|
status = 1;
|
2015-01-28 22:54:03 +03:00
|
|
|
}
|
2015-02-15 18:06:17 +03:00
|
|
|
else if (cmd == BIO_C_GET_EVENT)
|
|
|
|
{
|
|
|
|
if (arg2)
|
|
|
|
{
|
|
|
|
*((ULONG_PTR*) arg2) = (ULONG_PTR) tsg->rpc->client->PipeEvent;
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd == BIO_C_SET_NONBLOCK)
|
|
|
|
{
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
else if (cmd == BIO_C_READ_BLOCKED)
|
|
|
|
{
|
|
|
|
BIO* bio = outChannel->bio;
|
|
|
|
status = BIO_read_blocked(bio);
|
|
|
|
}
|
|
|
|
else if (cmd == BIO_C_WRITE_BLOCKED)
|
|
|
|
{
|
|
|
|
BIO* bio = inChannel->bio;
|
|
|
|
status = BIO_write_blocked(bio);
|
|
|
|
}
|
|
|
|
else if (cmd == BIO_C_WAIT_READ)
|
|
|
|
{
|
|
|
|
int timeout = (int) arg1;
|
|
|
|
BIO* bio = outChannel->bio;
|
|
|
|
|
|
|
|
if (BIO_read_blocked(bio))
|
|
|
|
return BIO_wait_read(bio, timeout);
|
|
|
|
else if (BIO_write_blocked(bio))
|
|
|
|
return BIO_wait_write(bio, timeout);
|
|
|
|
else
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
else if (cmd == BIO_C_WAIT_WRITE)
|
|
|
|
{
|
|
|
|
int timeout = (int) arg1;
|
|
|
|
BIO* bio = inChannel->bio;
|
2015-01-28 22:54:03 +03:00
|
|
|
|
2015-02-15 18:06:17 +03:00
|
|
|
if (BIO_write_blocked(bio))
|
|
|
|
status = BIO_wait_write(bio, timeout);
|
|
|
|
else if (BIO_read_blocked(bio))
|
|
|
|
status = BIO_wait_read(bio, timeout);
|
|
|
|
else
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2015-01-28 22:54:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int transport_bio_tsg_new(BIO* bio)
|
|
|
|
{
|
2016-11-21 19:28:54 +03:00
|
|
|
BIO_set_init(bio, 1);
|
|
|
|
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
2015-01-28 22:54:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int transport_bio_tsg_free(BIO* bio)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
BIO_METHOD* BIO_s_tsg(void)
|
|
|
|
{
|
2016-11-21 19:28:54 +03:00
|
|
|
static BIO_METHOD* bio_methods = NULL;
|
|
|
|
|
|
|
|
if (bio_methods == NULL)
|
|
|
|
{
|
|
|
|
if (!(bio_methods = BIO_meth_new(BIO_TYPE_TSG, "TSGateway")))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BIO_meth_set_write(bio_methods, transport_bio_tsg_write);
|
|
|
|
BIO_meth_set_read(bio_methods, transport_bio_tsg_read);
|
|
|
|
BIO_meth_set_puts(bio_methods, transport_bio_tsg_puts);
|
|
|
|
BIO_meth_set_gets(bio_methods, transport_bio_tsg_gets);
|
|
|
|
BIO_meth_set_ctrl(bio_methods, transport_bio_tsg_ctrl);
|
|
|
|
BIO_meth_set_create(bio_methods, transport_bio_tsg_new);
|
|
|
|
BIO_meth_set_destroy(bio_methods, transport_bio_tsg_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bio_methods;
|
2015-01-28 22:54:03 +03:00
|
|
|
}
|