/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Protocol services - TCP layer
Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
Copyright 2005-2011 Peter Astrand <astrand@cendio.se> for Cendio AB
Copyright 2012-2013 Henrik Andersson <hean01@cendio.se> for Cendio AB
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the General Public License version 2 (GPLv2) at this time for any software where
* a choice of GPL license versions is made available with the language indicating
* that GPLv2 or any later version may be used, or where a choice of which version
* of the GPL is applied is otherwise unspecified.
*/
#ifndef _WIN32
#include <unistd.h> /* select read write close */
#include <netdb.h> /* gethostbyname */
#include <errno.h> /* errno */
#endif
#include "rdesktop.h"
#ifdef _WIN32
#define socklen_t int
#else
#endif
#ifndef INADDR_NONE
#endif
#ifdef WITH_SCARD
#else
#endif
static int g_sock;
extern RD_BOOL g_user_quit;
extern RD_BOOL g_network_error;
extern RD_BOOL g_reconnect_loop;
/* wait till socket is ready to write or timeout */
static RD_BOOL
{
int sel_count;
if (sel_count > 0)
{
return True;
}
return False;
}
/* Initialise TCP transport data packet */
{
static int cur_stream_id = 0;
#ifdef WITH_SCARD
#endif
{
}
#ifdef WITH_SCARD
#endif
return result;
}
/* Send TCP transport data packet */
void
{
int ssl_err;
if (g_network_error == True)
return;
#ifdef WITH_SCARD
#endif
{
if (g_ssl)
{
if (sent <= 0)
{
{
sent = 0;
}
else
{
#ifdef WITH_SCARD
#endif
return;
}
}
}
else
{
if (sent <= 0)
{
{
sent = 0;
}
else
{
#ifdef WITH_SCARD
#endif
return;
}
}
}
}
#ifdef WITH_SCARD
#endif
}
/* Receive a message on the TCP layer */
{
if (g_network_error == True)
return NULL;
if (s == NULL)
{
/* read into "new" stream */
{
}
s = &g_in;
}
else
{
/* append to existing stream */
if (new_length > s->size)
{
s->size = new_length;
}
}
while (length > 0)
{
{
{
/* User quit */
g_user_quit = True;
return NULL;
}
}
if (g_ssl)
{
if (ssl_err == SSL_ERROR_SSL)
{
{
error("Remote peer initiated ssl shutdown.\n");
return NULL;
}
return NULL;
}
{
rcvd = 0;
}
else if (ssl_err != SSL_ERROR_NONE)
{
return NULL;
}
}
else
{
if (rcvd < 0)
{
{
rcvd = 0;
}
else
{
return NULL;
}
}
else if (rcvd == 0)
{
error("Connection closed\n");
return NULL;
}
}
}
return s;
}
tcp_tls_connect(void)
{
int err;
long options;
if (!g_ssl_initialized)
{
}
/* create process context */
{
{
error("tcp_tls_connect: SSL_CTX_new() failed to create TLS v1.0 context\n");
goto fail;
}
options = 0;
#ifdef SSL_OP_NO_COMPRESSION
#endif // __SSL_OP_NO_COMPRESSION
}
/* free old connection */
if (g_ssl)
/* create new ssl connection */
{
error("tcp_tls_connect: SSL_new() failed\n");
goto fail;
}
{
error("tcp_tls_connect: SSL_set_fd() failed\n");
goto fail;
}
do
{
}
if (err < 0)
{
goto fail;
}
return True;
fail:
if (g_ssl)
if (g_ssl_ctx)
return False;
}
/* Get public key from server of TLS 1.0 connection */
{
s->size = 0;
goto out;
{
error("tcp_tls_get_server_pubkey: SSL_get_peer_certificate() failed\n");
goto out;
}
{
error("tcp_tls_get_server_pubkey: X509_get_pubkey() failed\n");
goto out;
}
if (s->size < 1)
{
error("tcp_tls_get_server_pubkey: i2d_PublicKey() failed\n");
goto out;
}
i2d_PublicKey(pkey, &s->p);
s->p = s->data;
out:
if (cert)
if (pkey)
return (s->size != 0);
}
/* Establish a connection on the TCP layer */
{
int i;
#ifdef IPv6
int n;
{
return False;
}
g_sock = -1;
while (res)
{
if (!(g_sock < 0))
{
break;
g_sock = -1;
}
}
if (g_sock == -1)
{
return False;
}
#else /* no IPv6 support */
{
}
{
return False;
}
{
return False;
}
{
if (!g_reconnect_loop)
g_sock = -1;
return False;
}
#endif /* IPv6 */
option_value = 1;
option_len = sizeof(option_value);
/* receive buffer must be a least 16 K */
{
{
option_len = sizeof(option_value);
}
}
for (i = 0; i < STREAM_COUNT; i++)
{
}
return True;
}
/* Disconnect on the TCP layer */
void
tcp_disconnect(void)
{
if (g_ssl)
{
if (!g_network_error)
(void) SSL_shutdown(g_ssl);
}
g_sock = -1;
}
char *
{
{
}
else
return ipaddr;
}
{
return True;
return False;
}
/* reset the state of the tcp layer */
/* Support for Session Directory */
void
tcp_reset_state(void)
{
int i;
/* Clear the incoming stream */
/* Clear the outgoing stream(s) */
for (i = 0; i < STREAM_COUNT; i++)
{
}
}
void
{
}