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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-03-26 20:20:38 +04:00
|
|
|
|
2023-10-16 13:59:19 +03:00
|
|
|
#include "../settings.h"
|
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-10-30 04:54:49 +04:00
|
|
|
#include <winpr/crt.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"
|
2024-03-06 17:08:25 +03:00
|
|
|
#include "../utils.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
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
#define TSG_CAPABILITY_TYPE_NAP 0x00000001
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
#define TSG_PACKET_TYPE_HEADER 0x00004844
|
|
|
|
#define TSG_PACKET_TYPE_VERSIONCAPS 0x00005643
|
|
|
|
#define TSG_PACKET_TYPE_QUARCONFIGREQUEST 0x00005143
|
|
|
|
#define TSG_PACKET_TYPE_QUARREQUEST 0x00005152
|
|
|
|
#define TSG_PACKET_TYPE_RESPONSE 0x00005052
|
|
|
|
#define TSG_PACKET_TYPE_QUARENC_RESPONSE 0x00004552
|
|
|
|
#define TSG_PACKET_TYPE_CAPS_RESPONSE 0x00004350
|
|
|
|
#define TSG_PACKET_TYPE_MSGREQUEST_PACKET 0x00004752
|
|
|
|
#define TSG_PACKET_TYPE_MESSAGE_PACKET 0x00004750
|
|
|
|
#define TSG_PACKET_TYPE_AUTH 0x00004054
|
|
|
|
#define TSG_PACKET_TYPE_REAUTH 0x00005250
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
typedef WCHAR* RESOURCENAME;
|
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
RESOURCENAME* resourceName;
|
|
|
|
UINT32 numResourceNames;
|
|
|
|
RESOURCENAME* alternateResourceNames;
|
|
|
|
UINT16 numAlternateResourceNames;
|
|
|
|
UINT32 Port;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSENDPOINTINFO;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT16 ComponentId;
|
|
|
|
UINT16 PacketId;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_HEADER;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 capabilities;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_CAPABILITY_NAP;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2021-01-27 11:44:19 +03:00
|
|
|
typedef union
|
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
TSG_CAPABILITY_NAP tsgCapNap;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_CAPABILITIES_UNION;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 capabilityType;
|
|
|
|
TSG_CAPABILITIES_UNION tsgPacket;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_CAPABILITIES;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
TSG_PACKET_HEADER tsgHeader;
|
2023-10-25 11:38:48 +03:00
|
|
|
TSG_PACKET_CAPABILITIES tsgCaps;
|
2018-09-28 09:43:43 +03:00
|
|
|
UINT32 numCapabilities;
|
|
|
|
UINT16 majorVersion;
|
|
|
|
UINT16 minorVersion;
|
|
|
|
UINT16 quarantineCapabilities;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_VERSIONCAPS;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 flags;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_QUARCONFIGREQUEST;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 flags;
|
|
|
|
WCHAR* machineName;
|
|
|
|
UINT32 nameLength;
|
|
|
|
BYTE* data;
|
|
|
|
UINT32 dataLen;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_QUARREQUEST;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
BOOL enableAllRedirections;
|
|
|
|
BOOL disableAllRedirections;
|
|
|
|
BOOL driveRedirectionDisabled;
|
|
|
|
BOOL printerRedirectionDisabled;
|
|
|
|
BOOL portRedirectionDisabled;
|
|
|
|
BOOL reserved;
|
|
|
|
BOOL clipboardRedirectionDisabled;
|
|
|
|
BOOL pnpRedirectionDisabled;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_REDIRECTION_FLAGS;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 flags;
|
|
|
|
UINT32 reserved;
|
|
|
|
BYTE* responseData;
|
|
|
|
UINT32 responseDataLen;
|
|
|
|
TSG_REDIRECTION_FLAGS redirectionFlags;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_RESPONSE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 flags;
|
|
|
|
UINT32 certChainLen;
|
|
|
|
WCHAR* certChainData;
|
|
|
|
GUID nonce;
|
2023-10-25 11:38:48 +03:00
|
|
|
TSG_PACKET_VERSIONCAPS versionCaps;
|
|
|
|
} TSG_PACKET_QUARENC_RESPONSE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
INT32 isDisplayMandatory;
|
|
|
|
INT32 isConsentMandatory;
|
|
|
|
UINT32 msgBytes;
|
|
|
|
WCHAR* msgBuffer;
|
2018-12-11 17:24:24 +03:00
|
|
|
} TSG_PACKET_STRING_MESSAGE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT64 tunnelContext;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_REAUTH_MESSAGE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 msgID;
|
|
|
|
UINT32 msgType;
|
|
|
|
INT32 isMsgPresent;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_MSG_RESPONSE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
TSG_PACKET_QUARENC_RESPONSE pktQuarEncResponse;
|
|
|
|
TSG_PACKET_MSG_RESPONSE pktConsentMessage;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_CAPS_RESPONSE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 maxMessagesPerBatch;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_MSG_REQUEST;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
TSG_PACKET_VERSIONCAPS tsgVersionCaps;
|
|
|
|
UINT32 cookieLen;
|
|
|
|
BYTE* cookie;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_AUTH;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2021-01-27 11:44:19 +03:00
|
|
|
typedef union
|
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
TSG_PACKET_VERSIONCAPS packetVersionCaps;
|
|
|
|
TSG_PACKET_AUTH packetAuth;
|
|
|
|
} TSG_INITIAL_PACKET_TYPE_UNION;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT64 tunnelContext;
|
|
|
|
UINT32 packetId;
|
|
|
|
TSG_INITIAL_PACKET_TYPE_UNION tsgInitialPacket;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET_REAUTH;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2021-01-27 11:44:19 +03:00
|
|
|
typedef union
|
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
TSG_PACKET_HEADER packetHeader;
|
|
|
|
TSG_PACKET_VERSIONCAPS packetVersionCaps;
|
|
|
|
TSG_PACKET_QUARCONFIGREQUEST packetQuarConfigRequest;
|
|
|
|
TSG_PACKET_QUARREQUEST packetQuarRequest;
|
|
|
|
TSG_PACKET_RESPONSE packetResponse;
|
|
|
|
TSG_PACKET_QUARENC_RESPONSE packetQuarEncResponse;
|
|
|
|
TSG_PACKET_CAPS_RESPONSE packetCapsResponse;
|
|
|
|
TSG_PACKET_MSG_REQUEST packetMsgRequest;
|
|
|
|
TSG_PACKET_MSG_RESPONSE packetMsgResponse;
|
|
|
|
TSG_PACKET_AUTH packetAuth;
|
|
|
|
TSG_PACKET_REAUTH packetReauth;
|
2018-09-28 09:43:43 +03:00
|
|
|
} TSG_PACKET_TYPE_UNION;
|
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2018-09-28 09:43:43 +03:00
|
|
|
{
|
|
|
|
UINT32 packetId;
|
|
|
|
TSG_PACKET_TYPE_UNION tsgPacket;
|
2023-10-25 11:38:48 +03:00
|
|
|
} TSG_PACKET;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
struct rdp_tsg
|
|
|
|
{
|
|
|
|
BIO* bio;
|
|
|
|
rdpRpc* rpc;
|
|
|
|
UINT16 Port;
|
|
|
|
LPWSTR Hostname;
|
|
|
|
LPWSTR MachineName;
|
|
|
|
TSG_STATE state;
|
|
|
|
UINT32 TunnelId;
|
|
|
|
UINT32 ChannelId;
|
|
|
|
BOOL reauthSequence;
|
|
|
|
rdpTransport* transport;
|
|
|
|
UINT64 ReauthTunnelContext;
|
|
|
|
CONTEXT_HANDLE TunnelContext;
|
|
|
|
CONTEXT_HANDLE ChannelContext;
|
|
|
|
CONTEXT_HANDLE NewTunnelContext;
|
|
|
|
CONTEXT_HANDLE NewChannelContext;
|
2023-10-25 14:48:36 +03:00
|
|
|
wLog* log;
|
2018-09-28 09:43:43 +03:00
|
|
|
};
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_stream_align(wLog* log, wStream* s, size_t align);
|
2023-10-25 11:38:48 +03:00
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
static const char* tsg_packet_id_to_string(UINT32 packetId)
|
|
|
|
{
|
|
|
|
switch (packetId)
|
|
|
|
{
|
|
|
|
case TSG_PACKET_TYPE_HEADER:
|
|
|
|
return "TSG_PACKET_TYPE_HEADER";
|
|
|
|
case TSG_PACKET_TYPE_VERSIONCAPS:
|
|
|
|
return "TSG_PACKET_TYPE_VERSIONCAPS";
|
|
|
|
case TSG_PACKET_TYPE_QUARCONFIGREQUEST:
|
|
|
|
return "TSG_PACKET_TYPE_QUARCONFIGREQUEST";
|
|
|
|
case TSG_PACKET_TYPE_QUARREQUEST:
|
|
|
|
return "TSG_PACKET_TYPE_QUARREQUEST";
|
|
|
|
case TSG_PACKET_TYPE_RESPONSE:
|
|
|
|
return "TSG_PACKET_TYPE_RESPONSE";
|
|
|
|
case TSG_PACKET_TYPE_QUARENC_RESPONSE:
|
|
|
|
return "TSG_PACKET_TYPE_QUARENC_RESPONSE";
|
|
|
|
case TSG_CAPABILITY_TYPE_NAP:
|
|
|
|
return "TSG_CAPABILITY_TYPE_NAP";
|
|
|
|
case TSG_PACKET_TYPE_CAPS_RESPONSE:
|
|
|
|
return "TSG_PACKET_TYPE_CAPS_RESPONSE";
|
|
|
|
case TSG_PACKET_TYPE_MSGREQUEST_PACKET:
|
|
|
|
return "TSG_PACKET_TYPE_MSGREQUEST_PACKET";
|
|
|
|
case TSG_PACKET_TYPE_MESSAGE_PACKET:
|
|
|
|
return "TSG_PACKET_TYPE_MESSAGE_PACKET";
|
|
|
|
case TSG_PACKET_TYPE_AUTH:
|
|
|
|
return "TSG_PACKET_TYPE_AUTH";
|
|
|
|
case TSG_PACKET_TYPE_REAUTH:
|
|
|
|
return "TSG_PACKET_TYPE_REAUTH";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
static const char* tsg_component_id_to_string(UINT16 ComponentId, char* buffer, size_t bytelen)
|
|
|
|
{
|
|
|
|
const char* str = NULL;
|
|
|
|
|
|
|
|
#define ENTRY(x) \
|
|
|
|
case x: \
|
|
|
|
str = #x; \
|
|
|
|
break
|
|
|
|
switch (ComponentId)
|
|
|
|
{
|
|
|
|
ENTRY(TS_GATEWAY_TRANSPORT);
|
|
|
|
default:
|
|
|
|
str = "TS_UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#undef ENTRY
|
|
|
|
|
|
|
|
_snprintf(buffer, bytelen, "%s [0x%04" PRIx16 "]", str, ComponentId);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
static const char* tsg_state_to_string(TSG_STATE state)
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case TSG_STATE_INITIAL:
|
|
|
|
return "TSG_STATE_INITIAL";
|
|
|
|
case TSG_STATE_CONNECTED:
|
|
|
|
return "TSG_STATE_CONNECTED";
|
|
|
|
case TSG_STATE_AUTHORIZED:
|
|
|
|
return "TSG_STATE_AUTHORIZED";
|
|
|
|
case TSG_STATE_CHANNEL_CREATED:
|
|
|
|
return "TSG_STATE_CHANNEL_CREATED";
|
|
|
|
case TSG_STATE_PIPE_CREATED:
|
|
|
|
return "TSG_STATE_PIPE_CREATED";
|
|
|
|
case TSG_STATE_TUNNEL_CLOSE_PENDING:
|
|
|
|
return "TSG_STATE_TUNNEL_CLOSE_PENDING";
|
|
|
|
case TSG_STATE_CHANNEL_CLOSE_PENDING:
|
|
|
|
return "TSG_STATE_CHANNEL_CLOSE_PENDING";
|
|
|
|
case TSG_STATE_FINAL:
|
|
|
|
return "TSG_STATE_FINAL";
|
|
|
|
default:
|
|
|
|
return "TSG_STATE_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL TsProxyReadTunnelContext(wLog* log, wStream* s, CONTEXT_HANDLE* tunnelContext)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-11-20 18:20:08 +03:00
|
|
|
WINPR_ASSERT(tunnelContext);
|
2023-10-25 11:38:48 +03:00
|
|
|
Stream_Read_UINT32(s, tunnelContext->ContextType); /* ContextType (4 bytes) */
|
2023-11-20 18:20:08 +03:00
|
|
|
Stream_Read(s, &tunnelContext->ContextUuid,
|
|
|
|
sizeof(tunnelContext->ContextUuid)); /* ContextUuid (16 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL TsProxyWriteTunnelContext(wLog* log, wStream* s, const CONTEXT_HANDLE* tunnelContext)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 20))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, tunnelContext->ContextType); /* ContextType (4 bytes) */
|
2023-11-20 18:20:08 +03:00
|
|
|
Stream_Write(s, &tunnelContext->ContextUuid,
|
|
|
|
sizeof(tunnelContext->ContextUuid)); /* ContextUuid (16 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_pointer_write(wLog* log, wStream* s, UINT32* index, DWORD length)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(index);
|
|
|
|
const UINT32 ndrPtr = 0x20000 + (*index) * 4;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (length > 0)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, ndrPtr); /* mszGroupsNdrPtr (4 bytes) */
|
|
|
|
(*index) = (*index) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Stream_Write_UINT32(s, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_pointer_read(wLog* log, wStream* s, UINT32* index, UINT32* ptrval,
|
|
|
|
BOOL required)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(index);
|
|
|
|
const UINT32 ndrPtr = 0x20000 + (*index) * 4;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
DWORD val = 0;
|
|
|
|
Stream_Read_UINT32(s, val);
|
|
|
|
if (ptrval)
|
|
|
|
*ptrval = val;
|
|
|
|
|
|
|
|
if (val != 0)
|
|
|
|
{
|
|
|
|
if (val != ndrPtr)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_WARN, "Read NDR pointer 0x%04" PRIx32 " but expected 0x%04" PRIx32,
|
|
|
|
val, ndrPtr);
|
2023-10-25 11:38:48 +03:00
|
|
|
if ((val & 0xFFFF0000) != (ndrPtr & 0xFFFF0000))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
(*index)++;
|
|
|
|
}
|
|
|
|
else if (required)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "NDR pointer == 0, but the field is required");
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_write_string(wLog* log, wStream* s, const WCHAR* str, UINT32 length)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 12 + length))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, length); /* MaxCount (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0); /* Offset (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, length); /* ActualCount (4 bytes) */
|
|
|
|
Stream_Write_UTF16_String(s, str, length); /* Array */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_string(wLog* log, wStream* s, WCHAR** str, UINT32 lengthInBytes)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
UINT32 MaxCount = 0;
|
|
|
|
UINT32 Offset = 0;
|
|
|
|
UINT32 ActualCount = 0;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, MaxCount); /* MaxCount (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, Offset); /* Offset (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, ActualCount); /* ActualCount (4 bytes) */
|
|
|
|
if (ActualCount > MaxCount)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR,
|
|
|
|
"failed to read string, ActualCount (%" PRIu32 ") > MaxCount (%" PRIu32 ")",
|
|
|
|
ActualCount, MaxCount);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (Offset != 0)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "Unsupported Offset (%" PRIu32 "), expected 0", Offset);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (ActualCount > lengthInBytes / sizeof(WCHAR))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR,
|
|
|
|
"failed to read string, ActualCount (%" PRIu32
|
|
|
|
") * sizeof(WCHAR) > lengthInBytes (%" PRIu32 ")",
|
|
|
|
ActualCount, lengthInBytes);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (str)
|
|
|
|
*str = Stream_PointerAs(s, WCHAR);
|
2023-10-25 14:48:36 +03:00
|
|
|
|
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, MaxCount))
|
|
|
|
return FALSE;
|
|
|
|
Stream_Seek(s, MaxCount);
|
|
|
|
return TRUE;
|
2023-10-25 11:38:48 +03:00
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_packet_header(wLog* log, wStream* s, TSG_PACKET_HEADER* header)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
const UINT32 ComponentId = TS_GATEWAY_TRANSPORT;
|
|
|
|
|
|
|
|
WINPR_ASSERT(header);
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 2, sizeof(UINT16)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read_UINT16(s, header->ComponentId);
|
|
|
|
Stream_Read_UINT16(s, header->PacketId);
|
|
|
|
|
|
|
|
if (ComponentId != header->ComponentId)
|
|
|
|
{
|
|
|
|
char buffer[64] = { 0 };
|
|
|
|
char buffer2[64] = { 0 };
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "Unexpected ComponentId: %s, Expected %s",
|
|
|
|
tsg_component_id_to_string(header->ComponentId, buffer, sizeof(buffer)),
|
|
|
|
tsg_component_id_to_string(ComponentId, buffer2, sizeof(buffer2)));
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_write_packet_header(wLog* log, wStream* s, const TSG_PACKET_HEADER* header)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(header);
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 2 * sizeof(UINT16)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Write_UINT16(s, header->ComponentId);
|
|
|
|
Stream_Write_UINT16(s, header->PacketId);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_nap(wLog* log, wStream* s, TSG_CAPABILITY_NAP* nap)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(nap);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 1, sizeof(UINT32)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read_UINT32(s, nap->capabilities);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_write_nap(wLog* log, wStream* s, const TSG_CAPABILITY_NAP* nap)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(nap);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 1 * sizeof(UINT32)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Write_UINT32(s, nap->capabilities);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_tsg_caps(wLog* log, wStream* s, TSG_PACKET_CAPABILITIES* caps)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
UINT32 capabilityType = 0;
|
|
|
|
UINT32 count = 0;
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 3, sizeof(UINT32)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read_UINT32(s, count);
|
|
|
|
Stream_Read_UINT32(s, capabilityType);
|
|
|
|
Stream_Read_UINT32(s, caps->capabilityType);
|
|
|
|
if (capabilityType != caps->capabilityType)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "Inconsistent data, capabilityType %s != %s",
|
|
|
|
tsg_packet_id_to_string(capabilityType),
|
|
|
|
tsg_packet_id_to_string(caps->capabilityType));
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
switch (caps->capabilityType)
|
|
|
|
{
|
|
|
|
case TSG_CAPABILITY_TYPE_NAP:
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_read_nap(log, s, &caps->tsgPacket.tsgCapNap);
|
2023-10-25 11:38:48 +03:00
|
|
|
default:
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR,
|
|
|
|
"unknown TSG_PACKET_CAPABILITIES::capabilityType 0x%04" PRIx32,
|
|
|
|
caps->capabilityType);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_write_tsg_caps(wLog* log, wStream* s, const TSG_PACKET_CAPABILITIES* caps)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 2 * sizeof(UINT32)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Write_UINT32(s, caps->capabilityType);
|
|
|
|
Stream_Write_UINT32(s, caps->capabilityType);
|
|
|
|
|
|
|
|
switch (caps->capabilityType)
|
|
|
|
{
|
|
|
|
case TSG_CAPABILITY_TYPE_NAP:
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_write_nap(log, s, &caps->tsgPacket.tsgCapNap);
|
2023-10-25 11:38:48 +03:00
|
|
|
default:
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR,
|
|
|
|
"unknown TSG_PACKET_CAPABILITIES::capabilityType 0x%04" PRIx32,
|
|
|
|
caps->capabilityType);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_version_caps(wLog* log, wStream* s, UINT32* index,
|
|
|
|
TSG_PACKET_VERSIONCAPS* caps)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(caps);
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_packet_header(log, s, &caps->tsgHeader))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
UINT32 TSGCapsPtr = 0;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, s, index, &TSGCapsPtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 10))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read_UINT32(s, caps->numCapabilities);
|
|
|
|
Stream_Read_UINT16(s, caps->majorVersion);
|
|
|
|
Stream_Read_UINT16(s, caps->minorVersion);
|
|
|
|
Stream_Read_UINT16(s, caps->quarantineCapabilities);
|
|
|
|
/* 4-byte alignment */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_stream_align(log, s, 4))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_read_tsg_caps(log, s, &caps->tsgCaps);
|
2023-10-25 11:38:48 +03:00
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_write_version_caps(wLog* log, wStream* s, UINT32* index,
|
2023-10-25 11:38:48 +03:00
|
|
|
const TSG_PACKET_VERSIONCAPS* caps)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(caps);
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_write_packet_header(log, s, &caps->tsgHeader))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(log, s, index, 1)) /* TsgCapsPtr (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 10))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Write_UINT32(s, caps->numCapabilities);
|
|
|
|
Stream_Write_UINT16(s, caps->majorVersion);
|
|
|
|
Stream_Write_UINT16(s, caps->minorVersion);
|
|
|
|
Stream_Write_UINT16(s, caps->quarantineCapabilities);
|
|
|
|
|
|
|
|
/* 4-byte alignment (30 + 2) */
|
|
|
|
Stream_Write_UINT16(s, 0x0000); /* pad (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, caps->numCapabilities); /* MaxCount (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_write_tsg_caps(log, s, &caps->tsgCaps);
|
2023-10-25 11:38:48 +03:00
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_quarenc_response(wLog* log, wStream* s, UINT32* index,
|
2023-10-25 11:38:48 +03:00
|
|
|
TSG_PACKET_QUARENC_RESPONSE* quarenc)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(quarenc);
|
|
|
|
UINT32 CertChainDataPtr = 0;
|
|
|
|
UINT32 VersionCapsPtr = 0;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read_UINT32(s, quarenc->flags);
|
|
|
|
Stream_Read_UINT32(s, quarenc->certChainLen);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, s, index, &CertChainDataPtr, quarenc->certChainLen != 0))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 1, sizeof(quarenc->nonce)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read(s, &quarenc->nonce, sizeof(quarenc->nonce));
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, s, index, &VersionCapsPtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_quarenc_data(wLog* log, wStream* s, UINT32* index,
|
2023-10-25 11:38:48 +03:00
|
|
|
TSG_PACKET_QUARENC_RESPONSE* quarenc)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(quarenc);
|
|
|
|
|
|
|
|
if (quarenc->certChainLen > 0)
|
|
|
|
{
|
2024-07-03 16:36:37 +03:00
|
|
|
/* [MS-TSGU] 2.2.9.2.1.6 TSG_PACKET_QUARENC_RESPONSE::certChainLen number of WCHAR */
|
|
|
|
if (!tsg_ndr_read_string(log, s, &quarenc->certChainData,
|
|
|
|
quarenc->certChainLen * sizeof(WCHAR)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
/* 4-byte alignment */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_stream_align(log, s, 4))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_read_version_caps(log, s, index, &quarenc->versionCaps);
|
2023-10-25 11:38:48 +03:00
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_write_auth(wLog* log, wStream* s, UINT32* index, const TSG_PACKET_AUTH* auth)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(auth);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_write_version_caps(log, s, index, &auth->tsgVersionCaps))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, auth->cookieLen);
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(log, s, index, auth->cookieLen))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, auth->cookieLen))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Write(s, auth->cookie, auth->cookieLen);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_write_reauth(wLog* log, wStream* s, UINT32* index,
|
|
|
|
const TSG_PACKET_REAUTH* auth)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(auth);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 12))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT64(s, auth->tunnelContext); /* TunnelContext (8 bytes) */
|
|
|
|
Stream_Write_UINT32(s, auth->packetId); /* PacketId (4 bytes) */
|
|
|
|
|
|
|
|
switch (auth->packetId)
|
|
|
|
{
|
|
|
|
case TSG_PACKET_TYPE_VERSIONCAPS:
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_write_version_caps(log, s, index,
|
|
|
|
&auth->tsgInitialPacket.packetVersionCaps);
|
2023-10-25 11:38:48 +03:00
|
|
|
case TSG_PACKET_TYPE_AUTH:
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_write_auth(log, s, index, &auth->tsgInitialPacket.packetAuth);
|
2023-10-25 11:38:48 +03:00
|
|
|
default:
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "unexpected packetId %s",
|
|
|
|
tsg_packet_id_to_string(auth->packetId));
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_packet_response(wLog* log, wStream* s, UINT32* index,
|
|
|
|
TSG_PACKET_RESPONSE* response)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
UINT32 ResponseDataPtr = 0;
|
|
|
|
UINT32 MaxSizeValue = 0;
|
|
|
|
UINT32 MaxOffsetValue = 0;
|
|
|
|
UINT32 idleTimeout = 0;
|
|
|
|
|
|
|
|
WINPR_ASSERT(response);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 2, sizeof(UINT32)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read_UINT32(s, response->flags); /* Flags (4 bytes) */
|
2024-07-23 10:14:04 +03:00
|
|
|
Stream_Seek_UINT32(s); /* Reserved (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
|
|
|
|
if (response->flags != TSG_PACKET_TYPE_QUARREQUEST)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR,
|
|
|
|
"Unexpected Packet Response Flags: 0x%08" PRIX32
|
|
|
|
", Expected TSG_PACKET_TYPE_QUARREQUEST",
|
|
|
|
response->flags);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, s, index, &ResponseDataPtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 10, sizeof(UINT32)))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, response->responseDataLen); /* ResponseDataLength (4 bytes) */
|
|
|
|
Stream_Read_INT32(
|
|
|
|
s, response->redirectionFlags.enableAllRedirections); /* EnableAllRedirections (4 bytes) */
|
|
|
|
Stream_Read_INT32(
|
|
|
|
s,
|
|
|
|
response->redirectionFlags.disableAllRedirections); /* DisableAllRedirections (4 bytes) */
|
|
|
|
Stream_Read_INT32(s, response->redirectionFlags
|
|
|
|
.driveRedirectionDisabled); /* DriveRedirectionDisabled (4 bytes) */
|
|
|
|
Stream_Read_INT32(s,
|
|
|
|
response->redirectionFlags
|
|
|
|
.printerRedirectionDisabled); /* PrinterRedirectionDisabled (4 bytes) */
|
|
|
|
Stream_Read_INT32(
|
|
|
|
s,
|
|
|
|
response->redirectionFlags.portRedirectionDisabled); /* PortRedirectionDisabled (4 bytes) */
|
|
|
|
Stream_Read_INT32(s, response->redirectionFlags.reserved); /* Reserved (4 bytes) */
|
|
|
|
Stream_Read_INT32(
|
|
|
|
s, response->redirectionFlags
|
|
|
|
.clipboardRedirectionDisabled); /* ClipboardRedirectionDisabled (4 bytes) */
|
|
|
|
Stream_Read_INT32(
|
|
|
|
s,
|
|
|
|
response->redirectionFlags.pnpRedirectionDisabled); /* PnpRedirectionDisabled (4 bytes) */
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, MaxSizeValue); /* (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, MaxOffsetValue); /* (4 bytes) */
|
|
|
|
|
|
|
|
if (MaxSizeValue != response->responseDataLen)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "Unexpected size value: %" PRIu32 ", expected: %" PRIu32 "",
|
|
|
|
MaxSizeValue, response->responseDataLen);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, MaxSizeValue))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (MaxSizeValue == 4)
|
|
|
|
Stream_Read_UINT32(s, idleTimeout);
|
|
|
|
else
|
|
|
|
Stream_Seek(s, MaxSizeValue); /* ResponseData */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-08-25 13:14:09 +03:00
|
|
|
WINPR_ATTR_FORMAT_ARG(3, 4)
|
2023-10-11 16:21:15 +03:00
|
|
|
static BOOL tsg_print(char** buffer, size_t* len, WINPR_FORMAT_ARG const char* fmt, ...)
|
2020-06-17 09:41:21 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int rc = 0;
|
2020-06-17 09:41:21 +03:00
|
|
|
va_list ap;
|
|
|
|
if (!buffer || !len || !fmt)
|
|
|
|
return FALSE;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
rc = vsnprintf(*buffer, *len, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
if ((rc < 0) || ((size_t)rc > *len))
|
|
|
|
return FALSE;
|
|
|
|
*len -= (size_t)rc;
|
|
|
|
*buffer += (size_t)rc;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_header_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_HEADER* header)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(header);
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
return tsg_print(buffer, length,
|
|
|
|
"header { ComponentId=0x%04" PRIx16 ", PacketId=0x%04" PRIx16 " }",
|
|
|
|
header->ComponentId, header->PacketId);
|
|
|
|
}
|
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
static BOOL tsg_type_capability_nap_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_CAPABILITY_NAP* cur)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(cur);
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, "%s { capabilities=0x%08" PRIx32 " }",
|
|
|
|
tsg_packet_id_to_string(TSG_CAPABILITY_TYPE_NAP), cur->capabilities);
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
static BOOL tsg_packet_capabilities_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_CAPABILITIES* caps, UINT32 numCaps)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
if (!tsg_print(buffer, length, "capabilities { "))
|
|
|
|
return FALSE;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < numCaps; x++)
|
2020-06-17 09:41:21 +03:00
|
|
|
{
|
|
|
|
const TSG_PACKET_CAPABILITIES* cur = &caps[x];
|
|
|
|
switch (cur->capabilityType)
|
|
|
|
{
|
|
|
|
case TSG_CAPABILITY_TYPE_NAP:
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!tsg_type_capability_nap_to_string(buffer, length, &cur->tsgPacket.tsgCapNap))
|
2020-06-17 09:41:21 +03:00
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!tsg_print(buffer, length, "TSG_UNKNOWN_CAPABILITY"))
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_versioncaps_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_VERSIONCAPS* caps)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
if (!tsg_print(buffer, length, "versioncaps { "))
|
|
|
|
return FALSE;
|
|
|
|
if (!tsg_packet_header_to_string(buffer, length, &caps->tsgHeader))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " "))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if (!tsg_packet_capabilities_to_string(buffer, length, &caps->tsgCaps, caps->numCapabilities))
|
2020-06-17 09:41:21 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length,
|
|
|
|
" numCapabilities=0x%08" PRIx32 ", majorVersion=0x%04" PRIx16
|
|
|
|
", minorVersion=0x%04" PRIx16 ", quarantineCapabilities=0x%04" PRIx16,
|
|
|
|
caps->numCapabilities, caps->majorVersion, caps->minorVersion,
|
|
|
|
caps->quarantineCapabilities))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
static BOOL tsg_packet_quarconfigrequest_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_QUARCONFIGREQUEST* caps)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "quarconfigrequest { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " flags=0x%08" PRIx32, caps->flags))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_quarrequest_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_QUARREQUEST* caps)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
char* name = NULL;
|
|
|
|
char* strdata = NULL;
|
|
|
|
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "quarrequest { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (caps->nameLength > 0)
|
|
|
|
{
|
|
|
|
if (caps->nameLength > INT_MAX)
|
|
|
|
return FALSE;
|
2022-10-28 09:09:27 +03:00
|
|
|
name = ConvertWCharNToUtf8Alloc(caps->machineName, caps->nameLength, NULL);
|
|
|
|
if (!name)
|
2021-10-15 12:45:08 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
strdata = winpr_BinToHexString(caps->data, caps->dataLen, TRUE);
|
|
|
|
if (strdata || (caps->dataLen == 0))
|
|
|
|
rc = tsg_print(buffer, length,
|
|
|
|
" flags=0x%08" PRIx32 ", machineName=%s [%" PRIu32 "], data[%" PRIu32 "]=%s",
|
|
|
|
caps->flags, name, caps->nameLength, caps->dataLen, strdata);
|
|
|
|
free(name);
|
|
|
|
free(strdata);
|
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* tsg_bool_to_string(BOOL val)
|
|
|
|
{
|
|
|
|
if (val)
|
|
|
|
return "true";
|
|
|
|
return "false";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* tsg_redirection_flags_to_string(char* buffer, size_t size,
|
|
|
|
const TSG_REDIRECTION_FLAGS* flags)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(buffer || (size == 0));
|
|
|
|
WINPR_ASSERT(flags);
|
|
|
|
|
|
|
|
_snprintf(buffer, size,
|
|
|
|
"enableAllRedirections=%s, disableAllRedirections=%s, driveRedirectionDisabled=%s, "
|
|
|
|
"printerRedirectionDisabled=%s, portRedirectionDisabled=%s, reserved=%s, "
|
|
|
|
"clipboardRedirectionDisabled=%s, pnpRedirectionDisabled=%s",
|
|
|
|
tsg_bool_to_string(flags->enableAllRedirections),
|
|
|
|
tsg_bool_to_string(flags->disableAllRedirections),
|
|
|
|
tsg_bool_to_string(flags->driveRedirectionDisabled),
|
|
|
|
tsg_bool_to_string(flags->printerRedirectionDisabled),
|
|
|
|
tsg_bool_to_string(flags->portRedirectionDisabled),
|
|
|
|
tsg_bool_to_string(flags->reserved),
|
|
|
|
tsg_bool_to_string(flags->clipboardRedirectionDisabled),
|
|
|
|
tsg_bool_to_string(flags->pnpRedirectionDisabled));
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_response_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_RESPONSE* caps)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
char* strdata = NULL;
|
|
|
|
char tbuffer[8192] = { 0 };
|
|
|
|
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "response { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strdata = winpr_BinToHexString(caps->responseData, caps->responseDataLen, TRUE);
|
|
|
|
if (strdata || (caps->responseDataLen == 0))
|
|
|
|
rc = tsg_print(
|
|
|
|
buffer, length,
|
|
|
|
" flags=0x%08" PRIx32 ", reserved=0x%08" PRIx32 ", responseData[%" PRIu32
|
|
|
|
"]=%s, redirectionFlags={ %s }",
|
|
|
|
caps->flags, caps->reserved, caps->responseDataLen, strdata,
|
|
|
|
tsg_redirection_flags_to_string(tbuffer, ARRAYSIZE(tbuffer), &caps->redirectionFlags));
|
|
|
|
free(strdata);
|
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_quarenc_response_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_QUARENC_RESPONSE* caps)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
char* strdata = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
RPC_CSTR uuid = NULL;
|
2021-10-15 12:45:08 +03:00
|
|
|
char tbuffer[8192] = { 0 };
|
|
|
|
size_t size = ARRAYSIZE(tbuffer);
|
|
|
|
char* ptbuffer = tbuffer;
|
|
|
|
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "quarenc_response { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (caps->certChainLen > 0)
|
|
|
|
{
|
|
|
|
if (caps->certChainLen > INT_MAX)
|
|
|
|
return FALSE;
|
2022-10-28 09:09:27 +03:00
|
|
|
strdata = ConvertWCharNToUtf8Alloc(caps->certChainData, caps->certChainLen, NULL);
|
|
|
|
if (!strdata)
|
2021-10-15 12:45:08 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
tsg_packet_versioncaps_to_string(&ptbuffer, &size, &caps->versionCaps);
|
2021-10-15 12:45:08 +03:00
|
|
|
UuidToStringA(&caps->nonce, &uuid);
|
|
|
|
if (strdata || (caps->certChainLen == 0))
|
|
|
|
rc =
|
|
|
|
tsg_print(buffer, length,
|
|
|
|
" flags=0x%08" PRIx32 ", certChain[%" PRIu32 "]=%s, nonce=%s, versionCaps=%s",
|
|
|
|
caps->flags, caps->certChainLen, strdata, uuid, tbuffer);
|
|
|
|
free(strdata);
|
2023-11-02 12:57:47 +03:00
|
|
|
RpcStringFreeA(&uuid);
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_message_response_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_MSG_RESPONSE* caps)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "msg_response { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length,
|
|
|
|
" msgID=0x%08" PRIx32 ", msgType=0x%08" PRIx32 ", isMsgPresent=%" PRId32,
|
|
|
|
caps->msgID, caps->msgType, caps->isMsgPresent))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_caps_response_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_CAPS_RESPONSE* caps)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "caps_response { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_packet_quarenc_response_to_string(buffer, length, &caps->pktQuarEncResponse))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_packet_message_response_to_string(buffer, length, &caps->pktConsentMessage))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_message_request_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_MSG_REQUEST* caps)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "caps_message_request { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " maxMessagesPerBatch=%" PRIu32, caps->maxMessagesPerBatch))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_auth_to_string(char** buffer, size_t* length, const TSG_PACKET_AUTH* caps)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
char* strdata = NULL;
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "caps_message_request { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_packet_versioncaps_to_string(buffer, length, &caps->tsgVersionCaps))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strdata = winpr_BinToHexString(caps->cookie, caps->cookieLen, TRUE);
|
|
|
|
if (strdata || (caps->cookieLen == 0))
|
|
|
|
rc = tsg_print(buffer, length, " cookie[%" PRIu32 "]=%s", caps->cookieLen, strdata);
|
|
|
|
free(strdata);
|
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_packet_reauth_to_string(char** buffer, size_t* length,
|
|
|
|
const TSG_PACKET_REAUTH* caps)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
WINPR_ASSERT(buffer);
|
|
|
|
WINPR_ASSERT(length);
|
|
|
|
WINPR_ASSERT(caps);
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, "caps_message_request { "))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_print(buffer, length, " tunnelContext=0x%016" PRIx64 ", packetId=%s [0x%08" PRIx32 "]",
|
|
|
|
caps->tunnelContext, tsg_packet_id_to_string(caps->packetId), caps->packetId))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (caps->packetId)
|
|
|
|
{
|
|
|
|
case TSG_PACKET_TYPE_VERSIONCAPS:
|
|
|
|
rc = tsg_packet_versioncaps_to_string(buffer, length,
|
2023-10-25 11:38:48 +03:00
|
|
|
&caps->tsgInitialPacket.packetVersionCaps);
|
2021-10-15 12:45:08 +03:00
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_AUTH:
|
2023-10-25 11:38:48 +03:00
|
|
|
rc = tsg_packet_auth_to_string(buffer, length, &caps->tsgInitialPacket.packetAuth);
|
2021-10-15 12:45:08 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = tsg_print(buffer, length, "TODO: Unhandled packet type %s [0x%08" PRIx32 "]",
|
|
|
|
tsg_packet_id_to_string(caps->packetId), caps->packetId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return tsg_print(buffer, length, " }");
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
static const char* tsg_packet_to_string(const TSG_PACKET* packet)
|
|
|
|
{
|
|
|
|
size_t len = 8192;
|
|
|
|
static char sbuffer[8193] = { 0 };
|
|
|
|
char* buffer = sbuffer;
|
|
|
|
|
|
|
|
if (!tsg_print(&buffer, &len, "TSG_PACKET { packetId=%s [0x%08" PRIx32 "], ",
|
|
|
|
tsg_packet_id_to_string(packet->packetId), packet->packetId))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
switch (packet->packetId)
|
|
|
|
{
|
|
|
|
case TSG_PACKET_TYPE_HEADER:
|
2023-10-25 11:38:48 +03:00
|
|
|
if (!tsg_packet_header_to_string(&buffer, &len, &packet->tsgPacket.packetHeader))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_VERSIONCAPS:
|
|
|
|
if (!tsg_packet_versioncaps_to_string(&buffer, &len,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet->tsgPacket.packetVersionCaps))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_QUARCONFIGREQUEST:
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!tsg_packet_quarconfigrequest_to_string(&buffer, &len,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet->tsgPacket.packetQuarConfigRequest))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_QUARREQUEST:
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!tsg_packet_quarrequest_to_string(&buffer, &len,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet->tsgPacket.packetQuarRequest))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_RESPONSE:
|
2023-10-25 11:38:48 +03:00
|
|
|
if (!tsg_packet_response_to_string(&buffer, &len, &packet->tsgPacket.packetResponse))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_QUARENC_RESPONSE:
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!tsg_packet_quarenc_response_to_string(&buffer, &len,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet->tsgPacket.packetQuarEncResponse))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_CAPS_RESPONSE:
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!tsg_packet_caps_response_to_string(&buffer, &len,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet->tsgPacket.packetCapsResponse))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_MSGREQUEST_PACKET:
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!tsg_packet_message_request_to_string(&buffer, &len,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet->tsgPacket.packetMsgRequest))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_MESSAGE_PACKET:
|
2021-10-15 12:45:08 +03:00
|
|
|
if (!tsg_packet_message_response_to_string(&buffer, &len,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet->tsgPacket.packetMsgResponse))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_AUTH:
|
2023-10-25 11:38:48 +03:00
|
|
|
if (!tsg_packet_auth_to_string(&buffer, &len, &packet->tsgPacket.packetAuth))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case TSG_PACKET_TYPE_REAUTH:
|
2023-10-25 11:38:48 +03:00
|
|
|
if (!tsg_packet_reauth_to_string(&buffer, &len, &packet->tsgPacket.packetReauth))
|
2020-06-17 09:41:21 +03:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!tsg_print(&buffer, &len, "INVALID"))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tsg_print(&buffer, &len, " }"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return sbuffer;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_stream_align(wLog* log, wStream* s, size_t align)
|
2018-10-18 11:15:51 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
size_t pos = 0;
|
2018-10-18 11:15:51 +03:00
|
|
|
size_t offset = 0;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pos = Stream_GetPosition(s);
|
|
|
|
|
2018-10-18 11:41:03 +03:00
|
|
|
if ((pos % align) != 0)
|
|
|
|
offset = align - pos % align;
|
2018-10-18 11:15:51 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, offset))
|
|
|
|
return FALSE;
|
|
|
|
Stream_Seek(s, offset);
|
|
|
|
return TRUE;
|
2018-10-18 11:15:51 +03:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:43:37 +03:00
|
|
|
static BIO_METHOD* BIO_s_tsg(void);
|
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)
|
|
|
|
*/
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
static int TsProxySendToServer(handle_t IDL_handle, const byte pRpcMessage[], UINT32 count,
|
|
|
|
UINT32* lengths)
|
2012-04-01 05:32:13 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
|
|
|
rdpTsg* tsg = NULL;
|
|
|
|
size_t length = 0;
|
2018-09-28 09:43:43 +03:00
|
|
|
const byte* buffer1 = NULL;
|
|
|
|
const byte* buffer2 = NULL;
|
|
|
|
const byte* buffer3 = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 buffer1Length = 0;
|
|
|
|
UINT32 buffer2Length = 0;
|
|
|
|
UINT32 buffer3Length = 0;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 numBuffers = 0;
|
|
|
|
UINT32 totalDataBytes = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
tsg = (rdpTsg*)IDL_handle;
|
2012-04-24 04:13:06 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
length = 28ull + totalDataBytes;
|
|
|
|
if (length > INT_MAX)
|
|
|
|
return -1;
|
2018-09-28 09:43:43 +03:00
|
|
|
s = Stream_New(NULL, length);
|
2015-05-29 14:46:50 +03:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "Stream_New failed!");
|
2015-05-29 14:46:50 +03:00
|
|
|
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) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyWriteTunnelContext(tsg->log, s, &tsg->ChannelContext))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
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
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!rpc_client_write_call(tsg->rpc, s, TsProxySendToServerOpnum))
|
2012-04-24 04:13:06 +04:00
|
|
|
return -1;
|
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
return (int)length;
|
2023-10-25 11:38:48 +03:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return -1;
|
2012-04-01 05:32:13 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 1
|
|
|
|
*
|
|
|
|
* HRESULT TsProxyCreateTunnel(
|
2023-10-25 11:38:48 +03:00
|
|
|
* [in, ref] TSG_PACKET* tsgPacket,
|
|
|
|
* [out, ref] TSG_PACKET** tsgPacketResponse,
|
2015-02-18 00:15:57 +03:00
|
|
|
* [out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* tunnelContext,
|
|
|
|
* [out] unsigned long* tunnelId
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
static BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg, const TSG_PACKET* tsgPacket)
|
2012-03-26 10:45:01 +04:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
BOOL write = TRUE;
|
|
|
|
UINT16 opnum = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
|
|
|
rdpRpc* rpc = NULL;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
if (!tsg || !tsg->rpc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
rpc = tsg->rpc;
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "%s", tsg_packet_to_string(tsgPacket));
|
2018-09-28 09:43:43 +03:00
|
|
|
s = Stream_New(NULL, 108);
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (tsgPacket->packetId)
|
2015-02-16 02:22:49 +03:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
case TSG_PACKET_TYPE_VERSIONCAPS:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
const TSG_PACKET_VERSIONCAPS* packetVersionCaps =
|
|
|
|
&tsgPacket->tsgPacket.packetVersionCaps;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, tsgPacket->packetId); /* PacketId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, tsgPacket->packetId); /* SwitchValue (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketVersionCapsPtr (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_write_version_caps(tsg->log, s, &index, packetVersionCaps))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
Stream_Write_UINT8(s, 0x8A);
|
|
|
|
Stream_Write_UINT8(s, 0xE3);
|
|
|
|
Stream_Write_UINT8(s, 0x13);
|
|
|
|
Stream_Write_UINT8(s, 0x71);
|
|
|
|
Stream_Write_UINT8(s, 0x02);
|
|
|
|
Stream_Write_UINT8(s, 0xF4);
|
|
|
|
Stream_Write_UINT8(s, 0x36);
|
|
|
|
Stream_Write_UINT8(s, 0x71);
|
|
|
|
Stream_Write_UINT32(s, 0x00040001); /* 1.4 (version?) */
|
|
|
|
Stream_Write_UINT32(s, 0x00000001); /* 1 (element count?) */
|
|
|
|
/* p_cont_list_t */
|
|
|
|
Stream_Write_UINT8(s, 2); /* ncontext_elem */
|
|
|
|
Stream_Write_UINT8(s, 0x40); /* reserved1 */
|
|
|
|
Stream_Write_UINT16(s, 0x0028); /* reserved2 */
|
|
|
|
/* p_syntax_id_t */
|
|
|
|
Stream_Write(s, &TSGU_UUID, sizeof(p_uuid_t));
|
|
|
|
Stream_Write_UINT32(s, TSGU_SYNTAX_IF_VERSION);
|
|
|
|
/* p_syntax_id_t */
|
|
|
|
Stream_Write(s, &NDR_UUID, sizeof(p_uuid_t));
|
|
|
|
Stream_Write_UINT32(s, NDR_SYNTAX_IF_VERSION);
|
|
|
|
opnum = TsProxyCreateTunnelOpnum;
|
|
|
|
}
|
2023-10-25 11:38:48 +03:00
|
|
|
break;
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
case TSG_PACKET_TYPE_REAUTH:
|
2012-11-09 12:04:47 +04:00
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
const TSG_PACKET_REAUTH* packetReauth = &tsgPacket->tsgPacket.packetReauth;
|
|
|
|
UINT32 index = 0;
|
2023-10-25 14:48:36 +03:00
|
|
|
Stream_Write_UINT32(s, tsgPacket->packetId); /* PacketId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, tsgPacket->packetId); /* SwitchValue (4 bytes) */
|
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketReauthPtr (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_write_reauth(tsg->log, s, &index, packetReauth))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
opnum = TsProxyCreateTunnelOpnum;
|
2012-11-09 12:04:47 +04:00
|
|
|
}
|
2023-10-25 11:38:48 +03:00
|
|
|
break;
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
default:
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_WARN, "unexpected packetId %s",
|
|
|
|
tsg_packet_id_to_string(tsgPacket->packetId));
|
2023-10-25 11:38:48 +03:00
|
|
|
write = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2018-10-18 10:09:30 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
rc = TRUE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if (write)
|
|
|
|
return rpc_client_write_call(rpc, s, opnum);
|
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return rc;
|
|
|
|
}
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_consent_message(wLog* log, rdpContext* context, wStream* s, UINT32* index)
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
TSG_PACKET_STRING_MESSAGE packetStringMessage = { 0 };
|
|
|
|
UINT32 Pointer = 0;
|
2014-05-21 19:32:14 +04:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(index);
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
Stream_Read_INT32(s, packetStringMessage.isDisplayMandatory);
|
|
|
|
Stream_Read_INT32(s, packetStringMessage.isConsentMandatory);
|
|
|
|
Stream_Read_UINT32(s, packetStringMessage.msgBytes);
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, s, index, &Pointer, FALSE))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (Pointer)
|
|
|
|
{
|
|
|
|
if (packetStringMessage.msgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH)
|
2012-11-09 12:04:47 +04:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "Out of Spec Message Length %" PRIu32 "",
|
|
|
|
packetStringMessage.msgBytes);
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
2012-11-09 12:04:47 +04:00
|
|
|
}
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_string(log, s, &packetStringMessage.msgBuffer,
|
|
|
|
packetStringMessage.msgBytes))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if (context->instance)
|
2013-10-18 00:51:04 +04:00
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
return IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance,
|
|
|
|
TSG_ASYNC_MESSAGE_CONSENT_MESSAGE
|
|
|
|
? GATEWAY_MESSAGE_CONSENT
|
|
|
|
: TSG_ASYNC_MESSAGE_SERVICE_MESSAGE,
|
|
|
|
packetStringMessage.isDisplayMandatory != 0,
|
|
|
|
packetStringMessage.isConsentMandatory != 0,
|
|
|
|
packetStringMessage.msgBytes, packetStringMessage.msgBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-11-01 05:12:06 +04:00
|
|
|
|
2023-11-20 18:20:08 +03:00
|
|
|
static BOOL tsg_ndr_read_tunnel_context(wLog* log, wStream* s, CONTEXT_HANDLE* tunnelContext,
|
|
|
|
UINT32* tunnelId)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!tsg_stream_align(log, s, 4))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* TunnelContext (20 bytes) */
|
|
|
|
if (!TsProxyReadTunnelContext(log, s, tunnelContext))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
WINPR_ASSERT(tunnelId);
|
|
|
|
Stream_Read_UINT32(s, *tunnelId); /* TunnelId (4 bytes) */
|
|
|
|
|
|
|
|
UINT32 ReturnValue = 0;
|
|
|
|
Stream_Read_UINT32(s, ReturnValue); /* ReturnValue (4 bytes) */
|
|
|
|
if (ReturnValue != NO_ERROR)
|
|
|
|
WLog_WARN(TAG, "ReturnValue=%s", NtStatus2Tag(ReturnValue));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
static BOOL tsg_ndr_read_caps_response(wLog* log, rdpContext* context, wStream* s, UINT32* index,
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 PacketPtr, TSG_PACKET_CAPS_RESPONSE* caps,
|
|
|
|
CONTEXT_HANDLE* tunnelContext, UINT32* tunnelId)
|
|
|
|
{
|
|
|
|
UINT32 PacketQuarResponsePtr = 0;
|
|
|
|
UINT32 MessageSwitchValue = 0;
|
|
|
|
UINT32 MsgId = 0;
|
|
|
|
UINT32 MsgType = 0;
|
|
|
|
UINT32 IsMessagePresent = 0;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(index);
|
|
|
|
WINPR_ASSERT(caps);
|
2013-11-01 05:12:06 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, s, index, &PacketQuarResponsePtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_quarenc_response(log, s, index, &caps->pktQuarEncResponse))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2021-01-27 11:44:19 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if (PacketPtr)
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
Stream_Read_UINT32(s, MsgId); /* MsgId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, MsgType); /* MsgType (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, IsMessagePresent); /* IsMessagePresent (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, MessageSwitchValue); /* MessageSwitchValue (4 bytes) */
|
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2023-11-20 18:20:08 +03:00
|
|
|
{
|
|
|
|
UINT32 MsgPtr = 0;
|
|
|
|
if (!tsg_ndr_pointer_read(log, s, index, &MsgPtr, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_quarenc_data(log, s, index, &caps->pktQuarEncResponse))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-10-18 11:41:03 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
switch (MessageSwitchValue)
|
|
|
|
{
|
|
|
|
case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE:
|
|
|
|
case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE:
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_consent_message(log, context, s, index))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
case TSG_ASYNC_MESSAGE_REAUTH:
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_stream_align(log, s, 8))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
Stream_Seek_UINT64(s); /* TunnelContext (8 bytes) */
|
|
|
|
}
|
|
|
|
break;
|
2013-10-18 00:51:04 +04:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
default:
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "Unexpected Message Type: 0x%" PRIX32 "",
|
|
|
|
MessageSwitchValue);
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2012-11-09 12:04:47 +04:00
|
|
|
}
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2023-11-20 18:20:08 +03:00
|
|
|
return tsg_ndr_read_tunnel_context(log, s, tunnelContext, tunnelId);
|
2023-10-25 11:38:48 +03:00
|
|
|
fail:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, const RPC_PDU* pdu,
|
2023-10-25 11:38:48 +03:00
|
|
|
CONTEXT_HANDLE* tunnelContext, UINT32* tunnelId)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
UINT32 index = 0;
|
|
|
|
TSG_PACKET packet = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 SwitchValue = 0;
|
|
|
|
rdpContext* context = NULL;
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 PacketPtr = 0;
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(tsg->rpc);
|
|
|
|
WINPR_ASSERT(tsg->rpc->transport);
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
context = transport_get_context(tsg->rpc->transport);
|
|
|
|
WINPR_ASSERT(context);
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if (!pdu)
|
|
|
|
return FALSE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketPtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, 8))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */
|
2013-10-11 13:07:33 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "%s", tsg_packet_id_to_string(packet.packetId));
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if ((packet.packetId == TSG_PACKET_TYPE_CAPS_RESPONSE) &&
|
|
|
|
(SwitchValue == TSG_PACKET_TYPE_CAPS_RESPONSE))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_caps_response(tsg->log, context, pdu->s, &index, PacketPtr,
|
2023-10-25 11:38:48 +03:00
|
|
|
&packet.tsgPacket.packetCapsResponse, tunnelContext,
|
|
|
|
tunnelId))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2023-10-25 11:38:48 +03:00
|
|
|
}
|
|
|
|
else if ((packet.packetId == TSG_PACKET_TYPE_QUARENC_RESPONSE) &&
|
|
|
|
(SwitchValue == TSG_PACKET_TYPE_QUARENC_RESPONSE))
|
|
|
|
{
|
|
|
|
UINT32 PacketQuarResponsePtr = 0;
|
2012-11-09 12:04:47 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketQuarResponsePtr, TRUE))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2023-11-20 18:20:08 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_quarenc_response(tsg->log, pdu->s, &index,
|
|
|
|
&packet.tsgPacket.packetQuarEncResponse))
|
2018-10-18 11:15:51 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-11-20 18:20:08 +03:00
|
|
|
if (!tsg_ndr_read_quarenc_data(tsg->log, pdu->s, &index,
|
|
|
|
&packet.tsgPacket.packetQuarEncResponse))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-11-20 18:20:08 +03:00
|
|
|
if (!tsg_ndr_read_tunnel_context(tsg->log, pdu->s, tunnelContext, tunnelId))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
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
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR,
|
|
|
|
"Unexpected PacketId: 0x%08" PRIX32 ", Expected TSG_PACKET_TYPE_CAPS_RESPONSE "
|
|
|
|
"or TSG_PACKET_TYPE_QUARENC_RESPONSE",
|
|
|
|
packet.packetId);
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2012-11-09 08:45:29 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
|
|
|
return rc;
|
2012-11-09 08:45:29 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 2
|
|
|
|
*
|
|
|
|
* HRESULT TsProxyAuthorizeTunnel(
|
|
|
|
* [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
|
2023-10-25 11:38:48 +03:00
|
|
|
* [in, ref] TSG_PACKET* tsgPacket,
|
|
|
|
* [out, ref] TSG_PACKET** tsgPacketResponse
|
2015-02-18 00:15:57 +03:00
|
|
|
* );
|
|
|
|
*
|
|
|
|
*/
|
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
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
size_t pad = 0;
|
|
|
|
wStream* s = NULL;
|
|
|
|
size_t count = 0;
|
|
|
|
size_t offset = 0;
|
|
|
|
rdpRpc* rpc = NULL;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
if (!tsg || !tsg->rpc || !tunnelContext || !tsg->MachineName)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-10-31 17:22:32 +04:00
|
|
|
count = _wcslen(tsg->MachineName) + 1;
|
2021-10-15 12:45:08 +03:00
|
|
|
if (count > UINT32_MAX)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rpc = tsg->rpc;
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyAuthorizeTunnelWriteRequest");
|
2018-10-18 11:15:51 +03:00
|
|
|
s = Stream_New(NULL, 1024 + count * 2);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!s)
|
2015-01-13 21:50:46 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyWriteTunnelContext(tsg->log, s, tunnelContext))
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-10-31 17:22:32 +04:00
|
|
|
/* 4-byte alignment */
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 index = 0;
|
2018-09-28 09:43:43 +03:00
|
|
|
Stream_Write_UINT32(s, TSG_PACKET_TYPE_QUARREQUEST); /* PacketId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, TSG_PACKET_TYPE_QUARREQUEST); /* SwitchValue (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketQuarRequestPtr (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, 0x00000000); /* Flags (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* MachineNamePtr (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2021-10-15 12:45:08 +03:00
|
|
|
Stream_Write_UINT32(s, (UINT32)count); /* NameLength (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* DataPtr (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, 0); /* DataLength (4 bytes) */
|
2012-10-31 17:22:32 +04:00
|
|
|
/* MachineName */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_write_string(tsg->log, s, tsg->MachineName, count))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2012-10-31 17:22:32 +04:00
|
|
|
/* 4-byte alignment */
|
2018-09-28 09:43:43 +03:00
|
|
|
offset = Stream_GetPosition(s);
|
2012-10-31 17:22:32 +04:00
|
|
|
pad = rpc_offset_align(&offset, 4);
|
2018-09-28 09:43:43 +03:00
|
|
|
Stream_Zero(s, pad);
|
|
|
|
Stream_Write_UINT32(s, 0x00000000); /* MaxCount (4 bytes) */
|
|
|
|
Stream_SealLength(s);
|
|
|
|
return rpc_client_write_call(rpc, s, TsProxyAuthorizeTunnelOpnum);
|
2023-10-25 11:38:48 +03:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
2012-11-09 11:31:22 +04:00
|
|
|
}
|
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
static UINT32 tsg_redir_to_flags(const TSG_REDIRECTION_FLAGS* redirect)
|
|
|
|
{
|
|
|
|
UINT32 flags = 0;
|
|
|
|
if (redirect->enableAllRedirections)
|
|
|
|
flags |= HTTP_TUNNEL_REDIR_ENABLE_ALL;
|
|
|
|
if (redirect->disableAllRedirections)
|
|
|
|
flags |= HTTP_TUNNEL_REDIR_DISABLE_ALL;
|
|
|
|
|
|
|
|
if (redirect->driveRedirectionDisabled)
|
|
|
|
flags |= HTTP_TUNNEL_REDIR_DISABLE_DRIVE;
|
|
|
|
if (redirect->printerRedirectionDisabled)
|
|
|
|
flags |= HTTP_TUNNEL_REDIR_DISABLE_PRINTER;
|
|
|
|
if (redirect->portRedirectionDisabled)
|
|
|
|
flags |= HTTP_TUNNEL_REDIR_DISABLE_PORT;
|
|
|
|
if (redirect->clipboardRedirectionDisabled)
|
|
|
|
flags |= HTTP_TUNNEL_REDIR_DISABLE_CLIPBOARD;
|
|
|
|
if (redirect->pnpRedirectionDisabled)
|
|
|
|
flags |= HTTP_TUNNEL_REDIR_DISABLE_PNP;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tsg_redirect_apply(rdpTsg* tsg, const TSG_REDIRECTION_FLAGS* redirect)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(redirect);
|
|
|
|
|
|
|
|
rdpTransport* transport = tsg->transport;
|
|
|
|
WINPR_ASSERT(transport);
|
|
|
|
|
|
|
|
rdpContext* context = transport_get_context(transport);
|
|
|
|
UINT32 redirFlags = tsg_redir_to_flags(redirect);
|
|
|
|
return utils_apply_gateway_policy(tsg->log, context, redirFlags, "TSG");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, const RPC_PDU* pdu)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL rc = FALSE;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 SwitchValue = 0;
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
TSG_PACKET packet = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 PacketPtr = 0;
|
|
|
|
UINT32 PacketResponsePtr = 0;
|
2024-03-06 17:08:25 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(pdu);
|
|
|
|
|
|
|
|
wLog* log = tsg->log;
|
|
|
|
WINPR_ASSERT(log);
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, pdu->s, &index, &PacketPtr, TRUE))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 8))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, "%s", tsg_packet_id_to_string(packet.packetId));
|
2020-06-17 09:41:21 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if (packet.packetId == E_PROXY_NAP_ACCESSDENIED)
|
2014-03-04 20:39:39 +04:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR, "status: E_PROXY_NAP_ACCESSDENIED (0x%08X)",
|
|
|
|
E_PROXY_NAP_ACCESSDENIED);
|
|
|
|
WLog_Print(log, WLOG_ERROR,
|
|
|
|
"Ensure that the Gateway Connection Authorization Policy is correct");
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2014-03-04 20:39:39 +04:00
|
|
|
}
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
if ((packet.packetId != TSG_PACKET_TYPE_RESPONSE) || (SwitchValue != TSG_PACKET_TYPE_RESPONSE))
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_ERROR,
|
|
|
|
"Unexpected PacketId: 0x%08" PRIX32 ", Expected TSG_PACKET_TYPE_RESPONSE",
|
|
|
|
packet.packetId);
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2012-03-26 10:45:01 +04:00
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(log, pdu->s, &index, &PacketResponsePtr, TRUE))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2017-02-20 16:12:39 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_read_packet_response(log, pdu->s, &index, &packet.tsgPacket.packetResponse))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = TRUE;
|
2024-03-06 17:08:25 +03:00
|
|
|
|
|
|
|
if (packet.tsgPacket.packetResponse.flags & TSG_PACKET_TYPE_QUARREQUEST)
|
|
|
|
rc = tsg_redirect_apply(tsg, &packet.tsgPacket.packetResponse.redirectionFlags);
|
2018-09-28 09:43:43 +03:00
|
|
|
fail:
|
|
|
|
return rc;
|
2012-10-30 04:54:49 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* OpNum = 3
|
|
|
|
*
|
|
|
|
* HRESULT TsProxyMakeTunnelCall(
|
|
|
|
* [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
|
|
|
|
* [in] unsigned long procId,
|
2023-10-25 11:38:48 +03:00
|
|
|
* [in, ref] TSG_PACKET* tsgPacket,
|
|
|
|
* [out, ref] TSG_PACKET** tsgPacketResponse
|
2015-02-18 00:15:57 +03:00
|
|
|
* );
|
|
|
|
*/
|
2012-11-09 11:31:22 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL TsProxyMakeTunnelCallWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunnelContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 procId)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
|
|
|
rdpRpc* rpc = NULL;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
if (!tsg || !tsg->rpc || !tunnelContext)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
rpc = tsg->rpc;
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyMakeTunnelCallWriteRequest");
|
2018-09-28 09:43:43 +03:00
|
|
|
s = Stream_New(NULL, 40);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!s)
|
2015-01-13 21:50:46 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 index = 0;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyWriteTunnelContext(tsg->log, s, tunnelContext))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, procId); /* ProcId (4 bytes) */
|
2012-10-31 18:52:04 +04:00
|
|
|
/* 4-byte alignment */
|
2018-09-28 09:43:43 +03:00
|
|
|
Stream_Write_UINT32(s, TSG_PACKET_TYPE_MSGREQUEST_PACKET); /* PacketId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, TSG_PACKET_TYPE_MSGREQUEST_PACKET); /* SwitchValue (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketMsgRequestPtr (4 bytes) */
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, 0x00000001); /* MaxMessagesPerBatch (4 bytes) */
|
2018-09-28 09:43:43 +03:00
|
|
|
return rpc_client_write_call(rpc, s, TsProxyMakeTunnelCallOpnum);
|
2023-10-25 11:38:48 +03:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
2012-10-30 04:54:49 +04:00
|
|
|
}
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
static BOOL TsProxyReadPacketSTringMessage(rdpTsg* tsg, wStream* s, TSG_PACKET_STRING_MESSAGE* msg)
|
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 ConsentMessagePtr = 0;
|
|
|
|
UINT32 MsgPtr = 0;
|
|
|
|
UINT32 index = 0;
|
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
if (!tsg || !s || !msg)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, s, 32))
|
2018-12-11 17:24:24 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(tsg->log, s, &index, &ConsentMessagePtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
Stream_Read_INT32(s, msg->isDisplayMandatory); /* IsDisplayMandatory (4 bytes) */
|
|
|
|
Stream_Read_INT32(s, msg->isConsentMandatory); /* IsConsentMandatory (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, msg->msgBytes); /* MsgBytes (4 bytes) */
|
2018-12-11 17:24:24 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(tsg->log, s, &index, &MsgPtr, TRUE))
|
2018-12-11 17:24:24 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
return tsg_ndr_read_string(tsg->log, s, &msg->msgBuffer, msg->msgBytes);
|
2018-12-11 17:24:24 +03:00
|
|
|
}
|
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, const RPC_PDU* pdu)
|
2012-10-30 04:54:49 +04:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL rc = FALSE;
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 index = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 SwitchValue = 0;
|
2018-12-11 17:24:24 +03:00
|
|
|
TSG_PACKET packet;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpContext* context = NULL;
|
2013-03-14 20:57:45 +04:00
|
|
|
char* messageText = NULL;
|
2018-12-11 17:24:24 +03:00
|
|
|
TSG_PACKET_MSG_RESPONSE packetMsgResponse = { 0 };
|
|
|
|
TSG_PACKET_STRING_MESSAGE packetStringMessage = { 0 };
|
|
|
|
TSG_PACKET_REAUTH_MESSAGE packetReauthMessage = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 PacketPtr = 0;
|
|
|
|
UINT32 PacketMsgResponsePtr = 0;
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2021-09-06 12:12:28 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(tsg->rpc);
|
|
|
|
|
|
|
|
context = transport_get_context(tsg->rpc->transport);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2013-02-02 02:52:19 +04:00
|
|
|
/* This is an asynchronous response */
|
|
|
|
|
|
|
|
if (!pdu)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, 28))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketPtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */
|
2013-02-02 02:52:19 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "%s", tsg_packet_id_to_string(packet.packetId));
|
2020-06-17 09:41:21 +03:00
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
if ((packet.packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) ||
|
2017-02-20 16:12:39 +03:00
|
|
|
(SwitchValue != TSG_PACKET_TYPE_MESSAGE_PACKET))
|
2013-02-02 02:52:19 +04:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR,
|
|
|
|
"Unexpected PacketId: 0x%08" PRIX32 ", Expected TSG_PACKET_TYPE_MESSAGE_PACKET",
|
|
|
|
packet.packetId);
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2013-02-02 02:52:19 +04:00
|
|
|
}
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketMsgResponsePtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(pdu->s, packetMsgResponse.msgID); /* MsgId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(pdu->s, packetMsgResponse.msgType); /* MsgType (4 bytes) */
|
2018-12-11 17:24:24 +03:00
|
|
|
Stream_Read_INT32(pdu->s, packetMsgResponse.isMsgPresent); /* IsMsgPresent (4 bytes) */
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
/* 2.2.9.2.1.9 TSG_PACKET_MSG_RESPONSE: Ignore empty message body. */
|
|
|
|
if (!packetMsgResponse.isMsgPresent)
|
|
|
|
{
|
|
|
|
rc = TRUE;
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2018-12-11 17:24:24 +03:00
|
|
|
}
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
Stream_Read_UINT32(pdu->s, SwitchValue); /* 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:
|
2018-12-11 17:24:24 +03:00
|
|
|
if (!TsProxyReadPacketSTringMessage(tsg, pdu->s, &packetStringMessage))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
messageText = ConvertWCharNToUtf8Alloc(
|
|
|
|
packetStringMessage.msgBuffer, packetStringMessage.msgBytes / sizeof(WCHAR), NULL);
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_INFO, "Consent Message: %s", messageText);
|
2014-08-19 20:26:39 +04:00
|
|
|
free(messageText);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2021-09-06 12:12:28 +03:00
|
|
|
if (context->instance)
|
2018-12-11 17:24:24 +03:00
|
|
|
{
|
2021-09-06 12:12:28 +03:00
|
|
|
rc = IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance,
|
|
|
|
GATEWAY_MESSAGE_CONSENT,
|
2018-12-11 17:24:24 +03:00
|
|
|
packetStringMessage.isDisplayMandatory != 0,
|
|
|
|
packetStringMessage.isConsentMandatory != 0,
|
2019-11-06 17:24:51 +03:00
|
|
|
packetStringMessage.msgBytes, packetStringMessage.msgBuffer);
|
2022-04-28 11:49:42 +03:00
|
|
|
if (!rc)
|
|
|
|
goto fail;
|
2018-12-11 17:24:24 +03:00
|
|
|
}
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
break;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2018-12-11 17:24:24 +03:00
|
|
|
case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE:
|
|
|
|
if (!TsProxyReadPacketSTringMessage(tsg, pdu->s, &packetStringMessage))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
messageText = ConvertWCharNToUtf8Alloc(
|
|
|
|
packetStringMessage.msgBuffer, packetStringMessage.msgBytes / sizeof(WCHAR), NULL);
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_INFO, "Service Message: %s", messageText);
|
2014-08-19 20:26:39 +04:00
|
|
|
free(messageText);
|
2018-12-11 17:24:24 +03:00
|
|
|
|
2021-09-06 12:12:28 +03:00
|
|
|
if (context->instance)
|
2018-12-11 17:24:24 +03:00
|
|
|
{
|
2021-09-06 12:12:28 +03:00
|
|
|
rc = IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance,
|
|
|
|
GATEWAY_MESSAGE_SERVICE,
|
2018-12-11 17:24:24 +03:00
|
|
|
packetStringMessage.isDisplayMandatory != 0,
|
|
|
|
packetStringMessage.isConsentMandatory != 0,
|
2019-11-06 17:24:51 +03:00
|
|
|
packetStringMessage.msgBytes, packetStringMessage.msgBuffer);
|
2022-04-28 11:49:42 +03:00
|
|
|
if (!rc)
|
|
|
|
goto fail;
|
2018-12-11 17:24:24 +03:00
|
|
|
}
|
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
|
|
|
case TSG_ASYNC_MESSAGE_REAUTH:
|
2023-10-25 11:38:48 +03:00
|
|
|
{
|
|
|
|
UINT32 ReauthMessagePtr = 0;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, 20))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &ReauthMessagePtr, TRUE))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Seek_UINT32(pdu->s); /* alignment pad (4 bytes) */
|
|
|
|
Stream_Read_UINT64(pdu->s,
|
|
|
|
packetReauthMessage.tunnelContext); /* TunnelContext (8 bytes) */
|
|
|
|
Stream_Seek_UINT32(pdu->s); /* ReturnValue (4 bytes) */
|
2018-12-11 17:24:24 +03:00
|
|
|
tsg->ReauthTunnelContext = packetReauthMessage.tunnelContext;
|
2023-10-25 11:38:48 +03:00
|
|
|
}
|
|
|
|
break;
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
default:
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "unexpected message type: %" PRIu32 "", SwitchValue);
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2013-02-02 02:52:19 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
|
|
|
return rc;
|
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
|
|
|
{
|
2024-04-12 11:42:10 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(tunnelContext);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyCreateChannelWriteRequest");
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2024-04-12 11:42:10 +03:00
|
|
|
if (!tsg->rpc || !tsg->Hostname)
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2024-04-12 11:42:10 +03:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
|
|
|
const size_t count = _wcslen(tsg->Hostname) + 1;
|
2021-10-15 12:45:08 +03:00
|
|
|
if (count > UINT32_MAX)
|
|
|
|
return FALSE;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2024-04-12 11:42:10 +03:00
|
|
|
wStream* s = Stream_New(NULL, 60 + count * 2);
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!s)
|
2014-05-21 19:32:14 +04:00
|
|
|
return FALSE;
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyWriteTunnelContext(tsg->log, s, tunnelContext))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
|
|
|
|
2012-10-31 20:34:52 +04:00
|
|
|
/* TSENDPOINTINFO */
|
2023-10-25 11:38:48 +03:00
|
|
|
UINT32 index = 0;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
Stream_Write_UINT32(s, 0x00000001); /* NumResourceNames (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 0))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 0x0000); /* NumAlternateResourceNames (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 0x0000); /* Pad (2 bytes) */
|
2012-12-21 21:17:07 +04:00
|
|
|
/* Port (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 0x0003); /* ProtocolId (RDP = 3) (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tsg->Port); /* PortNumber (0xD3D = 3389) (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x00000001); /* NumResourceNames (4 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!tsg_ndr_write_string(tsg->log, s, tsg->Hostname, count))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
return rpc_client_write_call(rpc, s, TsProxyCreateChannelOpnum);
|
2023-10-25 11:38:48 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
2012-11-09 11:31:22 +04:00
|
|
|
}
|
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
static BOOL TsProxyCreateChannelReadResponse(wLog* log, const RPC_PDU* pdu,
|
2023-10-25 14:48:36 +03:00
|
|
|
CONTEXT_HANDLE* channelContext, UINT32* channelId)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL rc = FALSE;
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2024-04-12 11:25:35 +03:00
|
|
|
WINPR_ASSERT(log);
|
|
|
|
WINPR_ASSERT(pdu);
|
|
|
|
WINPR_ASSERT(channelId);
|
|
|
|
|
|
|
|
WLog_Print(log, WLOG_DEBUG, "TsProxyCreateChannelReadResponse");
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 28))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2012-12-08 02:41:12 +04:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyReadTunnelContext(log, pdu->s, channelContext))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, pdu->s, 2, sizeof(UINT32)))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(pdu->s, *channelId); /* ChannelId (4 bytes) */
|
|
|
|
Stream_Seek_UINT32(pdu->s); /* ReturnValue (4 bytes) */
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
|
|
|
return rc;
|
2012-11-09 11:31:22 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2024-04-12 11:25:35 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyCloseChannelWriteRequest");
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2024-04-12 11:25:35 +03:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
|
|
|
WINPR_ASSERT(rpc);
|
2015-08-28 11:59:48 +03:00
|
|
|
|
2024-04-12 11:25:35 +03:00
|
|
|
wStream* s = Stream_New(NULL, 20);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!s)
|
2015-01-13 21:50:46 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyWriteTunnelContext(tsg->log, s, context))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
return rpc_client_write_call(rpc, s, TsProxyCloseChannelOpnum);
|
2023-10-25 11:38:48 +03:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
2012-11-09 23:35:21 +04:00
|
|
|
}
|
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
static BOOL TsProxyCloseChannelReadResponse(wLog* log, const RPC_PDU* pdu, CONTEXT_HANDLE* context)
|
2012-11-09 23:35:21 +04:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL rc = FALSE;
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(log, WLOG_DEBUG, "TsProxyCloseChannelReadResponse");
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2012-12-13 21:40:46 +04:00
|
|
|
if (!pdu)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 24))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2012-12-13 21:40:46 +04:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyReadTunnelContext(log, pdu->s, context))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2023-10-25 14:48:36 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
const size_t len = sizeof(UINT32);
|
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, len))
|
|
|
|
goto fail;
|
|
|
|
Stream_Seek(pdu->s, len); /* ReturnValue (4 bytes) */
|
|
|
|
rc = TRUE;
|
|
|
|
}
|
2018-09-28 09:43:43 +03:00
|
|
|
fail:
|
|
|
|
return rc;
|
2012-12-13 21:40:46 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/**
|
|
|
|
* HRESULT TsProxyCloseTunnel(
|
|
|
|
* [in, out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* context
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
static BOOL TsProxyCloseTunnelWriteRequest(rdpTsg* tsg, const CONTEXT_HANDLE* context)
|
2012-12-13 21:40:46 +04:00
|
|
|
{
|
2024-04-12 11:35:50 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyCloseTunnelWriteRequest");
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2024-04-12 11:35:50 +03:00
|
|
|
rdpRpc* rpc = tsg->rpc;
|
|
|
|
WINPR_ASSERT(rpc);
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2024-04-12 11:35:50 +03:00
|
|
|
wStream* s = Stream_New(NULL, 20);
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!s)
|
2012-12-13 21:40:46 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyWriteTunnelContext(tsg->log, s, context))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
return rpc_client_write_call(rpc, s, TsProxyCloseTunnelOpnum);
|
2023-10-25 11:38:48 +03:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
2012-12-13 21:40:46 +04:00
|
|
|
}
|
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
static BOOL TsProxyCloseTunnelReadResponse(wLog* log, const RPC_PDU* pdu, CONTEXT_HANDLE* context)
|
2012-12-13 21:40:46 +04:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL rc = FALSE;
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2024-04-12 11:35:50 +03:00
|
|
|
WINPR_ASSERT(log);
|
|
|
|
WINPR_ASSERT(pdu);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
WLog_Print(log, WLOG_DEBUG, "TsProxyCloseTunnelReadResponse");
|
2012-12-13 21:40:46 +04:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 24))
|
2018-09-28 09:43:43 +03:00
|
|
|
goto fail;
|
2012-12-13 21:40:46 +04:00
|
|
|
|
2015-02-18 00:15:57 +03:00
|
|
|
/* TunnelContext (20 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyReadTunnelContext(log, pdu->s, context))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2023-10-25 14:48:36 +03:00
|
|
|
{
|
|
|
|
const size_t len = sizeof(UINT32);
|
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, len))
|
|
|
|
goto fail;
|
|
|
|
Stream_Seek(pdu->s, len); /* ReturnValue (4 bytes) */
|
|
|
|
rc = TRUE;
|
|
|
|
}
|
2018-09-28 09:43:43 +03:00
|
|
|
fail:
|
|
|
|
return rc;
|
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[]
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
static BOOL TsProxySetupReceivePipeWriteRequest(rdpTsg* tsg, const CONTEXT_HANDLE* channelContext)
|
2012-11-09 11:31:22 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
|
|
|
rdpRpc* rpc = NULL;
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "TsProxySetupReceivePipeWriteRequest");
|
2015-01-13 21:50:46 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(tsg->rpc);
|
|
|
|
|
|
|
|
if (!channelContext)
|
2015-01-13 21:50:46 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rpc = tsg->rpc;
|
|
|
|
s = Stream_New(NULL, 20);
|
2015-02-17 22:34:42 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!s)
|
2012-10-30 04:54:49 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
/* ChannelContext (20 bytes) */
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyWriteTunnelContext(tsg->log, s, channelContext))
|
2023-10-25 11:38:48 +03:00
|
|
|
goto fail;
|
2018-09-28 09:43:43 +03:00
|
|
|
return rpc_client_write_call(rpc, s, TsProxySetupReceivePipeOpnum);
|
2023-10-25 11:38:48 +03:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
2012-11-09 11:31:22 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
static BOOL tsg_transition_to_state(rdpTsg* tsg, TSG_STATE state)
|
2015-02-03 02:50:26 +03:00
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
2020-06-17 09:41:21 +03:00
|
|
|
const char* oldState = tsg_state_to_string(tsg->state);
|
|
|
|
const char* newState = tsg_state_to_string(state);
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_DEBUG, "%s -> %s", oldState, newState);
|
2018-09-28 09:43:43 +03:00
|
|
|
return tsg_set_state(tsg, state);
|
2015-02-03 02:50:26 +03:00
|
|
|
}
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
static BOOL tsg_initialize_version_caps(TSG_PACKET_VERSIONCAPS* packetVersionCaps)
|
2015-02-16 23:35:51 +03:00
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(packetVersionCaps);
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2015-02-16 23:35:51 +03:00
|
|
|
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;
|
2023-10-25 11:38:48 +03:00
|
|
|
packetVersionCaps->tsgCaps.capabilityType = TSG_CAPABILITY_TYPE_NAP;
|
2015-02-16 23:35:51 +03:00
|
|
|
/*
|
|
|
|
* 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
|
2019-11-06 17:24:51 +03:00
|
|
|
* "Only allow connections from Remote Desktop Services clients that support RD Gateway
|
|
|
|
* messaging"
|
2015-02-16 23:35:51 +03:00
|
|
|
*/
|
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
packetVersionCaps->tsgCaps.tsgPacket.tsgCapNap.capabilities =
|
|
|
|
TSG_NAP_CAPABILITY_QUAR_SOH | TSG_NAP_CAPABILITY_IDLE_TIMEOUT |
|
|
|
|
TSG_MESSAGING_CAP_CONSENT_SIGN | TSG_MESSAGING_CAP_SERVICE_MSG | TSG_MESSAGING_CAP_REAUTH;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL tsg_proxy_begin(rdpTsg* tsg)
|
|
|
|
{
|
|
|
|
TSG_PACKET tsgPacket = { 0 };
|
|
|
|
|
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
|
|
|
|
tsgPacket.packetId = TSG_PACKET_TYPE_VERSIONCAPS;
|
|
|
|
if (!tsg_initialize_version_caps(&tsgPacket.tsgPacket.packetVersionCaps) ||
|
|
|
|
!TsProxyCreateTunnelWriteRequest(tsg, &tsgPacket))
|
2015-02-16 23:35:51 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateTunnel failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_FINAL);
|
|
|
|
return FALSE;
|
2015-02-16 23:35:51 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
return tsg_transition_to_state(tsg, TSG_STATE_INITIAL);
|
2015-02-16 23:35:51 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
static BOOL tsg_proxy_reauth(rdpTsg* tsg)
|
2015-02-16 23:35:51 +03:00
|
|
|
{
|
2020-06-17 09:41:21 +03:00
|
|
|
TSG_PACKET tsgPacket = { 0 };
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2015-02-17 22:34:42 +03:00
|
|
|
tsg->reauthSequence = TRUE;
|
2023-10-25 11:38:48 +03:00
|
|
|
TSG_PACKET_REAUTH* packetReauth = &tsgPacket.tsgPacket.packetReauth;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2015-02-16 23:35:51 +03:00
|
|
|
tsgPacket.packetId = TSG_PACKET_TYPE_REAUTH;
|
|
|
|
packetReauth->tunnelContext = tsg->ReauthTunnelContext;
|
|
|
|
packetReauth->packetId = TSG_PACKET_TYPE_VERSIONCAPS;
|
2023-10-25 11:38:48 +03:00
|
|
|
|
|
|
|
if (!tsg_initialize_version_caps(&packetReauth->tsgInitialPacket.packetVersionCaps))
|
|
|
|
return FALSE;
|
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
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateTunnel failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_FINAL);
|
|
|
|
return FALSE;
|
2015-02-16 23:35:51 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!TsProxyMakeTunnelCallWriteRequest(tsg, &tsg->TunnelContext,
|
|
|
|
TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST))
|
2015-02-17 22:34:42 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCall failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
tsg_transition_to_state(tsg, TSG_STATE_FINAL);
|
|
|
|
return FALSE;
|
2015-02-17 22:34:42 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
return tsg_transition_to_state(tsg, TSG_STATE_INITIAL);
|
2015-02-16 23:35:51 +03:00
|
|
|
}
|
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
BOOL tsg_recv_pdu(rdpTsg* tsg, const RPC_PDU* pdu)
|
2012-10-30 04:54:49 +04:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL rc = FALSE;
|
2024-01-23 18:49:54 +03:00
|
|
|
RpcClientCall* call = NULL;
|
|
|
|
rdpRpc* rpc = NULL;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
WINPR_ASSERT(pdu);
|
|
|
|
WINPR_ASSERT(tsg->rpc);
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
rpc = tsg->rpc;
|
|
|
|
|
|
|
|
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
const size_t len = 24;
|
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, len))
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2023-10-25 14:48:36 +03:00
|
|
|
Stream_Seek(pdu->s, len);
|
2018-09-28 09:43:43 +03:00
|
|
|
}
|
2014-12-11 19:25:34 +03:00
|
|
|
|
2015-02-02 01:55:24 +03:00
|
|
|
switch (tsg->state)
|
|
|
|
{
|
|
|
|
case TSG_STATE_INITIAL:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
CONTEXT_HANDLE* TunnelContext = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
TunnelContext = (tsg->reauthSequence) ? &tsg->NewTunnelContext : &tsg->TunnelContext;
|
2012-11-15 07:34:45 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!TsProxyCreateTunnelReadResponse(tsg, pdu, TunnelContext, &tsg->TunnelId))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateTunnelReadResponse failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!tsg_transition_to_state(tsg, TSG_STATE_CONNECTED))
|
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!TsProxyAuthorizeTunnelWriteRequest(tsg, TunnelContext))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyAuthorizeTunnel failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
rc = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case TSG_STATE_CONNECTED:
|
|
|
|
{
|
2024-04-12 11:42:10 +03:00
|
|
|
CONTEXT_HANDLE* TunnelContext =
|
|
|
|
(tsg->reauthSequence) ? &tsg->NewTunnelContext : &tsg->TunnelContext;
|
2013-03-13 23:43:44 +04:00
|
|
|
|
2024-03-06 17:08:25 +03:00
|
|
|
if (!TsProxyAuthorizeTunnelReadResponse(tsg, pdu))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyAuthorizeTunnelReadResponse failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-13 23:43:44 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!tsg_transition_to_state(tsg, TSG_STATE_AUTHORIZED))
|
|
|
|
return FALSE;
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!tsg->reauthSequence)
|
|
|
|
{
|
|
|
|
if (!TsProxyMakeTunnelCallWriteRequest(tsg, TunnelContext,
|
|
|
|
TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST))
|
2015-02-18 00:36:01 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCall failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
2015-02-18 00:36:01 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!TsProxyCreateChannelWriteRequest(tsg, TunnelContext))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateChannel failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
|
|
|
rc = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2015-02-02 16:19:07 +03:00
|
|
|
case TSG_STATE_AUTHORIZED:
|
2018-09-27 17:23:01 +03:00
|
|
|
call = rpc_client_call_find_by_id(rpc->client, pdu->CallId);
|
2012-10-30 04:54:49 +04:00
|
|
|
|
2015-02-16 02:22:49 +03:00
|
|
|
if (!call)
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-16 02:22:49 +03:00
|
|
|
|
2015-02-02 01:55:24 +03:00
|
|
|
if (call->OpNum == TsProxyMakeTunnelCallOpnum)
|
|
|
|
{
|
|
|
|
if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCallReadResponse failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-02 01:55:24 +03:00
|
|
|
}
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = TRUE;
|
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;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyCreateChannelReadResponse(tsg->log, pdu, &ChannelContext,
|
|
|
|
&tsg->ChannelId))
|
2015-02-02 16:19:07 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateChannelReadResponse failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
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));
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CREATED))
|
|
|
|
return FALSE;
|
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
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxySetupReceivePipe failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-17 22:34:42 +03:00
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
2015-02-18 00:36:01 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!TsProxyCloseChannelWriteRequest(tsg, &tsg->NewChannelContext))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelWriteRequest failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!TsProxyCloseTunnelWriteRequest(tsg, &tsg->NewTunnelContext))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseTunnelWriteRequest failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
|
|
|
}
|
2013-03-14 20:57:45 +04:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = tsg_transition_to_state(tsg, TSG_STATE_PIPE_CREATED);
|
2015-02-17 22:34:42 +03:00
|
|
|
tsg->reauthSequence = FALSE;
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
|
|
|
else
|
2015-02-02 01:55:24 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR,
|
|
|
|
"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:
|
2018-09-27 17:23:01 +03:00
|
|
|
call = rpc_client_call_find_by_id(rpc->client, pdu->CallId);
|
2015-02-16 02:22:49 +03:00
|
|
|
|
|
|
|
if (!call)
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-16 02:22:49 +03:00
|
|
|
|
|
|
|
if (call->OpNum == TsProxyMakeTunnelCallOpnum)
|
|
|
|
{
|
|
|
|
if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCallReadResponse failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-16 02:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = TRUE;
|
2015-02-16 23:35:51 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (tsg->ReauthTunnelContext)
|
|
|
|
rc = tsg_proxy_reauth(tsg);
|
2015-02-16 02:22:49 +03:00
|
|
|
}
|
2015-02-18 00:36:01 +03:00
|
|
|
else if (call->OpNum == TsProxyCloseChannelOpnum)
|
|
|
|
{
|
|
|
|
CONTEXT_HANDLE ChannelContext;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyCloseChannelReadResponse(tsg->log, pdu, &ChannelContext))
|
2015-02-18 00:36:01 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelReadResponse failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = TRUE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
|
|
|
else if (call->OpNum == TsProxyCloseTunnelOpnum)
|
|
|
|
{
|
|
|
|
CONTEXT_HANDLE TunnelContext;
|
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyCloseTunnelReadResponse(tsg->log, pdu, &TunnelContext))
|
2015-02-18 00:36:01 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseTunnelReadResponse failure");
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
rc = TRUE;
|
2015-02-18 00:36:01 +03:00
|
|
|
}
|
|
|
|
|
2015-02-02 01:55:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_TUNNEL_CLOSE_PENDING:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
CONTEXT_HANDLE ChannelContext;
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyCloseChannelReadResponse(tsg->log, pdu, &ChannelContext))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelReadResponse failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CLOSE_PENDING))
|
|
|
|
return FALSE;
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!TsProxyCloseChannelWriteRequest(tsg, NULL))
|
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelWriteRequest failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:15:57 +03:00
|
|
|
}
|
2015-02-02 01:55:24 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!TsProxyMakeTunnelCallWriteRequest(tsg, &tsg->TunnelContext,
|
|
|
|
TSG_TUNNEL_CANCEL_ASYNC_MSG_REQUEST))
|
2015-02-02 16:19:07 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCall failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-02 16:19:07 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
rc = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSG_STATE_CHANNEL_CLOSE_PENDING:
|
|
|
|
{
|
|
|
|
CONTEXT_HANDLE TunnelContext;
|
2015-02-03 02:50:26 +03:00
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
if (!TsProxyCloseTunnelReadResponse(tsg->log, pdu, &TunnelContext))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseTunnelReadResponse failure");
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
2015-02-18 00:15:57 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
|
|
|
rc = tsg_transition_to_state(tsg, TSG_STATE_FINAL);
|
|
|
|
}
|
|
|
|
break;
|
2015-02-02 01:55:24 +03:00
|
|
|
|
|
|
|
case TSG_STATE_FINAL:
|
|
|
|
break;
|
2013-03-13 23:43:44 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
return rc;
|
2015-02-02 01:55:24 +03:00
|
|
|
}
|
2012-11-15 07:34:45 +04:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
BOOL tsg_check_event_handles(rdpTsg* tsg)
|
2015-02-02 19:50:56 +03:00
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
2018-10-18 11:15:51 +03:00
|
|
|
if (rpc_client_in_channel_recv(tsg->rpc) < 0)
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-04 01:17:17 +03:00
|
|
|
|
2018-10-18 11:15:51 +03:00
|
|
|
if (rpc_client_out_channel_recv(tsg->rpc) < 0)
|
2018-09-28 09:43:43 +03:00
|
|
|
return FALSE;
|
2015-02-02 19:50:56 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
return TRUE;
|
2015-02-02 19:50:56 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-09-27 17:05:14 +03:00
|
|
|
if (connection->DefaultInChannel && connection->DefaultInChannel->common.tls)
|
2015-02-15 18:06:17 +03:00
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2018-09-27 17:05:14 +03:00
|
|
|
BIO_get_event(connection->DefaultInChannel->common.tls->bio, &events[nCount]);
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 17:05:14 +03:00
|
|
|
if (connection->NonDefaultInChannel && connection->NonDefaultInChannel->common.tls)
|
2015-02-15 18:06:17 +03:00
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2018-09-27 17:05:14 +03:00
|
|
|
BIO_get_event(connection->NonDefaultInChannel->common.tls->bio, &events[nCount]);
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 17:05:14 +03:00
|
|
|
if (connection->DefaultOutChannel && connection->DefaultOutChannel->common.tls)
|
2015-02-15 18:06:17 +03:00
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2018-09-27 17:05:14 +03:00
|
|
|
BIO_get_event(connection->DefaultOutChannel->common.tls->bio, &events[nCount]);
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 17:05:14 +03:00
|
|
|
if (connection->NonDefaultOutChannel && connection->NonDefaultOutChannel->common.tls)
|
2015-02-15 18:06:17 +03:00
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
if (events && (nCount < count))
|
|
|
|
{
|
2018-09-27 17:05:14 +03:00
|
|
|
BIO_get_event(connection->NonDefaultOutChannel->common.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
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
2015-02-12 22:40:26 +03:00
|
|
|
free(tsg->Hostname);
|
2022-10-28 09:09:27 +03:00
|
|
|
tsg->Hostname = ConvertUtf8ToWCharAlloc(hostname, NULL);
|
|
|
|
return tsg->Hostname != NULL;
|
2015-02-12 22:40:26 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2023-10-25 11:38:48 +03:00
|
|
|
WINPR_ASSERT(tsg);
|
2015-02-12 22:40:26 +03:00
|
|
|
free(tsg->MachineName);
|
2022-10-28 09:09:27 +03:00
|
|
|
tsg->MachineName = ConvertUtf8ToWCharAlloc(machineName, NULL);
|
|
|
|
return tsg->MachineName != NULL;
|
2015-02-12 22:40:26 +03:00
|
|
|
}
|
|
|
|
|
2020-06-17 09:41:21 +03:00
|
|
|
BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, DWORD timeout)
|
2015-02-02 01:55:24 +03:00
|
|
|
{
|
2020-06-17 09:41:21 +03:00
|
|
|
UINT64 looptimeout = timeout * 1000ULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
DWORD nCount = 0;
|
2021-08-25 12:14:35 +03:00
|
|
|
HANDLE events[MAXIMUM_WAIT_OBJECTS] = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRpc* rpc = NULL;
|
|
|
|
rdpContext* context = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpTransport* transport = NULL;
|
2021-09-06 12:12:28 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(tsg);
|
|
|
|
|
|
|
|
rpc = tsg->rpc;
|
|
|
|
WINPR_ASSERT(rpc);
|
|
|
|
|
|
|
|
transport = rpc->transport;
|
|
|
|
context = transport_get_context(transport);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
settings = context->settings;
|
|
|
|
|
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;
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!tsg_set_hostname(tsg, hostname))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!tsg_set_machine_name(tsg, settings->ComputerName))
|
|
|
|
return FALSE;
|
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
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "rpc_connect error!");
|
2015-02-03 01:16:32 +03:00
|
|
|
return FALSE;
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
|
|
|
|
2021-08-25 12:14:35 +03:00
|
|
|
nCount = tsg_get_event_handles(tsg, events, ARRAYSIZE(events));
|
2015-04-21 13:24:50 +03:00
|
|
|
|
|
|
|
if (nCount == 0)
|
|
|
|
return FALSE;
|
2015-02-02 01:55:24 +03:00
|
|
|
|
|
|
|
while (tsg->state != TSG_STATE_PIPE_CREATED)
|
|
|
|
{
|
2020-06-17 09:41:21 +03:00
|
|
|
const DWORD polltimeout = 250;
|
|
|
|
DWORD status = WaitForMultipleObjects(nCount, events, FALSE, polltimeout);
|
|
|
|
if (status == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
if (timeout > 0)
|
|
|
|
{
|
|
|
|
if (looptimeout < polltimeout)
|
|
|
|
return FALSE;
|
|
|
|
looptimeout -= polltimeout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
looptimeout = timeout * 1000ULL;
|
2015-02-04 01:17:17 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!tsg_check_event_handles(tsg))
|
2015-02-02 19:50:56 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "tsg_check failure");
|
2021-09-06 12:01:36 +03:00
|
|
|
transport_set_layer(transport, 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
|
|
|
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_INFO, "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;
|
|
|
|
|
2019-11-06 17:24:51 +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
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
return tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CLOSE_PENDING);
|
2015-02-02 16:19:07 +03:00
|
|
|
}
|
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
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* @brief Read data from TSG
|
|
|
|
*
|
|
|
|
* @param[in] tsg The TSG instance to read from
|
|
|
|
* @param[in] data A pointer to the data buffer
|
|
|
|
* @param[in] length length of data
|
2014-11-26 00:55:39 +03:00
|
|
|
*
|
|
|
|
* @return < 0 on error; 0 if not enough data is available (non blocking mode); > 0 bytes to read
|
|
|
|
*/
|
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
static int tsg_read(rdpTsg* tsg, BYTE* data, size_t length)
|
2012-04-24 00:33:18 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRpc* rpc = NULL;
|
2015-02-01 21:09:28 +03:00
|
|
|
int status = 0;
|
2013-07-04 22:42:40 +04:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!tsg || !data)
|
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
|
|
|
|
2021-09-06 12:01:36 +03:00
|
|
|
if (transport_get_layer(rpc->transport) == TRANSPORT_LAYER_CLOSED)
|
2013-12-21 03:22:29 +04:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "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
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
status = rpc_client_receive_pipe_read(rpc->client, data, 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
|
|
|
|
2021-09-06 12:01:36 +03:00
|
|
|
if (!status && !transport_get_blocking(rpc->transport))
|
2014-05-21 19:32:14 +04:00
|
|
|
return 0;
|
2012-11-15 04:51:45 +04:00
|
|
|
|
2021-09-06 12:01:36 +03:00
|
|
|
if (transport_get_layer(rpc->transport) == TRANSPORT_LAYER_CLOSED)
|
2014-11-25 23:25:26 +03:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "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
|
|
|
|
2021-09-06 12:01:36 +03:00
|
|
|
if (transport_get_blocking(rpc->transport))
|
2015-02-02 19:50:56 +03:00
|
|
|
{
|
|
|
|
while (WaitForSingleObject(rpc->client->PipeEvent, 0) != WAIT_OBJECT_0)
|
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!tsg_check_event_handles(tsg))
|
2015-02-02 19:50:56 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
WaitForSingleObject(rpc->client->PipeEvent, 100);
|
|
|
|
}
|
|
|
|
}
|
2021-09-06 12:01:36 +03:00
|
|
|
} while (transport_get_blocking(rpc->transport));
|
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
|
|
|
}
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
static int tsg_write(rdpTsg* tsg, const BYTE* data, UINT32 length)
|
2012-03-26 10:45:01 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int status = 0;
|
2014-05-21 19:32:14 +04:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
if (!tsg || !data || !tsg->rpc || !tsg->rpc->transport)
|
|
|
|
return -1;
|
|
|
|
|
2021-09-06 12:01:36 +03:00
|
|
|
if (transport_get_layer(tsg->rpc->transport) == TRANSPORT_LAYER_CLOSED)
|
2013-12-21 03:24:29 +04:00
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
WLog_Print(tsg->log, WLOG_ERROR, "error, connection lost");
|
2013-12-21 03:24:29 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03: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
|
|
|
|
2021-10-15 12:45:08 +03:00
|
|
|
return (int)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
|
|
|
{
|
2023-10-25 14:48:36 +03:00
|
|
|
rdpTsg* 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;
|
2023-10-25 14:48:36 +03:00
|
|
|
tsg->log = WLog_Get(TAG);
|
2014-05-21 19:32:14 +04:00
|
|
|
tsg->transport = transport;
|
|
|
|
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
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
rpc_free(tsg->rpc);
|
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)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int status = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpTsg* tsg = (rdpTsg*)BIO_get_data(bio);
|
2015-01-28 22:54:03 +03:00
|
|
|
BIO_clear_flags(bio, BIO_FLAGS_WRITE);
|
2021-10-15 12:45:08 +03:00
|
|
|
|
|
|
|
if (num < 0)
|
|
|
|
return -1;
|
|
|
|
status = tsg_write(tsg, (const BYTE*)buf, (UINT32)num);
|
2015-01-28 22:54:03 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int status = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpTsg* tsg = (rdpTsg*)BIO_get_data(bio);
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
if (!tsg || (size < 0))
|
|
|
|
{
|
|
|
|
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-28 22:54:03 +03:00
|
|
|
BIO_clear_flags(bio, BIO_FLAGS_READ);
|
2021-10-15 12:45:08 +03:00
|
|
|
status = tsg_read(tsg, (BYTE*)buf, (size_t)size);
|
2015-01-28 22:54:03 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
WINPR_UNUSED(bio);
|
|
|
|
WINPR_UNUSED(str);
|
2015-01-28 22:54:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int transport_bio_tsg_gets(BIO* bio, char* str, int size)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
WINPR_UNUSED(bio);
|
|
|
|
WINPR_UNUSED(str);
|
|
|
|
WINPR_UNUSED(size);
|
2015-01-28 22:54:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long transport_bio_tsg_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
long status = -1;
|
2019-11-06 17:24:51 +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;
|
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
switch (cmd)
|
2015-02-15 18:06:17 +03:00
|
|
|
{
|
2018-09-28 09:43:43 +03:00
|
|
|
case BIO_CTRL_FLUSH:
|
|
|
|
(void)BIO_flush(inChannel->common.tls->bio);
|
|
|
|
(void)BIO_flush(outChannel->common.tls->bio);
|
2015-02-15 18:06:17 +03:00
|
|
|
status = 1;
|
2018-09-28 09:43:43 +03:00
|
|
|
break;
|
2015-02-15 18:06:17 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
case BIO_C_GET_EVENT:
|
|
|
|
if (arg2)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
*((HANDLE*)arg2) = tsg->rpc->client->PipeEvent;
|
2018-09-28 09:43:43 +03:00
|
|
|
status = 1;
|
|
|
|
}
|
2015-01-28 22:54:03 +03:00
|
|
|
|
2018-09-28 09:43:43 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_C_SET_NONBLOCK:
|
2015-02-15 18:06:17 +03:00
|
|
|
status = 1;
|
2018-09-28 09:43:43 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_C_READ_BLOCKED:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2021-07-29 11:07:04 +03:00
|
|
|
BIO* cbio = outChannel->common.bio;
|
|
|
|
status = BIO_read_blocked(cbio);
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
case BIO_C_WRITE_BLOCKED:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2021-07-29 11:07:04 +03:00
|
|
|
BIO* cbio = inChannel->common.bio;
|
|
|
|
status = BIO_write_blocked(cbio);
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
case BIO_C_WAIT_READ:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
int timeout = (int)arg1;
|
2021-07-29 11:07:04 +03:00
|
|
|
BIO* cbio = outChannel->common.bio;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2021-07-29 11:07:04 +03:00
|
|
|
if (BIO_read_blocked(cbio))
|
|
|
|
return BIO_wait_read(cbio, timeout);
|
|
|
|
else if (BIO_write_blocked(cbio))
|
|
|
|
return BIO_wait_write(cbio, timeout);
|
2019-11-06 17:24:51 +03:00
|
|
|
else
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
break;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
case BIO_C_WAIT_WRITE:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
int timeout = (int)arg1;
|
2021-07-29 11:07:04 +03:00
|
|
|
BIO* cbio = inChannel->common.bio;
|
2018-09-28 09:43:43 +03:00
|
|
|
|
2021-07-29 11:07:04 +03:00
|
|
|
if (BIO_write_blocked(cbio))
|
|
|
|
status = BIO_wait_write(cbio, timeout);
|
|
|
|
else if (BIO_read_blocked(cbio))
|
|
|
|
status = BIO_wait_read(cbio, timeout);
|
2019-11-06 17:24:51 +03:00
|
|
|
else
|
|
|
|
status = 1;
|
|
|
|
}
|
|
|
|
break;
|
2022-04-24 22:16:52 +03:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
|
|
|
case BIO_CTRL_GET_KTLS_SEND:
|
|
|
|
status = 0;
|
|
|
|
break;
|
|
|
|
case BIO_CTRL_GET_KTLS_RECV:
|
|
|
|
status = 0;
|
|
|
|
break;
|
|
|
|
#endif
|
2018-09-28 09:43:43 +03:00
|
|
|
default:
|
|
|
|
break;
|
2015-02-15 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2015-01-28 22:54:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int transport_bio_tsg_new(BIO* bio)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
WINPR_ASSERT(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)
|
|
|
|
{
|
2021-10-15 12:45:08 +03:00
|
|
|
WINPR_ASSERT(bio);
|
|
|
|
WINPR_UNUSED(bio);
|
2015-01-28 22:54:03 +03:00
|
|
|
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
|
|
|
}
|
2018-09-28 09:43:43 +03:00
|
|
|
|
|
|
|
TSG_STATE tsg_get_state(rdpTsg* tsg)
|
|
|
|
{
|
|
|
|
if (!tsg)
|
|
|
|
return TSG_STATE_INITIAL;
|
|
|
|
|
|
|
|
return tsg->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
BIO* tsg_get_bio(rdpTsg* tsg)
|
|
|
|
{
|
|
|
|
if (!tsg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return tsg->bio;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL tsg_set_state(rdpTsg* tsg, TSG_STATE state)
|
|
|
|
{
|
|
|
|
if (!tsg)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
tsg->state = state;
|
|
|
|
return TRUE;
|
|
|
|
}
|