FreeRDP/libfreerdp/core/transport.c

1527 lines
34 KiB
C
Raw Normal View History

/**
2012-10-09 07:02:04 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
* Network Transport Layer
*
* Copyright 2011 Vic Lee
*
* 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>
2021-06-09 15:03:34 +03:00
#include <winpr/assert.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
2012-12-14 09:25:48 +04:00
#include <winpr/print.h>
#include <winpr/stream.h>
#include <winpr/winsock.h>
#include <winpr/crypto.h>
2014-08-19 20:26:39 +04:00
#include <freerdp/log.h>
2012-12-14 09:25:48 +04:00
#include <freerdp/error.h>
#include <freerdp/utils/ringbuffer.h>
#include <openssl/bio.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#ifndef _WIN32
2011-08-16 23:35:29 +04:00
#include <netdb.h>
#include <sys/socket.h>
#endif /* _WIN32 */
#ifdef HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/memcheck.h>
#endif
#include "tpkt.h"
#include "fastpath.h"
#include "transport.h"
#include "rdp.h"
2017-08-18 20:17:17 +03:00
#include "proxy.h"
#include "utils.h"
#include "state.h"
#define TAG FREERDP_TAG("core.transport")
#define BUFFER_SIZE 16384
2021-09-06 12:01:36 +03:00
struct rdp_transport
{
TRANSPORT_LAYER layer;
BIO* frontBio;
rdpRdg* rdg;
rdpTsg* tsg;
rdpTls* tls;
rdpContext* context;
rdpNla* nla;
void* ReceiveExtra;
wStream* ReceiveBuffer;
TransportRecv ReceiveCallback;
wStreamPool* ReceivePool;
HANDLE connectedEvent;
BOOL NlaMode;
BOOL blocking;
BOOL GatewayEnabled;
CRITICAL_SECTION ReadLock;
CRITICAL_SECTION WriteLock;
ULONG written;
HANDLE rereadEvent;
BOOL haveMoreBytesToRead;
wLog* log;
rdpTransportIo io;
HANDLE ioEvent;
BOOL useIoEvent;
2021-09-06 12:01:36 +03:00
};
static void transport_ssl_cb(SSL* ssl, int where, int ret)
{
if (where & SSL_CB_ALERT)
{
2019-11-06 17:24:51 +03:00
rdpTransport* transport = (rdpTransport*)SSL_get_app_data(ssl);
WINPR_ASSERT(transport);
2017-02-22 11:42:56 +03:00
switch (ret)
2016-06-20 12:49:54 +03:00
{
case (SSL3_AL_FATAL << 8) | SSL_AD_ACCESS_DENIED:
2019-11-06 17:24:51 +03:00
{
2021-09-06 12:01:36 +03:00
if (!freerdp_get_last_error(transport_get_context(transport)))
{
2019-11-06 17:24:51 +03:00
WLog_Print(transport->log, WLOG_ERROR, "%s: ACCESS DENIED", __FUNCTION__);
2021-09-06 12:01:36 +03:00
freerdp_set_last_error_log(transport_get_context(transport),
FREERDP_ERROR_AUTHENTICATION_FAILED);
}
2019-11-06 17:24:51 +03:00
}
break;
case (SSL3_AL_FATAL << 8) | SSL_AD_INTERNAL_ERROR:
2019-11-06 17:24:51 +03:00
{
if (transport->NlaMode)
{
2021-09-06 12:01:36 +03:00
if (!freerdp_get_last_error(transport_get_context(transport)))
2019-11-06 17:24:51 +03:00
{
2021-04-16 16:47:53 +03:00
UINT32 kret = nla_get_error(transport->nla);
if (kret == 0)
kret = FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED;
2021-09-06 12:01:36 +03:00
freerdp_set_last_error_log(transport_get_context(transport), kret);
2019-11-06 17:24:51 +03:00
}
}
2016-09-20 09:58:04 +03:00
2019-11-06 17:24:51 +03:00
break;
case (SSL3_AL_WARNING << 8) | SSL3_AD_CLOSE_NOTIFY:
break;
default:
2019-11-06 17:24:51 +03:00
WLog_Print(transport->log, WLOG_WARN,
"Unhandled SSL error (where=%d, ret=%d [%s, %s])", where, ret,
2017-02-22 11:42:56 +03:00
SSL_alert_type_string_long(ret), SSL_alert_desc_string_long(ret));
break;
2019-11-06 17:24:51 +03:00
}
2016-06-20 12:49:54 +03:00
}
}
}
wStream* transport_send_stream_init(rdpTransport* transport, size_t size)
{
wStream* s;
WINPR_ASSERT(transport);
if (!(s = StreamPool_Take(transport->ReceivePool, size)))
return NULL;
2016-09-20 09:58:04 +03:00
if (!Stream_EnsureCapacity(s, size))
{
Stream_Release(s);
return NULL;
}
2016-09-20 09:58:04 +03:00
Stream_SetPosition(s, 0);
return s;
}
BOOL transport_attach(rdpTransport* transport, int sockfd)
{
if (!transport)
return FALSE;
return IFCALLRESULT(FALSE, transport->io.TransportAttach, transport, sockfd);
}
static BOOL transport_default_attach(rdpTransport* transport, int sockfd)
{
2018-10-25 14:08:00 +03:00
BIO* socketBio = NULL;
BIO* bufferedBio;
const rdpSettings* settings;
rdpContext* context = transport_get_context(transport);
if (sockfd < 0)
{
WLog_WARN(TAG, "Running peer without socket (sockfd=%d)", sockfd);
return TRUE;
}
settings = context->settings;
WINPR_ASSERT(settings);
if (sockfd >= 0)
{
if (!freerdp_tcp_set_keep_alive_mode(settings, sockfd))
goto fail;
socketBio = BIO_new(BIO_s_simple_socket());
if (!socketBio)
goto fail;
BIO_set_fd(socketBio, sockfd, BIO_CLOSE);
}
bufferedBio = BIO_new(BIO_s_buffered_socket());
if (!bufferedBio)
2018-10-25 14:08:00 +03:00
goto fail;
if (socketBio)
bufferedBio = BIO_push(bufferedBio, socketBio);
WINPR_ASSERT(bufferedBio);
transport->frontBio = bufferedBio;
return TRUE;
2018-10-25 14:08:00 +03:00
fail:
if (socketBio)
BIO_free_all(socketBio);
else
2022-07-14 12:46:25 +03:00
closesocket(sockfd);
2018-10-25 14:08:00 +03:00
return FALSE;
}
BOOL transport_connect_rdp(rdpTransport* transport)
{
if (!transport)
return FALSE;
2021-09-06 12:01:36 +03:00
switch (utils_authenticate(transport_get_context(transport)->instance, AUTH_RDP, FALSE))
{
case AUTH_SKIP:
case AUTH_SUCCESS:
case AUTH_NO_CREDENTIALS:
return TRUE;
default:
return FALSE;
}
}
BOOL transport_connect_tls(rdpTransport* transport)
{
const rdpSettings* settings;
rdpContext* context = transport_get_context(transport);
settings = context->settings;
WINPR_ASSERT(settings);
/* Only prompt for password if we use TLS (NLA also calls this function) */
if (settings->SelectedProtocol == PROTOCOL_SSL)
{
2021-09-06 12:01:36 +03:00
switch (utils_authenticate(transport_get_context(transport)->instance, AUTH_TLS, FALSE))
{
case AUTH_SKIP:
case AUTH_SUCCESS:
case AUTH_NO_CREDENTIALS:
break;
default:
return FALSE;
}
}
return IFCALLRESULT(FALSE, transport->io.TLSConnect, transport);
}
static BOOL transport_default_connect_tls(rdpTransport* transport)
{
int tlsStatus;
rdpTls* tls = NULL;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(transport);
2021-09-06 12:01:36 +03:00
context = transport_get_context(transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
2015-05-05 20:45:34 +03:00
if (!(tls = tls_new(settings)))
return FALSE;
transport->tls = tls;
if (transport->GatewayEnabled)
2013-10-24 22:13:41 +04:00
transport->layer = TRANSPORT_LAYER_TSG_TLS;
else
transport->layer = TRANSPORT_LAYER_TLS;
tls->hostname = settings->ServerHostname;
tls->port = settings->ServerPort;
if (tls->port == 0)
tls->port = 3389;
tls->isGatewayTransport = FALSE;
tlsStatus = tls_connect(tls, transport->frontBio);
if (tlsStatus < 1)
{
if (tlsStatus < 0)
{
freerdp_set_last_error_if_not(context, FREERDP_ERROR_TLS_CONNECT_FAILED);
}
else
{
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED);
}
return FALSE;
}
2012-05-22 00:01:24 +04:00
transport->frontBio = tls->bio;
2019-11-06 17:24:51 +03:00
BIO_callback_ctrl(tls->bio, BIO_CTRL_SET_CALLBACK, (bio_info_cb*)(void*)transport_ssl_cb);
SSL_set_app_data(tls->ssl, transport);
if (!transport->frontBio)
{
2017-02-22 11:42:56 +03:00
WLog_Print(transport->log, WLOG_ERROR, "unable to prepend a filtering TLS bio");
return FALSE;
}
return TRUE;
}
BOOL transport_connect_nla(rdpTransport* transport)
{
rdpContext* context = NULL;
rdpSettings* settings = NULL;
rdpRdp* rdp = NULL;
if (!transport)
return FALSE;
2021-09-06 12:01:36 +03:00
context = transport_get_context(transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
rdp = context->rdp;
WINPR_ASSERT(rdp);
if (!transport_connect_tls(transport))
return FALSE;
2013-11-08 02:37:58 +04:00
if (!settings->Authentication)
return TRUE;
2020-05-12 10:09:13 +03:00
nla_free(rdp->nla);
rdp->nla = nla_new(context, transport);
2014-08-19 20:26:39 +04:00
2015-02-16 00:04:59 +03:00
if (!rdp->nla)
return FALSE;
2015-02-16 00:04:59 +03:00
transport_set_nla_mode(transport, TRUE);
2015-02-16 00:04:59 +03:00
if (settings->AuthenticationServiceClass)
{
if (!nla_set_service_principal(rdp->nla, settings->AuthenticationServiceClass,
freerdp_settings_get_server_name(settings)))
2015-02-16 00:04:59 +03:00
return FALSE;
2014-02-12 09:43:02 +04:00
}
2015-02-16 00:04:59 +03:00
if (nla_client_begin(rdp->nla) < 0)
{
2018-05-04 10:10:31 +03:00
WLog_Print(transport->log, WLOG_ERROR, "NLA begin failed");
freerdp_set_last_error_if_not(context, FREERDP_ERROR_AUTHENTICATION_FAILED);
transport_set_nla_mode(transport, FALSE);
return FALSE;
}
return rdp_client_transition_to_state(rdp, CONNECTION_STATE_NLA);
}
BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port, DWORD timeout)
{
int sockfd;
BOOL status = FALSE;
rdpSettings* settings;
rdpContext* context = transport_get_context(transport);
BOOL rpcFallback;
WINPR_ASSERT(context);
WINPR_ASSERT(hostname);
settings = context->settings;
WINPR_ASSERT(settings);
rpcFallback = !settings->GatewayHttpTransport;
if (transport->GatewayEnabled)
{
if (!status && settings->GatewayHttpTransport)
2015-03-17 21:54:16 +03:00
{
2018-10-24 16:42:44 +03:00
transport->rdg = rdg_new(context);
if (!transport->rdg)
return FALSE;
status = rdg_connect(transport->rdg, timeout, &rpcFallback);
if (status)
{
transport->frontBio = rdg_get_front_bio_and_take_ownership(transport->rdg);
WINPR_ASSERT(transport->frontBio);
BIO_set_nonblock(transport->frontBio, 0);
transport->layer = TRANSPORT_LAYER_TSG;
status = TRUE;
}
else
{
rdg_free(transport->rdg);
transport->rdg = NULL;
}
}
if (!status && settings->GatewayRpcTransport && rpcFallback)
{
transport->tsg = tsg_new(transport);
2015-03-17 21:54:16 +03:00
if (!transport->tsg)
return FALSE;
2015-03-17 21:54:16 +03:00
/* Reset error condition from RDG */
freerdp_set_last_error_log(context, FREERDP_ERROR_SUCCESS);
status = tsg_connect(transport->tsg, hostname, port, timeout);
2015-03-17 21:54:16 +03:00
if (status)
{
2018-09-28 09:43:43 +03:00
transport->frontBio = tsg_get_bio(transport->tsg);
transport->layer = TRANSPORT_LAYER_TSG;
status = TRUE;
}
else
{
tsg_free(transport->tsg);
transport->tsg = NULL;
}
}
}
else
{
2017-08-18 20:17:17 +03:00
UINT16 peerPort;
2019-11-06 17:24:51 +03:00
const char *proxyHostname, *proxyUsername, *proxyPassword;
BOOL isProxyConnection =
proxy_prepare(settings, &proxyHostname, &peerPort, &proxyUsername, &proxyPassword);
2017-08-18 20:17:17 +03:00
if (isProxyConnection)
2021-09-06 12:01:36 +03:00
sockfd = transport_tcp_connect(transport, proxyHostname, peerPort, timeout);
2017-08-18 20:17:17 +03:00
else
2021-09-06 12:01:36 +03:00
sockfd = transport_tcp_connect(transport, hostname, port, timeout);
if (sockfd < 0)
return FALSE;
if (!transport_attach(transport, sockfd))
return FALSE;
2017-08-18 20:17:17 +03:00
if (isProxyConnection)
{
2019-11-06 17:24:51 +03:00
if (!proxy_connect(settings, transport->frontBio, proxyUsername, proxyPassword,
hostname, port))
return FALSE;
}
2017-08-18 20:17:17 +03:00
status = TRUE;
}
return status;
}
BOOL transport_accept_rdp(rdpTransport* transport)
{
if (!transport)
return FALSE;
/* RDP encryption */
return TRUE;
}
BOOL transport_accept_tls(rdpTransport* transport)
{
if (!transport)
return FALSE;
return IFCALLRESULT(FALSE, transport->io.TLSAccept, transport);
}
static BOOL transport_default_accept_tls(rdpTransport* transport)
{
rdpContext* context = transport_get_context(transport);
rdpSettings* settings;
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!transport->tls)
transport->tls = tls_new(settings);
transport->layer = TRANSPORT_LAYER_TLS;
if (!tls_accept(transport->tls, transport->frontBio, settings))
return FALSE;
transport->frontBio = transport->tls->bio;
return TRUE;
}
BOOL transport_accept_nla(rdpTransport* transport)
{
rdpContext* context = transport_get_context(transport);
2020-09-18 09:47:56 +03:00
rdpSettings* settings;
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!IFCALLRESULT(FALSE, transport->io.TLSAccept, transport))
return FALSE;
/* Network Level Authentication */
2013-11-08 02:37:58 +04:00
if (!settings->Authentication)
return TRUE;
2015-02-15 19:10:14 +03:00
if (!transport->nla)
{
transport->nla = nla_new(context, transport);
transport_set_nla_mode(transport, TRUE);
}
2015-02-15 19:10:14 +03:00
if (nla_authenticate(transport->nla) < 0)
{
2017-02-22 11:42:56 +03:00
WLog_Print(transport->log, WLOG_ERROR, "client authentication failure");
transport_set_nla_mode(transport, FALSE);
2015-02-15 19:10:14 +03:00
nla_free(transport->nla);
transport->nla = NULL;
2016-09-20 09:58:04 +03:00
tls_set_alert_code(transport->tls, TLS_ALERT_LEVEL_FATAL,
TLS_ALERT_DESCRIPTION_ACCESS_DENIED);
tls_send_alert(transport->tls);
return FALSE;
}
2015-02-15 19:10:14 +03:00
/* don't free nla module yet, we need to copy the credentials from it first */
transport_set_nla_mode(transport, FALSE);
return TRUE;
}
2017-02-22 11:42:56 +03:00
#define WLog_ERR_BIO(transport, biofunc, bio) \
transport_bio_error_log(transport, biofunc, bio, __FILE__, __FUNCTION__, __LINE__)
2019-11-06 17:24:51 +03:00
static void transport_bio_error_log(rdpTransport* transport, LPCSTR biofunc, BIO* bio, LPCSTR file,
LPCSTR func, DWORD line)
{
unsigned long sslerr;
int saveerrno;
DWORD level;
WINPR_ASSERT(transport);
saveerrno = errno;
level = WLOG_ERROR;
2016-09-20 09:58:04 +03:00
2017-02-22 11:42:56 +03:00
if (level < WLog_GetLogLevel(transport->log))
return;
if (ERR_peek_error() == 0)
{
const char* fmt = "%s returned a system error %d: %s";
2017-02-22 11:42:56 +03:00
WLog_PrintMessage(transport->log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
saveerrno, strerror(saveerrno));
return;
}
2022-07-14 12:46:25 +03:00
while ((sslerr = ERR_get_error()))
{
char buf[120] = { 0 };
const char* fmt = "%s returned an error: %s";
2016-09-20 09:58:04 +03:00
2022-07-14 12:46:25 +03:00
ERR_error_string_n(sslerr, buf, 120);
WLog_PrintMessage(transport->log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
buf);
}
}
2019-11-20 13:30:14 +03:00
static SSIZE_T transport_read_layer(rdpTransport* transport, BYTE* data, size_t bytes)
{
2019-02-07 16:22:28 +03:00
SSIZE_T read = 0;
rdpRdp* rdp;
2021-09-06 12:01:36 +03:00
rdpContext* context;
WINPR_ASSERT(transport);
2021-09-06 12:01:36 +03:00
context = transport_get_context(transport);
WINPR_ASSERT(context);
rdp = context->rdp;
WINPR_ASSERT(rdp);
2012-12-13 08:52:23 +04:00
2019-02-07 16:22:28 +03:00
if (!transport->frontBio || (bytes > SSIZE_MAX))
{
transport->layer = TRANSPORT_LAYER_CLOSED;
2021-09-06 12:01:36 +03:00
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
return -1;
}
2019-02-07 16:22:28 +03:00
while (read < (SSIZE_T)bytes)
{
2019-02-07 16:22:28 +03:00
const SSIZE_T tr = (SSIZE_T)bytes - read;
int r = (int)((tr > INT_MAX) ? INT_MAX : tr);
ERR_clear_error();
2019-10-16 19:49:24 +03:00
int status = BIO_read(transport->frontBio, data + read, r);
2012-12-13 08:52:23 +04:00
if (freerdp_shall_disconnect_context(context))
return -1;
if (status <= 0)
{
2014-05-30 19:34:04 +04:00
if (!transport->frontBio || !BIO_should_retry(transport->frontBio))
{
/* something unexpected happened, let's close */
if (!transport->frontBio)
{
2017-02-22 11:42:56 +03:00
WLog_Print(transport->log, WLOG_ERROR, "BIO_read: transport->frontBio null");
return -1;
}
2016-09-20 09:58:04 +03:00
2017-02-22 11:42:56 +03:00
WLog_ERR_BIO(transport, "BIO_read", transport->frontBio);
transport->layer = TRANSPORT_LAYER_CLOSED;
2021-09-06 12:01:36 +03:00
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
return -1;
}
/* non blocking will survive a partial read */
if (!transport->blocking)
return read;
2019-11-06 17:24:51 +03:00
/* blocking means that we can't continue until we have read the number of requested
* bytes */
if (BIO_wait_read(transport->frontBio, 100) < 0)
{
2017-02-22 11:42:56 +03:00
WLog_ERR_BIO(transport, "BIO_wait_read", transport->frontBio);
return -1;
}
2014-08-19 20:26:39 +04:00
continue;
}
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(data + read, bytes - read);
#endif
read += status;
rdp->inBytes += status;
}
2012-12-13 08:52:23 +04:00
return read;
}
/**
* @brief Tries to read toRead bytes from the specified transport
*
* Try to read toRead bytes from the transport to the stream.
2019-11-06 17:24:51 +03:00
* In case it was not possible to read toRead bytes 0 is returned. The stream is always advanced by
* the number of bytes read.
*
2014-07-28 15:12:01 +04:00
* The function assumes that the stream has enough capacity to hold the data.
*
* @param[in] transport rdpTransport
* @param[in] s wStream
* @param[in] toRead number of bytes to read
2014-07-28 15:12:01 +04:00
* @return < 0 on error; 0 if not enough data is available (non blocking mode); 1 toRead bytes read
*/
2019-11-06 17:24:51 +03:00
static SSIZE_T transport_read_layer_bytes(rdpTransport* transport, wStream* s, size_t toRead)
{
2019-02-07 16:22:28 +03:00
SSIZE_T status;
if (!transport)
return -1;
2019-02-07 16:22:28 +03:00
if (toRead > SSIZE_MAX)
return 0;
status = IFCALLRESULT(-1, transport->io.ReadBytes, transport, Stream_Pointer(s), toRead);
2014-08-19 20:26:39 +04:00
if (status <= 0)
return status;
2019-02-07 16:22:28 +03:00
Stream_Seek(s, (size_t)status);
return status == (SSIZE_T)toRead ? 1 : 0;
}
/**
2014-07-28 15:12:01 +04:00
* @brief Try to read a complete PDU (NLA, fast-path or tpkt) from the underlying transport.
*
* If possible a complete PDU is read, in case of non blocking transport this might not succeed.
* Except in case of an error the passed stream will point to the last byte read (correct
* position). When the pdu read is completed the stream is sealed and the pointer set to 0
*
* @param[in] transport rdpTransport
* @param[in] s wStream
2014-07-28 15:12:01 +04:00
* @return < 0 on error; 0 if not enough data is available (non blocking mode); > 0 number of
* bytes of the *complete* pdu read
*/
int transport_read_pdu(rdpTransport* transport, wStream* s)
{
if (!transport)
return -1;
return IFCALLRESULT(-1, transport->io.ReadPdu, transport, s);
}
SSIZE_T transport_parse_pdu(rdpTransport* transport, wStream* s, BOOL* incomplete)
{
size_t position;
2019-02-07 16:22:28 +03:00
size_t pduLength;
2014-08-19 20:26:39 +04:00
BYTE* header;
pduLength = 0;
if (!transport)
return -1;
if (!s)
return -1;
header = Stream_Buffer(s);
2013-11-08 02:37:58 +04:00
position = Stream_GetPosition(s);
2016-09-20 09:58:04 +03:00
if (incomplete)
*incomplete = TRUE;
/* Make sure at least two bytes are read for further processing */
if (position < 2)
{
/* No data available at the moment */
return 0;
}
if (transport->NlaMode)
{
/*
2014-07-28 15:12:01 +04:00
* In case NlaMode is set TSRequest package(s) are expected
* 0x30 = DER encoded data with these bits set:
* bit 6 P/C constructed
* bit 5 tag number - sequence
*/
if (header[0] == 0x30)
{
/* TSRequest (NLA) */
if (header[1] & 0x80)
{
if ((header[1] & ~(0x80)) == 1)
{
/* check for header bytes already was readed in previous calls */
if (position < 3)
return 0;
2014-08-19 20:26:39 +04:00
pduLength = header[2];
pduLength += 3;
}
else if ((header[1] & ~(0x80)) == 2)
{
/* check for header bytes already was readed in previous calls */
if (position < 4)
return 0;
2014-08-19 20:26:39 +04:00
pduLength = (header[2] << 8) | header[3];
pduLength += 4;
}
else
{
2017-02-22 11:42:56 +03:00
WLog_Print(transport->log, WLOG_ERROR, "Error reading TSRequest!");
return -1;
}
}
else
{
pduLength = header[1];
pduLength += 2;
}
}
}
else
{
if (header[0] == 0x03)
{
/* TPKT header */
/* check for header bytes already was readed in previous calls */
if (position < 4)
return 0;
pduLength = (header[2] << 8) | header[3];
/* min and max values according to ITU-T Rec. T.123 (01/2007) section 8 */
if ((pduLength < 7) || (pduLength > 0xFFFF))
{
2019-11-06 17:24:51 +03:00
WLog_Print(transport->log, WLOG_ERROR, "tpkt - invalid pduLength: %" PRIdz,
pduLength);
return -1;
}
}
else
{
/* Fast-Path Header */
if (header[1] & 0x80)
2014-07-28 15:12:01 +04:00
{
/* check for header bytes already was readed in previous calls */
if (position < 3)
return 0;
2014-08-19 20:26:39 +04:00
pduLength = ((header[1] & 0x7F) << 8) | header[2];
}
else
pduLength = header[1];
/*
* fast-path has 7 bits for length so the maximum size, including headers is 0x8000
* The theoretical minimum fast-path PDU consists only of two header bytes plus one
* byte for data (e.g. fast-path input synchronize pdu)
*/
if (pduLength < 3 || pduLength > 0x8000)
{
2019-11-06 17:24:51 +03:00
WLog_Print(transport->log, WLOG_ERROR, "fast path - invalid pduLength: %" PRIdz,
pduLength);
return -1;
}
}
}
if (position > pduLength)
return -1;
if (incomplete)
2020-12-10 01:20:44 +03:00
*incomplete = position < pduLength;
return pduLength;
}
static int transport_default_read_pdu(rdpTransport* transport, wStream* s)
{
BOOL incomplete;
SSIZE_T status;
size_t pduLength;
size_t position;
WINPR_ASSERT(transport);
WINPR_ASSERT(s);
/* Read in pdu length */
status = transport_parse_pdu(transport, s, &incomplete);
while ((status == 0) && incomplete)
{
int rc;
if (!Stream_EnsureRemainingCapacity(s, 1))
return -1;
rc = transport_read_layer_bytes(transport, s, 1);
if (rc != 1)
return rc;
status = transport_parse_pdu(transport, s, &incomplete);
}
if (status < 0)
return -1;
pduLength = (size_t)status;
/* Read in rest of the PDU */
if (!Stream_EnsureCapacity(s, pduLength))
return -1;
position = Stream_GetPosition(s);
if (position > pduLength)
return -1;
2016-09-20 09:58:04 +03:00
status = transport_read_layer_bytes(transport, s, pduLength - Stream_GetPosition(s));
if (status != 1)
return status;
if (Stream_GetPosition(s) >= pduLength)
2019-11-06 17:24:51 +03:00
WLog_Packet(transport->log, WLOG_TRACE, Stream_Buffer(s), pduLength, WLOG_PACKET_INBOUND);
Stream_SealLength(s);
Stream_SetPosition(s, 0);
return Stream_Length(s);
}
int transport_write(rdpTransport* transport, wStream* s)
{
if (!transport)
return -1;
return IFCALLRESULT(-1, transport->io.WritePdu, transport, s);
}
static int transport_default_write(rdpTransport* transport, wStream* s)
{
size_t length;
int status = -1;
int writtenlength = 0;
2020-09-18 09:47:56 +03:00
rdpRdp* rdp;
rdpContext* context = transport_get_context(transport);
WINPR_ASSERT(transport);
WINPR_ASSERT(context);
if (!s)
return -1;
Stream_AddRef(s);
2021-09-06 12:01:36 +03:00
rdp = context->rdp;
2020-09-18 09:47:56 +03:00
if (!rdp)
goto fail;
2021-09-17 10:07:40 +03:00
EnterCriticalSection(&(transport->WriteLock));
if (!transport->frontBio)
2021-09-17 10:07:40 +03:00
goto out_cleanup;
length = Stream_GetPosition(s);
writtenlength = length;
Stream_SetPosition(s, 0);
if (length > 0)
{
rdp->outBytes += length;
2019-11-06 17:24:51 +03:00
WLog_Packet(transport->log, WLOG_TRACE, Stream_Buffer(s), length, WLOG_PACKET_OUTBOUND);
}
while (length > 0)
{
ERR_clear_error();
status = BIO_write(transport->frontBio, Stream_Pointer(s), length);
if (status <= 0)
{
/* the buffered BIO that is at the end of the chain always says OK for writing,
* so a retry means that for any reason we need to read. The most probable
* is a SSL or TSG BIO in the chain.
*/
if (!BIO_should_retry(transport->frontBio))
{
2017-02-22 11:42:56 +03:00
WLog_ERR_BIO(transport, "BIO_should_retry", transport->frontBio);
goto out_cleanup;
}
/* non-blocking can live with blocked IOs */
if (!transport->blocking)
{
2017-02-22 11:42:56 +03:00
WLog_ERR_BIO(transport, "BIO_write", transport->frontBio);
goto out_cleanup;
}
if (BIO_wait_write(transport->frontBio, 100) < 0)
{
2017-02-22 11:42:56 +03:00
WLog_ERR_BIO(transport, "BIO_wait_write", transport->frontBio);
status = -1;
goto out_cleanup;
}
2014-08-19 20:26:39 +04:00
continue;
}
WINPR_ASSERT(context->settings);
if (transport->blocking || context->settings->WaitForOutputBufferFlush)
{
while (BIO_write_blocked(transport->frontBio))
{
if (BIO_wait_write(transport->frontBio, 100) < 0)
{
2017-02-22 11:42:56 +03:00
WLog_Print(transport->log, WLOG_ERROR, "error when selecting for write");
status = -1;
goto out_cleanup;
}
if (BIO_flush(transport->frontBio) < 1)
{
2017-02-22 11:42:56 +03:00
WLog_Print(transport->log, WLOG_ERROR, "error when flushing outputBuffer");
status = -1;
goto out_cleanup;
}
}
}
length -= status;
Stream_Seek(s, status);
}
2016-09-20 09:58:04 +03:00
transport->written += writtenlength;
out_cleanup:
if (status < 0)
{
/* A write error indicates that the peer has dropped the connection */
transport->layer = TRANSPORT_LAYER_CLOSED;
2021-09-06 12:01:36 +03:00
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
}
LeaveCriticalSection(&(transport->WriteLock));
fail:
Stream_Release(s);
return status;
}
2019-11-06 17:24:51 +03:00
DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events, DWORD count)
{
DWORD nCount = 0; /* always the reread Event */
2015-04-21 13:35:55 +03:00
DWORD tmp;
WINPR_ASSERT(transport);
WINPR_ASSERT(events);
WINPR_ASSERT(count > 0);
if (events)
{
if (count < 1)
{
2019-11-06 17:24:51 +03:00
WLog_Print(transport->log, WLOG_ERROR, "%s: provided handles array is too small",
__FUNCTION__);
return 0;
}
events[nCount++] = transport->rereadEvent;
if (transport->useIoEvent)
{
if (count < 2)
return 0;
events[nCount++] = transport->ioEvent;
}
}
if (!transport->GatewayEnabled)
{
if (events)
{
if (nCount >= count)
{
2017-02-22 11:42:56 +03:00
WLog_Print(transport->log, WLOG_ERROR,
2019-11-06 17:24:51 +03:00
"%s: provided handles array is too small (count=%" PRIu32
" nCount=%" PRIu32 ")",
2017-02-22 11:42:56 +03:00
__FUNCTION__, count, nCount);
return 0;
}
2016-09-20 09:58:04 +03:00
if (transport->frontBio)
{
if (BIO_get_event(transport->frontBio, &events[nCount]) != 1)
{
WLog_Print(transport->log, WLOG_ERROR, "%s: error getting the frontBio handle",
__FUNCTION__);
return 0;
}
nCount++;
}
}
}
else
{
2015-03-17 21:54:16 +03:00
if (transport->rdg)
{
tmp = rdg_get_event_handles(transport->rdg, &events[nCount], count - nCount);
if (tmp == 0)
return 0;
nCount += tmp;
2015-03-17 21:54:16 +03:00
}
else if (transport->tsg)
{
tmp = tsg_get_event_handles(transport->tsg, &events[nCount], count - nCount);
if (tmp == 0)
return 0;
nCount += tmp;
2015-03-17 21:54:16 +03:00
}
}
return nCount;
}
#if defined(WITH_FREERDP_DEPRECATED)
void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount)
{
2015-04-21 13:35:55 +03:00
DWORD index;
DWORD nCount;
2021-08-25 12:14:35 +03:00
HANDLE events[MAXIMUM_WAIT_OBJECTS] = { 0 };
WINPR_ASSERT(transport);
WINPR_ASSERT(rfds);
WINPR_ASSERT(rcount);
2021-08-25 12:14:35 +03:00
nCount = transport_get_event_handles(transport, events, ARRAYSIZE(events));
*rcount = nCount + 1;
for (index = 0; index < nCount; index++)
{
rfds[index] = GetEventWaitObject(events[index]);
}
2018-03-06 15:58:40 +03:00
rfds[nCount] = GetEventWaitObject(transport->rereadEvent);
}
#endif
BOOL transport_is_write_blocked(rdpTransport* transport)
{
WINPR_ASSERT(transport);
2021-09-17 10:07:40 +03:00
WINPR_ASSERT(transport->frontBio);
return BIO_write_blocked(transport->frontBio);
}
int transport_drain_output_buffer(rdpTransport* transport)
{
BOOL status = FALSE;
WINPR_ASSERT(transport);
2021-09-17 10:07:40 +03:00
WINPR_ASSERT(transport->frontBio);
if (BIO_write_blocked(transport->frontBio))
{
if (BIO_flush(transport->frontBio) < 1)
return -1;
2014-08-19 20:26:39 +04:00
status |= BIO_write_blocked(transport->frontBio);
}
return status;
}
int transport_check_fds(rdpTransport* transport)
{
int status;
state_run_t recv_status;
wStream* received;
UINT64 now = GetTickCount64();
UINT64 dueDate = 0;
rdpContext* context = transport_get_context(transport);
2021-09-06 12:01:36 +03:00
WINPR_ASSERT(context);
if (transport->layer == TRANSPORT_LAYER_CLOSED)
{
WLog_Print(transport->log, WLOG_DEBUG, "transport_check_fds: transport layer closed");
2021-09-06 12:01:36 +03:00
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
return -1;
}
WINPR_ASSERT(context->settings);
dueDate = now + context->settings->MaxTimeInCheckLoop;
make cppcheck even more happier: [channels/tsmf/client/gstreamer/tsmf_X11.c:317] -> [channels/tsmf/client/gstreamer/tsmf_X11.c:322]: (warning) Either the condition '!decoder' is redundant or there is possible null pointer dereference: decoder. [channels/tsmf/client/gstreamer/tsmf_X11.c:470] -> [channels/tsmf/client/gstreamer/tsmf_X11.c:475]: (warning) Either the condition '!decoder' is redundant or there is possible null pointer dereference: decoder. [channels/tsmf/client/gstreamer/tsmf_X11.c:472] -> [channels/tsmf/client/gstreamer/tsmf_X11.c:475]: (warning) Either the condition '!decoder' is redundant or there is possible null pointer dereference: decoder. [channels/tsmf/client/tsmf_media.c:179] -> [channels/tsmf/client/tsmf_media.c:181]: (warning) Either the condition '!stream' is redundant or there is possible null pointer dereference: stream. [client/Windows/wf_cliprdr.c:2219] -> [client/Windows/wf_cliprdr.c:2222]: (warning) Either the condition '!formatDataResponse' is redundant or there is possible null pointer dereference: formatDataResponse [client/Windows/wf_cliprdr.c:2445] -> [client/Windows/wf_cliprdr.c:2448]: (warning) Either the condition '!fileContentsResponse' is redundant or there is possible null pointer dereference: fileContentsResponse. [client/X11/xf_cliprdr.c:911] -> [client/X11/xf_cliprdr.c:913]: (warning) Either the condition '!clipboard' is redundant or there is possible null pointer dereference: clipboard. [client/X11/xf_graphics.c:504] -> [client/X11/xf_graphics.c:506]: (warning) Either the condition '!xfc' is redundant or there is possible null pointer dereference: xfc. [libfreerdp/core/transport.c:861] -> [libfreerdp/core/transport.c:863]: (warning) Either the condition '!transport' is redundant or there is possible null pointer dereference: transport. [server/shadow/shadow_server.c:777] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:778] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:779] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:781] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:782] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:783] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:784] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:785] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:787] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server. [server/shadow/shadow_server.c:789] -> [server/shadow/shadow_server.c:791]: (warning) Either the condition '!server' is redundant or there is possible null pointer dereference: server.
2017-01-26 12:44:19 +03:00
if (transport->haveMoreBytesToRead)
{
transport->haveMoreBytesToRead = FALSE;
ResetEvent(transport->rereadEvent);
}
2017-09-19 11:18:41 +03:00
while (now < dueDate)
{
2021-09-06 12:01:36 +03:00
WINPR_ASSERT(context);
if (freerdp_shall_disconnect_context(context))
{
2017-09-19 11:18:41 +03:00
return -1;
}
/**
* Note: transport_read_pdu tries to read one PDU from
* the transport layer.
2014-07-28 15:12:01 +04:00
* The ReceiveBuffer might have a position > 0 in case of a non blocking
* transport. If transport_read_pdu returns 0 the pdu couldn't be read at
* this point.
* Note that transport->ReceiveBuffer is replaced after each iteration
* of this loop with a fresh stream instance from a pool.
*/
if ((status = transport_read_pdu(transport, transport->ReceiveBuffer)) <= 0)
{
if (status < 0)
2019-11-06 17:24:51 +03:00
WLog_Print(transport->log, WLOG_DEBUG,
"transport_check_fds: transport_read_pdu() - %i", status);
2016-09-20 09:58:04 +03:00
return status;
}
received = transport->ReceiveBuffer;
2016-09-20 09:58:04 +03:00
if (!(transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0)))
return -1;
2016-09-20 09:58:04 +03:00
/**
* status:
* -1: error
* 0: success
* 1: redirection
*/
WINPR_ASSERT(transport->ReceiveCallback);
recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra);
Stream_Release(received);
/* session redirection or activation */
if (recv_status == STATE_RUN_REDIRECT || recv_status == STATE_RUN_ACTIVE)
{
return recv_status;
}
if (state_run_failed(recv_status))
2015-05-02 06:26:08 +03:00
{
char buffer[64] = { 0 };
2019-11-06 17:24:51 +03:00
WLog_Print(transport->log, WLOG_ERROR,
"transport_check_fds: transport->ReceiveCallback() - %s",
state_run_result_string(recv_status, buffer, ARRAYSIZE(buffer)));
return -1;
}
now = GetTickCount64();
}
2016-10-08 23:37:31 +03:00
if (now >= dueDate)
{
SetEvent(transport->rereadEvent);
transport->haveMoreBytesToRead = TRUE;
}
2016-10-13 23:02:25 +03:00
return 0;
}
BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking)
{
WINPR_ASSERT(transport);
transport->blocking = blocking;
if (transport->frontBio)
{
if (!BIO_set_nonblock(transport->frontBio, blocking ? FALSE : TRUE))
return FALSE;
}
return TRUE;
}
void transport_set_gateway_enabled(rdpTransport* transport, BOOL GatewayEnabled)
{
WINPR_ASSERT(transport);
transport->GatewayEnabled = GatewayEnabled;
}
void transport_set_nla_mode(rdpTransport* transport, BOOL NlaMode)
{
WINPR_ASSERT(transport);
transport->NlaMode = NlaMode;
}
BOOL transport_disconnect(rdpTransport* transport)
{
if (!transport)
return FALSE;
return IFCALLRESULT(FALSE, transport->io.TransportDisconnect, transport);
}
static BOOL transport_default_disconnect(rdpTransport* transport)
{
BOOL status = TRUE;
if (!transport)
return FALSE;
2015-02-18 23:36:57 +03:00
if (transport->tls)
{
2015-02-18 23:36:57 +03:00
tls_free(transport->tls);
transport->tls = NULL;
}
else
{
2015-02-18 23:36:57 +03:00
if (transport->frontBio)
2018-10-25 14:08:00 +03:00
BIO_free_all(transport->frontBio);
2015-02-18 23:36:57 +03:00
}
if (transport->tsg)
{
tsg_free(transport->tsg);
transport->tsg = NULL;
}
if (transport->rdg)
{
rdg_free(transport->rdg);
transport->rdg = NULL;
}
transport->frontBio = NULL;
transport->layer = TRANSPORT_LAYER_TCP;
return status;
}
rdpTransport* transport_new(rdpContext* context)
{
rdpTransport* transport = (rdpTransport*)calloc(1, sizeof(rdpTransport));
WINPR_ASSERT(context);
if (!transport)
return NULL;
2017-02-22 11:42:56 +03:00
transport->log = WLog_Get(TAG);
if (!transport->log)
goto fail;
// transport->io.DataHandler = transport_data_handler;
transport->io.TCPConnect = freerdp_tcp_default_connect;
transport->io.TLSConnect = transport_default_connect_tls;
transport->io.TLSAccept = transport_default_accept_tls;
transport->io.TransportAttach = transport_default_attach;
transport->io.TransportDisconnect = transport_default_disconnect;
transport->io.ReadPdu = transport_default_read_pdu;
transport->io.WritePdu = transport_default_write;
transport->io.ReadBytes = transport_read_layer;
2017-02-22 11:42:56 +03:00
transport->context = context;
transport->ReceivePool = StreamPool_New(TRUE, BUFFER_SIZE);
2014-08-19 20:26:39 +04:00
if (!transport->ReceivePool)
goto fail;
2013-01-26 02:52:37 +04:00
/* receive buffer for non-blocking read. */
transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);
2014-08-19 20:26:39 +04:00
if (!transport->ReceiveBuffer)
goto fail;
transport->connectedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
2014-08-19 20:26:39 +04:00
2019-11-06 17:24:51 +03:00
if (!transport->connectedEvent || transport->connectedEvent == INVALID_HANDLE_VALUE)
goto fail;
transport->rereadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
2016-10-13 23:02:25 +03:00
if (!transport->rereadEvent || transport->rereadEvent == INVALID_HANDLE_VALUE)
goto fail;
transport->ioEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!transport->ioEvent || transport->ioEvent == INVALID_HANDLE_VALUE)
goto fail;
transport->haveMoreBytesToRead = FALSE;
transport->blocking = TRUE;
transport->GatewayEnabled = FALSE;
transport->layer = TRANSPORT_LAYER_TCP;
if (!InitializeCriticalSectionAndSpinCount(&(transport->ReadLock), 4000))
goto fail;
2014-08-19 20:26:39 +04:00
if (!InitializeCriticalSectionAndSpinCount(&(transport->WriteLock), 4000))
goto fail;
return transport;
fail:
transport_free(transport);
return NULL;
}
void transport_free(rdpTransport* transport)
{
if (!transport)
return;
2015-01-12 15:32:59 +03:00
transport_disconnect(transport);
if (transport->ReceiveBuffer)
Stream_Release(transport->ReceiveBuffer);
2013-02-15 05:39:56 +04:00
2020-05-12 10:09:13 +03:00
nla_free(transport->nla);
StreamPool_Free(transport->ReceivePool);
CloseHandle(transport->connectedEvent);
CloseHandle(transport->rereadEvent);
CloseHandle(transport->ioEvent);
DeleteCriticalSection(&(transport->ReadLock));
DeleteCriticalSection(&(transport->WriteLock));
free(transport);
}
BOOL transport_set_io_callbacks(rdpTransport* transport, const rdpTransportIo* io_callbacks)
{
if (!transport || !io_callbacks)
return FALSE;
transport->io = *io_callbacks;
return TRUE;
}
const rdpTransportIo* transport_get_io_callbacks(rdpTransport* transport)
{
if (!transport)
return NULL;
return &transport->io;
}
rdpContext* transport_get_context(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->context;
}
rdpTransport* freerdp_get_transport(rdpContext* context)
{
WINPR_ASSERT(context);
WINPR_ASSERT(context->rdp);
return context->rdp->transport;
}
2021-09-06 12:01:36 +03:00
BOOL transport_set_nla(rdpTransport* transport, rdpNla* nla)
{
WINPR_ASSERT(transport);
nla_free(transport->nla);
transport->nla = nla;
return TRUE;
}
rdpNla* transport_get_nla(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->nla;
}
BOOL transport_set_tls(rdpTransport* transport, rdpTls* tls)
{
WINPR_ASSERT(transport);
tls_free(transport->tls);
transport->tls = tls;
return TRUE;
}
rdpTls* transport_get_tls(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->tls;
}
BOOL transport_set_tsg(rdpTransport* transport, rdpTsg* tsg)
{
WINPR_ASSERT(transport);
tsg_free(transport->tsg);
transport->tsg = tsg;
return TRUE;
}
rdpTsg* transport_get_tsg(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->tsg;
}
wStream* transport_take_from_pool(rdpTransport* transport, size_t size)
{
WINPR_ASSERT(transport);
return StreamPool_Take(transport->ReceivePool, size);
}
ULONG transport_get_bytes_sent(rdpTransport* transport, BOOL resetCount)
{
ULONG rc;
WINPR_ASSERT(transport);
rc = transport->written;
if (resetCount)
transport->written = 0;
return rc;
}
TRANSPORT_LAYER transport_get_layer(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->layer;
}
BOOL transport_set_layer(rdpTransport* transport, TRANSPORT_LAYER layer)
{
WINPR_ASSERT(transport);
transport->layer = layer;
return TRUE;
}
BOOL transport_set_connected_event(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return SetEvent(transport->connectedEvent);
}
BOOL transport_set_recv_callbacks(rdpTransport* transport, TransportRecv recv, void* extra)
{
WINPR_ASSERT(transport);
transport->ReceiveCallback = recv;
transport->ReceiveExtra = extra;
2021-09-13 09:11:40 +03:00
return TRUE;
2021-09-06 12:01:36 +03:00
}
BOOL transport_get_blocking(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->blocking;
}
BOOL transport_set_blocking(rdpTransport* transport, BOOL blocking)
{
WINPR_ASSERT(transport);
transport->blocking = blocking;
return TRUE;
}
BOOL transport_have_more_bytes_to_read(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->haveMoreBytesToRead;
}
int transport_tcp_connect(rdpTransport* transport, const char* hostname, int port, DWORD timeout)
{
rdpContext* context = transport_get_context(transport);
WINPR_ASSERT(context);
WINPR_ASSERT(context->settings);
return IFCALLRESULT(-1, transport->io.TCPConnect, context, context->settings, hostname, port,
timeout);
}
HANDLE transport_get_front_bio(rdpTransport* transport)
{
HANDLE hEvent = NULL;
WINPR_ASSERT(transport);
WINPR_ASSERT(transport->frontBio);
BIO_get_event(transport->frontBio, &hEvent);
return hEvent;
}
BOOL transport_io_callback_set_event(rdpTransport* transport, BOOL set)
{
WINPR_ASSERT(transport);
transport->useIoEvent = TRUE;
if (!set)
return ResetEvent(transport->ioEvent);
return SetEvent(transport->ioEvent);
}