2014-12-24 07:51:10 +03:00
|
|
|
/**
|
2012-09-20 07:51:34 +04:00
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2014-02-20 12:41:53 +04:00
|
|
|
* Copyright (C) Jay Sorg 2004-2014
|
2012-09-20 07:51:34 +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.
|
|
|
|
*
|
|
|
|
* rdp layer
|
|
|
|
*/
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
#include "libxrdp.h"
|
2019-12-19 12:55:38 +03:00
|
|
|
#include "ms-rdpbcgr.h"
|
2013-01-16 17:41:57 +04:00
|
|
|
#include "log.h"
|
2017-06-08 19:39:07 +03:00
|
|
|
#include "ssl_calls.h"
|
2020-08-22 20:05:24 +03:00
|
|
|
#include "string_calls.h"
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2013-08-24 13:02:01 +04:00
|
|
|
#if defined(XRDP_NEUTRINORDP)
|
2012-07-17 23:59:03 +04:00
|
|
|
#include <freerdp/codec/rfx.h>
|
2014-01-22 22:30:46 +04:00
|
|
|
#include <freerdp/constants.h>
|
2012-04-06 02:40:46 +04:00
|
|
|
#endif
|
|
|
|
|
2020-08-02 07:04:12 +03:00
|
|
|
|
2014-03-08 00:45:33 +04:00
|
|
|
|
2014-03-10 08:07:08 +04:00
|
|
|
#define FASTPATH_FRAG_SIZE (16 * 1024 - 128)
|
2014-03-09 23:11:36 +04:00
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2020-06-05 11:53:31 +03:00
|
|
|
xrdp_rdp_read_config(const char *xrdp_ini, struct xrdp_client_info *client_info)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int index = 0;
|
|
|
|
struct list *items = (struct list *)NULL;
|
|
|
|
struct list *values = (struct list *)NULL;
|
2017-02-02 04:14:55 +03:00
|
|
|
char *item = NULL;
|
|
|
|
char *value = NULL;
|
2017-06-08 19:39:07 +03:00
|
|
|
int pos;
|
2017-02-02 04:14:55 +03:00
|
|
|
char *tmp = NULL;
|
2016-12-13 09:49:13 +03:00
|
|
|
int tmp_length = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-08-15 17:54:26 +03:00
|
|
|
client_info->xrdp_keyboard_overrides.type = -1;
|
|
|
|
client_info->xrdp_keyboard_overrides.subtype = -1;
|
|
|
|
client_info->xrdp_keyboard_overrides.layout = -1;
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* initialize (zero out) local variables: */
|
|
|
|
items = list_create();
|
|
|
|
items->auto_free = 1;
|
|
|
|
values = list_create();
|
|
|
|
values->auto_free = 1;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Reading config file %s", xrdp_ini);
|
2020-06-05 11:53:31 +03:00
|
|
|
file_by_name_read_section(xrdp_ini, "globals", items, values);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
for (index = 0; index < items->count; index++)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
item = (char *)list_get_item(items, index);
|
|
|
|
value = (char *)list_get_item(values, index);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "item %s, value %s", item, value);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_strcasecmp(item, "bitmap_cache") == 0)
|
|
|
|
{
|
2013-08-25 09:41:44 +04:00
|
|
|
client_info->use_bitmap_cache = g_text2bool(value);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "bitmap_compression") == 0)
|
|
|
|
{
|
2013-08-25 09:41:44 +04:00
|
|
|
client_info->use_bitmap_comp = g_text2bool(value);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2013-01-07 11:56:40 +04:00
|
|
|
else if (g_strcasecmp(item, "bulk_compression") == 0)
|
|
|
|
{
|
2013-08-25 09:41:44 +04:00
|
|
|
client_info->use_bulk_comp = g_text2bool(value);
|
2013-01-07 11:56:40 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (g_strcasecmp(item, "crypt_level") == 0)
|
|
|
|
{
|
2014-08-05 23:28:54 +04:00
|
|
|
if (g_strcasecmp(value, "none") == 0)
|
|
|
|
{
|
|
|
|
client_info->crypt_level = 0;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "low") == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
client_info->crypt_level = 1;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "medium") == 0)
|
|
|
|
{
|
|
|
|
client_info->crypt_level = 2;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "high") == 0)
|
|
|
|
{
|
|
|
|
client_info->crypt_level = 3;
|
|
|
|
}
|
2014-02-20 12:41:53 +04:00
|
|
|
else if (g_strcasecmp(value, "fips") == 0)
|
|
|
|
{
|
|
|
|
client_info->crypt_level = 4;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "Your configured crypt level is "
|
2020-11-30 06:29:57 +03:00
|
|
|
"undefined, 'high' will be used");
|
2012-09-20 07:51:34 +04:00
|
|
|
client_info->crypt_level = 3;
|
|
|
|
}
|
|
|
|
}
|
2013-02-01 13:00:39 +04:00
|
|
|
else if (g_strcasecmp(item, "allow_channels") == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2017-01-06 08:59:49 +03:00
|
|
|
client_info->channels_allowed = g_text2bool(value);
|
|
|
|
if (client_info->channels_allowed == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "All channels are disabled");
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
2013-07-15 11:13:03 +04:00
|
|
|
else if (g_strcasecmp(item, "allow_multimon") == 0)
|
2020-11-30 06:29:57 +03:00
|
|
|
{
|
|
|
|
client_info->multimon = g_text2bool(value);
|
|
|
|
if (client_info->multimon == 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "Multi monitor server support disabled");
|
2020-11-30 06:29:57 +03:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (g_strcasecmp(item, "max_bpp") == 0)
|
|
|
|
{
|
|
|
|
client_info->max_bpp = g_atoi(value);
|
|
|
|
}
|
2013-07-03 21:45:46 +04:00
|
|
|
else if (g_strcasecmp(item, "rfx_min_pixel") == 0)
|
|
|
|
{
|
|
|
|
client_info->rfx_min_pixel = g_atoi(value);
|
|
|
|
}
|
2013-06-08 10:43:58 +04:00
|
|
|
else if (g_strcasecmp(item, "new_cursors") == 0)
|
|
|
|
{
|
2013-08-25 09:41:44 +04:00
|
|
|
client_info->pointer_flags = g_text2bool(value) == 0 ? 2 : 0;
|
2013-06-08 10:43:58 +04:00
|
|
|
}
|
2013-08-04 02:47:26 +04:00
|
|
|
else if (g_strcasecmp(item, "require_credentials") == 0)
|
|
|
|
{
|
2013-08-25 09:41:44 +04:00
|
|
|
client_info->require_credentials = g_text2bool(value);
|
2020-08-17 09:52:17 +03:00
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "enable_token_login") == 0)
|
|
|
|
{
|
|
|
|
client_info->enable_token_login = g_text2bool(value);
|
2013-08-04 02:47:26 +04:00
|
|
|
}
|
2014-02-11 02:28:43 +04:00
|
|
|
else if (g_strcasecmp(item, "use_fastpath") == 0)
|
|
|
|
{
|
|
|
|
if (g_strcasecmp(value, "output") == 0)
|
|
|
|
{
|
|
|
|
client_info->use_fast_path = 1;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "input") == 0)
|
|
|
|
{
|
|
|
|
client_info->use_fast_path = 2;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "both") == 0)
|
|
|
|
{
|
|
|
|
client_info->use_fast_path = 3;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "none") == 0)
|
|
|
|
{
|
|
|
|
client_info->use_fast_path = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "Your configured fastpath level is "
|
2020-11-30 06:29:57 +03:00
|
|
|
"undefined, fastpath will not be used");
|
2014-02-11 02:28:43 +04:00
|
|
|
client_info->use_fast_path = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 09:49:13 +03:00
|
|
|
else if (g_strcasecmp(item, "ssl_protocols") == 0)
|
2016-08-25 21:20:47 +03:00
|
|
|
{
|
2017-01-31 08:59:46 +03:00
|
|
|
/* put leading/trailing comma to properly detect "TLSv1" without regex */
|
2016-12-13 09:49:13 +03:00
|
|
|
tmp_length = g_strlen(value) + 3;
|
|
|
|
tmp = g_new(char, tmp_length);
|
2017-01-31 08:59:46 +03:00
|
|
|
g_snprintf(tmp, tmp_length, "%s%s%s", ",", value, ",");
|
2017-06-08 19:39:07 +03:00
|
|
|
/* replace all spaces with comma */
|
2017-01-31 08:59:46 +03:00
|
|
|
/* to accept space after comma */
|
2017-06-08 19:39:07 +03:00
|
|
|
while ((pos = g_pos(tmp, " ")) != -1)
|
2017-01-31 08:59:46 +03:00
|
|
|
{
|
2017-06-08 19:39:07 +03:00
|
|
|
tmp[pos] = ',';
|
2016-12-14 08:47:46 +03:00
|
|
|
}
|
2017-06-08 19:39:07 +03:00
|
|
|
ssl_get_protocols_from_string(tmp, &(client_info->ssl_protocols));
|
2017-03-08 09:25:02 +03:00
|
|
|
g_free(tmp);
|
2016-08-25 21:20:47 +03:00
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "tls_ciphers") == 0)
|
|
|
|
{
|
2017-03-04 10:27:03 +03:00
|
|
|
client_info->tls_ciphers = g_strdup(value);
|
2016-08-25 21:20:47 +03:00
|
|
|
}
|
2014-07-09 16:33:39 +04:00
|
|
|
else if (g_strcasecmp(item, "security_layer") == 0)
|
|
|
|
{
|
|
|
|
if (g_strcasecmp(value, "rdp") == 0)
|
|
|
|
{
|
2014-07-10 16:40:16 +04:00
|
|
|
client_info->security_layer = PROTOCOL_RDP;
|
2014-07-09 16:33:39 +04:00
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "tls") == 0)
|
|
|
|
{
|
2014-07-10 16:40:16 +04:00
|
|
|
client_info->security_layer = PROTOCOL_SSL;
|
2014-07-09 16:33:39 +04:00
|
|
|
}
|
|
|
|
else if (g_strcasecmp(value, "hybrid") == 0)
|
|
|
|
{
|
2014-07-10 16:40:16 +04:00
|
|
|
client_info->security_layer = PROTOCOL_SSL | PROTOCOL_HYBRID;
|
2014-07-09 16:33:39 +04:00
|
|
|
}
|
2016-11-28 10:49:32 +03:00
|
|
|
else if (g_strcasecmp(value, "negotiate") == 0)
|
|
|
|
{
|
|
|
|
client_info->security_layer = PROTOCOL_SSL | PROTOCOL_HYBRID | PROTOCOL_HYBRID_EX;
|
|
|
|
}
|
2014-07-09 16:33:39 +04:00
|
|
|
else
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "security_layer=%s is not "
|
2020-11-30 06:29:57 +03:00
|
|
|
"recognized, will use security_layer=negotiate",
|
|
|
|
value);
|
2014-07-10 16:40:16 +04:00
|
|
|
client_info->security_layer = PROTOCOL_SSL | PROTOCOL_HYBRID | PROTOCOL_HYBRID_EX;
|
2014-07-09 16:33:39 +04:00
|
|
|
}
|
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
else if (g_strcasecmp(item, "certificate") == 0)
|
|
|
|
{
|
|
|
|
g_memset(client_info->certificate, 0, sizeof(char) * 1024);
|
2016-06-11 11:58:15 +03:00
|
|
|
if (g_strlen(value) == 0)
|
2014-07-23 16:31:45 +04:00
|
|
|
{
|
2014-12-24 07:04:20 +03:00
|
|
|
/* default certificate path */
|
2014-07-23 16:31:45 +04:00
|
|
|
g_snprintf(client_info->certificate, 1023, "%s/cert.pem", XRDP_CFG_PATH);
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_INFO,
|
2020-11-30 06:29:57 +03:00
|
|
|
"Using default X.509 certificate: %s",
|
|
|
|
client_info->certificate);
|
2016-06-11 11:58:15 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
else if (value[0] != '/')
|
|
|
|
{
|
|
|
|
/* default certificate path */
|
|
|
|
g_snprintf(client_info->certificate, 1023, "%s/cert.pem", XRDP_CFG_PATH);
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING,
|
2020-11-30 06:29:57 +03:00
|
|
|
"X.509 certificate should use absolute path, using "
|
|
|
|
"default instead: %s", client_info->certificate);
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-24 07:04:20 +03:00
|
|
|
/* use user defined certificate */
|
|
|
|
g_strncpy(client_info->certificate, value, 1023);
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
2017-03-08 07:30:14 +03:00
|
|
|
|
2020-11-30 06:29:57 +03:00
|
|
|
if (!g_file_readable(client_info->certificate))
|
2017-03-08 07:30:14 +03:00
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Cannot read certificate file %s: %s",
|
2020-11-30 06:29:57 +03:00
|
|
|
client_info->certificate, g_get_strerror());
|
2017-03-08 07:30:14 +03:00
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "key_file") == 0)
|
|
|
|
{
|
|
|
|
g_memset(client_info->key_file, 0, sizeof(char) * 1024);
|
2016-06-11 11:58:15 +03:00
|
|
|
if (g_strlen(value) == 0)
|
|
|
|
{
|
|
|
|
/* default key_file path */
|
|
|
|
g_snprintf(client_info->key_file, 1023, "%s/key.pem", XRDP_CFG_PATH);
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "Using default X.509 key file: %s",
|
2020-11-30 06:29:57 +03:00
|
|
|
client_info->key_file);
|
2016-06-11 11:58:15 +03:00
|
|
|
}
|
|
|
|
else if (value[0] != '/')
|
2014-07-23 16:31:45 +04:00
|
|
|
{
|
2014-12-24 07:04:20 +03:00
|
|
|
/* default key_file path */
|
2014-07-23 16:31:45 +04:00
|
|
|
g_snprintf(client_info->key_file, 1023, "%s/key.pem", XRDP_CFG_PATH);
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING,
|
2020-11-30 06:29:57 +03:00
|
|
|
"X.509 key file should use absolute path, using "
|
|
|
|
"default instead: %s", client_info->key_file);
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-24 07:04:20 +03:00
|
|
|
/* use user defined key_file */
|
|
|
|
g_strncpy(client_info->key_file, value, 1023);
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
2017-03-08 07:30:14 +03:00
|
|
|
|
2018-10-25 05:34:00 +03:00
|
|
|
if (!g_file_readable(client_info->key_file))
|
2017-03-08 07:30:14 +03:00
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Cannot read private key file %s: %s",
|
2020-11-30 06:29:57 +03:00
|
|
|
client_info->key_file, g_get_strerror());
|
2017-03-08 07:30:14 +03:00
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
2020-08-30 22:20:21 +03:00
|
|
|
else if (g_strcasecmp(item, "domain_user_separator") == 0
|
|
|
|
&& g_strlen(value) > 0)
|
|
|
|
{
|
|
|
|
g_strncpy(client_info->domain_user_separator, value, sizeof(client_info->domain_user_separator) - 1);
|
|
|
|
}
|
2021-07-23 16:31:04 +03:00
|
|
|
else if (g_strcasecmp(item, "xrdp.override_keyboard_type") == 0)
|
|
|
|
{
|
|
|
|
client_info->xrdp_keyboard_overrides.type = g_atoix(value);
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "xrdp.override_keyboard_subtype") == 0)
|
|
|
|
{
|
|
|
|
client_info->xrdp_keyboard_overrides.subtype = g_atoix(value);
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "xrdp.override_keylayout") == 0)
|
|
|
|
{
|
|
|
|
client_info->xrdp_keyboard_overrides.layout = g_atoix(value);
|
|
|
|
}
|
2011-08-25 09:45:02 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
list_delete(items);
|
|
|
|
list_delete(values);
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
2013-08-24 13:02:01 +04:00
|
|
|
#if defined(XRDP_NEUTRINORDP)
|
2012-07-17 23:59:03 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
cpuid(tui32 info, tui32 *eax, tui32 *ebx, tui32 *ecx, tui32 *edx)
|
2012-07-17 23:59:03 +04:00
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2012-09-20 07:51:34 +04:00
|
|
|
__asm volatile
|
|
|
|
(
|
|
|
|
/* The EBX (or RBX register on x86_64) is used for the PIC base address
|
|
|
|
and must not be corrupted by our inline assembly. */
|
2012-07-17 23:59:03 +04:00
|
|
|
#if defined(__i386__)
|
2012-09-20 07:51:34 +04:00
|
|
|
"mov %%ebx, %%esi;"
|
|
|
|
"cpuid;"
|
|
|
|
"xchg %%ebx, %%esi;"
|
2012-07-17 23:59:03 +04:00
|
|
|
#else
|
2012-09-20 07:51:34 +04:00
|
|
|
"mov %%rbx, %%rsi;"
|
|
|
|
"cpuid;"
|
|
|
|
"xchg %%rbx, %%rsi;"
|
2012-07-17 23:59:03 +04:00
|
|
|
#endif
|
2020-11-30 06:29:57 +03:00
|
|
|
: "=a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx)
|
|
|
|
: "0" (info)
|
|
|
|
);
|
2012-07-17 23:59:03 +04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static tui32
|
|
|
|
xrdp_rdp_detect_cpu(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
tui32 eax;
|
|
|
|
tui32 ebx;
|
|
|
|
tui32 ecx;
|
|
|
|
tui32 edx;
|
|
|
|
tui32 cpu_opt;
|
|
|
|
|
|
|
|
eax = 0;
|
|
|
|
ebx = 0;
|
|
|
|
ecx = 0;
|
|
|
|
edx = 0;
|
|
|
|
cpu_opt = 0;
|
|
|
|
cpuid(1, &eax, &ebx, &ecx, &edx);
|
|
|
|
|
|
|
|
if (edx & (1 << 26))
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "SSE2 detected");
|
2012-09-20 07:51:34 +04:00
|
|
|
cpu_opt |= CPU_SSE2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpu_opt;
|
2012-07-17 23:59:03 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
struct xrdp_rdp *
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_create(struct xrdp_session *session, struct trans *trans)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct xrdp_rdp *self = (struct xrdp_rdp *)NULL;
|
|
|
|
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "in xrdp_rdp_create");
|
2012-09-20 07:51:34 +04:00
|
|
|
self = (struct xrdp_rdp *)g_malloc(sizeof(struct xrdp_rdp), 1);
|
|
|
|
self->session = session;
|
|
|
|
self->share_id = 66538;
|
|
|
|
/* read ini settings */
|
2020-06-05 11:53:31 +03:00
|
|
|
xrdp_rdp_read_config(session->xrdp_ini, &self->client_info);
|
2012-09-20 07:51:34 +04:00
|
|
|
/* create sec layer */
|
2014-07-23 16:31:45 +04:00
|
|
|
self->sec_layer = xrdp_sec_create(self, trans);
|
2012-09-20 07:51:34 +04:00
|
|
|
/* default 8 bit v1 color bitmap cache entries and size */
|
|
|
|
self->client_info.cache1_entries = 600;
|
|
|
|
self->client_info.cache1_size = 256;
|
|
|
|
self->client_info.cache2_entries = 300;
|
|
|
|
self->client_info.cache2_size = 1024;
|
|
|
|
self->client_info.cache3_entries = 262;
|
|
|
|
self->client_info.cache3_size = 4096;
|
|
|
|
/* load client ip info */
|
2022-04-22 13:56:23 +03:00
|
|
|
g_sck_get_peer_ip_address(trans->sck,
|
|
|
|
self->client_info.client_ip,
|
|
|
|
sizeof(self->client_info.client_ip),
|
|
|
|
NULL);
|
|
|
|
g_sck_get_peer_description(trans->sck,
|
|
|
|
self->client_info.client_description,
|
|
|
|
sizeof(self->client_info.client_description));
|
2012-09-20 07:51:34 +04:00
|
|
|
self->mppc_enc = mppc_enc_new(PROTO_RDP_50);
|
2013-08-24 13:02:01 +04:00
|
|
|
#if defined(XRDP_NEUTRINORDP)
|
2012-09-20 07:51:34 +04:00
|
|
|
self->rfx_enc = rfx_context_new();
|
|
|
|
rfx_context_set_cpu_opt(self->rfx_enc, xrdp_rdp_detect_cpu());
|
2012-04-06 02:40:46 +04:00
|
|
|
#endif
|
2012-09-20 07:51:34 +04:00
|
|
|
self->client_info.size = sizeof(self->client_info);
|
2021-02-26 14:27:13 +03:00
|
|
|
self->client_info.version = CLIENT_INFO_CURRENT_VERSION;
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "out xrdp_rdp_create");
|
2012-09-20 07:51:34 +04:00
|
|
|
return self;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_delete(struct xrdp_rdp *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (self == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xrdp_sec_delete(self->sec_layer);
|
2012-12-29 10:37:48 +04:00
|
|
|
mppc_enc_free(self->mppc_enc);
|
2013-08-24 13:02:01 +04:00
|
|
|
#if defined(XRDP_NEUTRINORDP)
|
2012-09-20 07:51:34 +04:00
|
|
|
rfx_context_free((RFX_CONTEXT *)(self->rfx_enc));
|
2012-04-06 02:40:46 +04:00
|
|
|
#endif
|
2017-03-04 10:27:03 +03:00
|
|
|
g_free(self->client_info.tls_ciphers);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_free(self);
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Initialize the stream for sending a [MS-RDPBCGR] Control PDU */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_init(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (xrdp_sec_init(self->sec_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_init: xrdp_sec_init failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
s_push_layer(s, rdp_hdr, 6); /* 6 = sizeof(TS_SHARECONTROLHEADER) */
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Initialize the stream for sending a [MS-RDPBCGR] Data PDU */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_init_data(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (xrdp_sec_init(self->sec_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_init_data: xrdp_sec_init failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
s_push_layer(s, rdp_hdr, 18); /* 18 = sizeof(TS_SHAREDATAHEADER) */
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2014-03-08 00:45:33 +04:00
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/*
|
|
|
|
Receives and parses pdu code from next data unit.
|
|
|
|
|
|
|
|
@param self
|
|
|
|
@param (in/out) s: the stream to read from. Upon return the stream is ?
|
|
|
|
@param (out) code: the pdu code from the packet
|
|
|
|
returns error
|
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int error = 0;
|
|
|
|
int len = 0;
|
|
|
|
int pdu_code = 0;
|
|
|
|
int chan = 0;
|
2014-03-04 12:19:19 +04:00
|
|
|
const tui8 *header;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (s->next_packet == 0 || s->next_packet >= s->end)
|
|
|
|
{
|
2014-03-05 01:25:49 +04:00
|
|
|
/* check for fastpath first */
|
2014-03-06 00:38:17 +04:00
|
|
|
header = (const tui8 *) (s->p);
|
2014-11-21 04:17:45 +03:00
|
|
|
if (header[0] != 0x3)
|
2014-02-08 22:55:41 +04:00
|
|
|
{
|
2014-03-04 12:19:19 +04:00
|
|
|
if (xrdp_sec_recv_fastpath(self->sec_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_recv: xrdp_sec_recv_fastpath failed");
|
2014-03-05 06:11:55 +04:00
|
|
|
return 1;
|
2014-03-04 12:19:19 +04:00
|
|
|
}
|
2014-03-07 05:51:35 +04:00
|
|
|
/* next_packet gets set in xrdp_sec_recv_fastpath */
|
2014-03-05 01:56:26 +04:00
|
|
|
*code = 2; // special code for fastpath input
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_rdp_recv: out code 2 (fastpath)");
|
2014-02-10 07:48:03 +04:00
|
|
|
return 0;
|
2014-02-08 22:55:41 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 01:25:49 +04:00
|
|
|
/* not fastpath, do tpkt */
|
2014-03-04 12:19:19 +04:00
|
|
|
chan = 0;
|
|
|
|
error = xrdp_sec_recv(self->sec_layer, s, &chan);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (error == -1) /* special code for send demand active */
|
|
|
|
{
|
|
|
|
s->next_packet = 0;
|
|
|
|
*code = -1;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_rdp_recv: out code -1 (send demand active)");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_recv: xrdp_sec_recv failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((chan != MCS_GLOBAL_CHANNEL) && (chan > 0))
|
|
|
|
{
|
|
|
|
if (chan > MCS_GLOBAL_CHANNEL)
|
|
|
|
{
|
|
|
|
if (xrdp_channel_process(self->sec_layer->chan_layer, s, chan) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_recv: xrdp_channel_process failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-24 08:45:59 +04:00
|
|
|
if (chan != 1)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"xrdp_rdp_recv: Wrong channel Id to be handled "
|
|
|
|
"by xrdp_channel_process, channel id %d", chan);
|
2014-02-24 08:45:59 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
s->next_packet = 0;
|
|
|
|
*code = 0;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_rdp_recv: out code 0 (skip data) "
|
|
|
|
"data processed by channel id %d", chan);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->next_packet = s->p;
|
|
|
|
}
|
|
|
|
else
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_rdp_recv: stream not touched");
|
2012-09-20 07:51:34 +04:00
|
|
|
s->p = s->next_packet;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 6, "Parsing [MS-RDPBCGR] TS_SHARECONTROLHEADER"))
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
s->next_packet = 0;
|
|
|
|
*code = 0;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_recv: out code 0 (skip data) "
|
|
|
|
"bad RDP packet");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint16_le(s, len); /* totalLength */
|
|
|
|
in_uint16_le(s, pdu_code); /* pduType */
|
2012-09-20 07:51:34 +04:00
|
|
|
*code = pdu_code & 0xf;
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint8s(s, 2); /* pduSource */
|
2012-09-20 07:51:34 +04:00
|
|
|
s->next_packet += len;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received header [MS-RDPBCGR] TS_SHARECONTROLHEADER "
|
|
|
|
"totalLength %d, pduType.type %s (%d), pduType.PDUVersion %d, "
|
|
|
|
"pduSource (ignored)", len, PDUTYPE_TO_STR(*code), *code,
|
|
|
|
((pdu_code & 0xfff0) >> 4));
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
}
|
2014-03-06 00:38:17 +04:00
|
|
|
|
2014-02-08 15:34:01 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a [MS-RDPBCGR] Control PDU with for the given pduType with the headers
|
|
|
|
added */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send(struct xrdp_rdp *self, struct stream *s, int pdu_type)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
s_pop_layer(s, rdp_hdr);
|
|
|
|
len = s->end - s->p;
|
2021-02-04 13:11:54 +03:00
|
|
|
|
|
|
|
/* TS_SHARECONTROLHEADER */
|
|
|
|
out_uint16_le(s, len); /* totalLength */
|
|
|
|
out_uint16_le(s, 0x10 | pdu_type); /* pduType */
|
|
|
|
out_uint16_le(s, self->mcs_channel); /* pduSource */
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Adding header [MS-RDPBCGR] TS_SHARECONTROLHEADER "
|
|
|
|
"totalLength %d, pduType.type %s (%d), pduType.PDUVersion %d, "
|
|
|
|
"pduSource %d", len, PDUTYPE_TO_STR(pdu_type & 0xf),
|
|
|
|
pdu_type & 0xf, (((0x10 | pdu_type) & 0xfff0) >> 4),
|
|
|
|
self->mcs_channel);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (xrdp_sec_send(self->sec_layer, s, MCS_GLOBAL_CHANNEL) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send: xrdp_sec_send failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a [MS-RDPBCGR] Data PDU with for the given pduType2 with the headers
|
|
|
|
added and data compressed */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_data(struct xrdp_rdp *self, struct stream *s,
|
2005-06-28 07:11:35 +04:00
|
|
|
int data_pdu_type)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int len;
|
|
|
|
int ctype;
|
|
|
|
int clen;
|
|
|
|
int dlen;
|
|
|
|
int pdulen;
|
|
|
|
int pdutype;
|
|
|
|
int tocomplen;
|
|
|
|
int iso_offset;
|
|
|
|
int mcs_offset;
|
|
|
|
int sec_offset;
|
|
|
|
int rdp_offset;
|
|
|
|
struct stream ls;
|
2012-12-29 10:37:48 +04:00
|
|
|
struct xrdp_mppc_enc *mppc_enc;
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
s_pop_layer(s, rdp_hdr);
|
|
|
|
len = (int)(s->end - s->p);
|
2018-12-12 11:19:18 +03:00
|
|
|
pdutype = 0x10 | PDUTYPE_DATAPDU;
|
2012-09-20 07:51:34 +04:00
|
|
|
pdulen = len;
|
|
|
|
dlen = len;
|
|
|
|
ctype = 0;
|
|
|
|
clen = len;
|
|
|
|
tocomplen = pdulen - 18;
|
|
|
|
|
|
|
|
if (self->client_info.rdp_compression && self->session->up_and_running)
|
2012-04-06 02:40:46 +04:00
|
|
|
{
|
2012-12-29 10:37:48 +04:00
|
|
|
mppc_enc = self->mppc_enc;
|
2012-09-20 07:51:34 +04:00
|
|
|
if (compress_rdp(mppc_enc, (tui8 *)(s->p + 18), tocomplen))
|
|
|
|
{
|
2013-11-07 07:48:22 +04:00
|
|
|
clen = mppc_enc->bytes_in_opb + 18;
|
|
|
|
pdulen = clen;
|
|
|
|
ctype = mppc_enc->flags;
|
|
|
|
iso_offset = (int)(s->iso_hdr - s->data);
|
|
|
|
mcs_offset = (int)(s->mcs_hdr - s->data);
|
|
|
|
sec_offset = (int)(s->sec_hdr - s->data);
|
|
|
|
rdp_offset = (int)(s->rdp_hdr - s->data);
|
|
|
|
|
|
|
|
/* outputBuffer has 64 bytes preceding it */
|
|
|
|
ls.data = mppc_enc->outputBuffer - (rdp_offset + 18);
|
|
|
|
ls.p = ls.data + rdp_offset;
|
|
|
|
ls.end = ls.p + clen;
|
2021-05-19 13:37:22 +03:00
|
|
|
ls.size = s->end - s->data;
|
2013-11-07 07:48:22 +04:00
|
|
|
ls.iso_hdr = ls.data + iso_offset;
|
|
|
|
ls.mcs_hdr = ls.data + mcs_offset;
|
|
|
|
ls.sec_hdr = ls.data + sec_offset;
|
|
|
|
ls.rdp_hdr = ls.data + rdp_offset;
|
|
|
|
ls.channel_hdr = 0;
|
|
|
|
ls.next_packet = 0;
|
|
|
|
s = &ls;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-26 05:48:51 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE,
|
2021-02-04 13:11:54 +03:00
|
|
|
"xrdp_rdp_send_data: compress_rdp failed, sending "
|
|
|
|
"uncompressed data. type %d, flags %d",
|
|
|
|
mppc_enc->protocol_type, mppc_enc->flags);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2012-04-06 02:40:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TS_SHARECONTROLHEADER */
|
|
|
|
out_uint16_le(s, pdulen); /* totalLength */
|
|
|
|
out_uint16_le(s, pdutype); /* pduType */
|
|
|
|
out_uint16_le(s, self->mcs_channel); /* pduSource */
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Adding header [MS-RDPBCGR] TS_SHARECONTROLHEADER "
|
|
|
|
"totalLength %d, pduType.type %s (%d), pduType.PDUVersion %d, "
|
|
|
|
"pduSource %d", pdulen, PDUTYPE_TO_STR(pdutype & 0xf),
|
|
|
|
pdutype & 0xf, ((pdutype & 0xfff0) >> 4), self->mcs_channel);
|
|
|
|
|
|
|
|
/* TS_SHAREDATAHEADER */
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint32_le(s, self->share_id);
|
2021-02-04 13:11:54 +03:00
|
|
|
out_uint8(s, 0); /* pad */
|
|
|
|
out_uint8(s, 1); /* streamID */
|
|
|
|
out_uint16_le(s, dlen); /* uncompressedLength */
|
|
|
|
out_uint8(s, data_pdu_type); /* pduType2 */
|
|
|
|
out_uint8(s, ctype); /* compressedType */
|
|
|
|
out_uint16_le(s, clen); /* compressedLength */
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Adding header [MS-RDPBCGR] TS_SHAREDATAHEADER "
|
|
|
|
"shareID %d, streamID 1, uncompressedLength %d, "
|
|
|
|
"pduType2 0x%2.2x, compressedType 0x%2.2x, compressedLength %d",
|
|
|
|
self->share_id, dlen, data_pdu_type, ctype, clen);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (xrdp_sec_send(self->sec_layer, s, MCS_GLOBAL_CHANNEL) != 0)
|
2012-04-06 02:40:46 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_data: xrdp_sec_send failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
2012-04-06 02:40:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
2014-03-18 11:07:11 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns the fastpath rdp byte count */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-03-18 11:07:11 +04:00
|
|
|
xrdp_rdp_get_fastpath_bytes(struct xrdp_rdp *self)
|
|
|
|
{
|
|
|
|
if (self->client_info.rdp_compression)
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2014-03-08 00:45:33 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-03-08 00:45:33 +04:00
|
|
|
xrdp_rdp_init_fastpath(struct xrdp_rdp *self, struct stream *s)
|
|
|
|
{
|
|
|
|
if (xrdp_sec_init_fastpath(self->sec_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_init_fastpath: xrdp_sec_init_fastpath failed");
|
2014-03-08 00:45:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (self->client_info.rdp_compression)
|
|
|
|
{
|
|
|
|
s_push_layer(s, rdp_hdr, 4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_push_layer(s, rdp_hdr, 3);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2014-03-09 23:11:36 +04:00
|
|
|
/* returns error */
|
|
|
|
/* 2.2.9.1.2.1 Fast-Path Update (TS_FP_UPDATE)
|
|
|
|
* http://msdn.microsoft.com/en-us/library/cc240622.aspx */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-03-08 00:45:33 +04:00
|
|
|
xrdp_rdp_send_fastpath(struct xrdp_rdp *self, struct stream *s,
|
|
|
|
int data_pdu_type)
|
|
|
|
{
|
|
|
|
int updateHeader;
|
2014-03-09 23:11:36 +04:00
|
|
|
int updateCode;
|
|
|
|
int fragmentation;
|
|
|
|
int compression;
|
2014-06-29 07:53:05 +04:00
|
|
|
int comp_type;
|
|
|
|
int comp_len;
|
|
|
|
int no_comp_len;
|
|
|
|
int send_len;
|
2014-03-09 23:11:36 +04:00
|
|
|
int cont;
|
|
|
|
int header_bytes;
|
|
|
|
int sec_bytes;
|
2014-06-29 07:53:05 +04:00
|
|
|
int to_comp_len;
|
|
|
|
int sec_offset;
|
|
|
|
int rdp_offset;
|
|
|
|
struct stream frag_s;
|
|
|
|
struct stream comp_s;
|
2014-07-01 05:22:37 +04:00
|
|
|
struct stream send_s;
|
2014-06-29 07:53:05 +04:00
|
|
|
struct xrdp_mppc_enc *mppc_enc;
|
2021-02-04 13:11:54 +03:00
|
|
|
char comp_type_str[7];
|
|
|
|
comp_type_str[0] = '\0';
|
2014-03-08 00:45:33 +04:00
|
|
|
|
|
|
|
s_pop_layer(s, rdp_hdr);
|
2014-03-09 23:11:36 +04:00
|
|
|
updateCode = data_pdu_type;
|
2014-03-08 00:45:33 +04:00
|
|
|
if (self->client_info.rdp_compression)
|
|
|
|
{
|
2014-03-09 23:11:36 +04:00
|
|
|
compression = 2;
|
|
|
|
header_bytes = 4;
|
2014-03-08 00:45:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-09 23:11:36 +04:00
|
|
|
compression = 0;
|
|
|
|
header_bytes = 3;
|
2014-03-08 00:45:33 +04:00
|
|
|
}
|
2014-03-09 23:11:36 +04:00
|
|
|
sec_bytes = xrdp_sec_get_fastpath_bytes(self->sec_layer);
|
|
|
|
fragmentation = 0;
|
2014-06-29 07:53:05 +04:00
|
|
|
frag_s = *s;
|
|
|
|
sec_offset = (int)(frag_s.sec_hdr - frag_s.data);
|
|
|
|
rdp_offset = (int)(frag_s.rdp_hdr - frag_s.data);
|
2014-03-09 23:11:36 +04:00
|
|
|
cont = 1;
|
|
|
|
while (cont)
|
2014-03-08 00:45:33 +04:00
|
|
|
{
|
2014-06-29 07:53:05 +04:00
|
|
|
comp_type = 0;
|
2014-07-01 05:22:37 +04:00
|
|
|
send_s = frag_s;
|
2014-06-29 07:53:05 +04:00
|
|
|
no_comp_len = (int)(frag_s.end - frag_s.p);
|
|
|
|
if (no_comp_len > FASTPATH_FRAG_SIZE)
|
2014-03-09 23:11:36 +04:00
|
|
|
{
|
2014-06-29 07:53:05 +04:00
|
|
|
no_comp_len = FASTPATH_FRAG_SIZE;
|
2014-03-09 23:11:36 +04:00
|
|
|
if (fragmentation == 0)
|
|
|
|
{
|
|
|
|
fragmentation = 2; /* FASTPATH_FRAGMENT_FIRST */
|
|
|
|
}
|
|
|
|
else if (fragmentation == 2)
|
|
|
|
{
|
|
|
|
fragmentation = 3; /* FASTPATH_FRAGMENT_NEXT */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fragmentation != 0)
|
|
|
|
{
|
|
|
|
fragmentation = 1; /* FASTPATH_FRAGMENT_LAST */
|
|
|
|
}
|
|
|
|
}
|
2014-06-29 07:53:05 +04:00
|
|
|
send_len = no_comp_len;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_rdp_send_fastpath: no_comp_len %d, fragmentation %d",
|
2020-11-30 06:29:57 +03:00
|
|
|
no_comp_len, fragmentation);
|
2014-07-01 05:22:37 +04:00
|
|
|
if ((compression != 0) && (no_comp_len > header_bytes + 16))
|
2014-06-29 07:53:05 +04:00
|
|
|
{
|
|
|
|
to_comp_len = no_comp_len - header_bytes;
|
|
|
|
mppc_enc = self->mppc_enc;
|
|
|
|
if (compress_rdp(mppc_enc, (tui8 *)(frag_s.p + header_bytes),
|
|
|
|
to_comp_len))
|
|
|
|
{
|
|
|
|
comp_len = mppc_enc->bytes_in_opb + header_bytes;
|
|
|
|
send_len = comp_len;
|
|
|
|
comp_type = mppc_enc->flags;
|
|
|
|
/* outputBuffer has 64 bytes preceding it */
|
|
|
|
g_memset(&comp_s, 0, sizeof(comp_s));
|
|
|
|
comp_s.data = mppc_enc->outputBuffer -
|
2020-11-30 06:29:57 +03:00
|
|
|
(rdp_offset + header_bytes);
|
2014-06-29 07:53:05 +04:00
|
|
|
comp_s.p = comp_s.data + rdp_offset;
|
|
|
|
comp_s.end = comp_s.p + send_len;
|
|
|
|
comp_s.size = send_len;
|
|
|
|
comp_s.sec_hdr = comp_s.data + sec_offset;
|
|
|
|
comp_s.rdp_hdr = comp_s.data + rdp_offset;
|
2014-07-01 05:22:37 +04:00
|
|
|
send_s = comp_s;
|
2014-06-29 07:53:05 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"compress_rdp failed, sending uncompressed data. "
|
|
|
|
"type %d, flags %d", mppc_enc->protocol_type,
|
|
|
|
mppc_enc->flags);
|
2014-06-29 07:53:05 +04:00
|
|
|
}
|
|
|
|
}
|
2014-03-09 23:11:36 +04:00
|
|
|
updateHeader = (updateCode & 15) |
|
2020-11-30 06:29:57 +03:00
|
|
|
((fragmentation & 3) << 4) |
|
|
|
|
((compression & 3) << 6);
|
2021-12-02 16:47:09 +03:00
|
|
|
|
|
|
|
send_s.end = send_s.p + send_len;
|
|
|
|
send_s.size = send_s.end - send_s.data;
|
2014-07-01 05:22:37 +04:00
|
|
|
out_uint8(&send_s, updateHeader);
|
2014-03-09 23:11:36 +04:00
|
|
|
if (compression != 0)
|
|
|
|
{
|
2014-07-01 05:22:37 +04:00
|
|
|
out_uint8(&send_s, comp_type);
|
2021-02-04 13:11:54 +03:00
|
|
|
g_snprintf(comp_type_str, 7, "0x%4.4x", comp_type);
|
2014-03-09 23:11:36 +04:00
|
|
|
}
|
2014-06-29 07:53:05 +04:00
|
|
|
send_len -= header_bytes;
|
2014-07-01 05:22:37 +04:00
|
|
|
out_uint16_le(&send_s, send_len);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Adding header [MS-RDPBCGR] TS_FP_UPDATE "
|
|
|
|
"updateCode %d, fragmentation %d, compression %d, compressionFlags %s, size %d",
|
|
|
|
updateCode, fragmentation, compression,
|
|
|
|
(compression ? comp_type_str : "(not present)"), send_len);
|
2014-07-01 05:22:37 +04:00
|
|
|
if (xrdp_sec_send_fastpath(self->sec_layer, &send_s) != 0)
|
2014-03-09 23:11:36 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_fastpath: xrdp_sec_send_fastpath failed");
|
2014-03-09 23:11:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2014-07-01 05:22:37 +04:00
|
|
|
frag_s.p += no_comp_len;
|
2014-06-29 07:53:05 +04:00
|
|
|
cont = frag_s.p < frag_s.end;
|
|
|
|
frag_s.p -= header_bytes;
|
|
|
|
frag_s.sec_hdr = frag_s.p - sec_bytes;
|
|
|
|
frag_s.data = frag_s.sec_hdr;
|
2014-03-08 00:45:33 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-09 02:04:18 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a [MS-RDPBCGR] TS_UPDATE_SYNC or TS_FP_UPDATE_SYNCHRONIZE message
|
|
|
|
depending on if the client supports the fast path capability or not */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_data_update_sync(struct xrdp_rdp *self)
|
2007-04-09 02:04:18 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s = (struct stream *)NULL;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
2014-03-15 18:10:20 +04:00
|
|
|
if (self->client_info.use_fast_path & 1) /* fastpath output supported */
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2014-03-15 18:10:20 +04:00
|
|
|
if (xrdp_rdp_init_fastpath(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_data_update_sync: xrdp_rdp_init_fastpath failed");
|
2014-07-20 00:25:23 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
2014-03-15 18:10:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* slowpath */
|
|
|
|
{
|
|
|
|
if (xrdp_rdp_init_data(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_data_update_sync: xrdp_rdp_init_data failed");
|
2014-03-15 18:10:20 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
out_uint16_le(s, RDP_UPDATE_SYNCHRONIZE); /* updateType */
|
2016-12-27 10:53:53 +03:00
|
|
|
out_uint16_le(s, 0); /* pad */
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
s_mark_end(s);
|
|
|
|
|
2014-03-15 18:10:20 +04:00
|
|
|
if (self->client_info.use_fast_path & 1) /* fastpath output supported */
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_FP_UPDATE_SYNCHRONIZE");
|
2014-03-15 18:10:20 +04:00
|
|
|
if (xrdp_rdp_send_fastpath(self, s,
|
|
|
|
FASTPATH_UPDATETYPE_SYNCHRONIZE) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Sending [MS-RDPBCGR] TS_FP_UPDATE_SYNCHRONIZE failed");
|
2014-07-20 00:25:23 +04:00
|
|
|
free_stream(s);
|
2014-03-15 18:10:20 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* slowpath */
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_UPDATE_SYNC "
|
|
|
|
"updateType %s (%d)",
|
|
|
|
GRAPHICS_UPDATE_TYPE_TO_STR(RDP_UPDATE_SYNCHRONIZE),
|
|
|
|
RDP_UPDATE_SYNCHRONIZE);
|
2014-03-15 18:10:20 +04:00
|
|
|
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_UPDATE) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Sending [MS-RDPBCGR] TS_UPDATE_SYNC failed");
|
2014-03-15 18:10:20 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2007-04-09 02:04:18 +04:00
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2007-04-09 02:04:18 +04:00
|
|
|
}
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_incoming(struct xrdp_rdp *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2016-09-09 09:42:04 +03:00
|
|
|
struct xrdp_iso *iso;
|
2022-04-22 13:56:23 +03:00
|
|
|
|
2016-09-09 09:42:04 +03:00
|
|
|
iso = self->sec_layer->mcs_layer->iso_layer;
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (xrdp_sec_incoming(self->sec_layer) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_incoming: xrdp_sec_incoming failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
self->mcs_channel = self->sec_layer->mcs_layer->userid +
|
|
|
|
MCS_USERCHANNEL_BASE;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_rdp->mcs_channel %d", self->mcs_channel);
|
2016-09-09 09:42:04 +03:00
|
|
|
|
2017-03-08 06:57:19 +03:00
|
|
|
/* log TLS version and cipher of TLS connections */
|
2016-09-09 09:42:04 +03:00
|
|
|
if (iso->selectedProtocol > PROTOCOL_RDP)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_INFO,
|
2022-04-22 13:56:23 +03:00
|
|
|
"TLS connection established from %s %s with cipher %s",
|
|
|
|
self->client_info.client_description,
|
2020-11-30 06:29:57 +03:00
|
|
|
iso->trans->ssl_protocol,
|
|
|
|
iso->trans->cipher_name);
|
2016-09-09 09:42:04 +03:00
|
|
|
}
|
2017-03-08 06:57:19 +03:00
|
|
|
/* log non-TLS connections */
|
2016-10-11 06:53:17 +03:00
|
|
|
else
|
|
|
|
{
|
2022-01-28 15:17:38 +03:00
|
|
|
int crypt_level = self->sec_layer->crypt_level;
|
|
|
|
const char *security_level =
|
|
|
|
(crypt_level == CRYPT_LEVEL_NONE) ? "none" :
|
|
|
|
(crypt_level == CRYPT_LEVEL_LOW) ? "low" :
|
|
|
|
(crypt_level == CRYPT_LEVEL_CLIENT_COMPATIBLE) ? "medium" :
|
|
|
|
(crypt_level == CRYPT_LEVEL_HIGH) ? "high" :
|
|
|
|
(crypt_level == CRYPT_LEVEL_FIPS) ? "fips" :
|
|
|
|
/* default */ "unknown";
|
|
|
|
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_INFO,
|
2022-04-22 13:56:23 +03:00
|
|
|
"Non-TLS connection established from %s with security level : %s",
|
|
|
|
self->client_info.client_description, security_level);
|
2016-10-11 06:53:17 +03:00
|
|
|
}
|
2016-09-09 09:42:04 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_POINTER_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_data_pointer(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING, "Protocol error ignored: a [MS-RDPBCGR] "
|
|
|
|
"TS_SHAREDATAHEADER PDUTYPE2_POINTER was received by the server "
|
|
|
|
"but this type of PDU is only suppose to be sent by the server "
|
|
|
|
"to the client.");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_INPUT_PDU_DATA message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_data_input(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int num_events;
|
|
|
|
int index;
|
|
|
|
int msg_type;
|
|
|
|
int device_flags;
|
|
|
|
int param1;
|
|
|
|
int param2;
|
|
|
|
int time;
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPBCGR] TS_INPUT_PDU_DATA"))
|
2013-09-11 03:20:11 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, num_events);
|
|
|
|
in_uint8s(s, 2); /* pad */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_INPUT_PDU_DATA "
|
|
|
|
"numEvents %d", num_events);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
for (index = 0; index < num_events; index++)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 12, "Parsing [MS-RDPBCGR] TS_INPUT_EVENT"))
|
2013-09-11 03:20:11 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint32_le(s, time);
|
|
|
|
in_uint16_le(s, msg_type);
|
|
|
|
in_uint16_le(s, device_flags);
|
|
|
|
in_sint16_le(s, param1);
|
|
|
|
in_sint16_le(s, param2);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "With field [MS-RDPBCGR] TS_INPUT_EVENT "
|
|
|
|
"eventTime %d, messageType 0x%4.4x", time, msg_type);
|
|
|
|
|
|
|
|
switch (msg_type)
|
|
|
|
{
|
|
|
|
case RDP_INPUT_SYNCHRONIZE:
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_SYNC_EVENT "
|
|
|
|
"toggleFlags 0x%8.8x", ((param2 << 16) | param1));
|
|
|
|
break;
|
|
|
|
case RDP_INPUT_SCANCODE:
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_KEYBOARD_EVENT "
|
|
|
|
"keyboardFlags 0x%4.4x, keyCode %d", device_flags, param1);
|
|
|
|
break;
|
|
|
|
case RDP_INPUT_UNICODE:
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_UNICODE_KEYBOARD_EVENT "
|
|
|
|
"keyboardFlags 0x%4.4x, unicodeCode %d", device_flags, param1);
|
|
|
|
break;
|
|
|
|
case RDP_INPUT_MOUSE:
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_POINTER_EVENT "
|
|
|
|
"pointerFlags 0x%4.4x, xPos %d, yPos %d",
|
|
|
|
device_flags, param1, param2);
|
|
|
|
break;
|
|
|
|
case RDP_INPUT_MOUSEX:
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "With field [MS-RDPBCGR] TS_INPUT_EVENT - TS_POINTERX_EVENT "
|
|
|
|
"pointerFlags 0x%4.4x, xPos %d, yPos %d",
|
|
|
|
device_flags, param1, param2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING, "Received unknown [MS-RDPBCGR] TS_INPUT_EVENT "
|
|
|
|
"messageType 0x%4.4x", msg_type);
|
|
|
|
break;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (self->session->callback != 0)
|
|
|
|
{
|
|
|
|
/* msg_type can be
|
|
|
|
RDP_INPUT_SYNCHRONIZE - 0
|
|
|
|
RDP_INPUT_SCANCODE - 4
|
2013-08-08 08:02:22 +04:00
|
|
|
RDP_INPUT_MOUSE - 0x8001
|
|
|
|
RDP_INPUT_MOUSEX - 0x8002 */
|
2012-09-20 07:51:34 +04:00
|
|
|
/* call to xrdp_wm.c : callback */
|
|
|
|
self->session->callback(self->session->id, msg_type, param1, param2,
|
|
|
|
device_flags, time);
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"Bug: no callback registered for xrdp_rdp_process_data_input");
|
|
|
|
}
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Processing [MS-RDPBCGR] TS_INPUT_PDU_DATA complete");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a [MS-RDPBCGR] TS_SYNCHRONIZE_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_synchronise(struct xrdp_rdp *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_rdp_init_data(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_synchronise: xrdp_rdp_init_data failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-15 18:10:20 +04:00
|
|
|
out_uint16_le(s, 1); /* messageType (2 bytes) */
|
|
|
|
out_uint16_le(s, 1002); /* targetUser (2 bytes) */
|
2012-09-20 07:51:34 +04:00
|
|
|
s_mark_end(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_SYNCHRONIZE_PDU "
|
|
|
|
"messageType 1, targetUser 1002");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_SYNCHRONISE) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Sending [MS-RDPBCGR] TS_SYNCHRONIZE_PDU failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-06-28 07:11:35 +04:00
|
|
|
|
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a [MS-RDPBCGR] TS_CONTROL_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_control(struct xrdp_rdp *self, int action)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_rdp_init_data(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_control: xrdp_rdp_init_data failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_uint16_le(s, action);
|
|
|
|
out_uint16_le(s, 0); /* userid */
|
|
|
|
out_uint32_le(s, 1002); /* control id */
|
|
|
|
s_mark_end(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_CONTROL_PDU "
|
|
|
|
"action %d, grantId 0, controlId 1002", action);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_CONTROL) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Sending [MS-RDPBCGR] TS_CONTROL_PDU failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-06-28 07:11:35 +04:00
|
|
|
|
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_CONTROL_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_data_control(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int action;
|
|
|
|
|
|
|
|
in_uint16_le(s, action);
|
|
|
|
in_uint8s(s, 2); /* user id */
|
|
|
|
in_uint8s(s, 4); /* control id */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_CONTROL_PDU "
|
|
|
|
"action 0x%4.4x, grantId (ignored), controlId (ignored)",
|
|
|
|
action);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (action == RDP_CTL_REQUEST_CONTROL)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Responding to [MS-RDPBCGR] TS_CONTROL_PDU "
|
|
|
|
"action CTRLACTION_REQUEST_CONTROL with 3 messages: "
|
|
|
|
"TS_SYNCHRONIZE_PDU, TS_CONTROL_PDU with CTRLACTION_COOPERATE, "
|
|
|
|
" and TS_CONTROL_PDU with CTRLACTION_GRANTED_CONTROL");
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_synchronise(self);
|
|
|
|
xrdp_rdp_send_control(self, RDP_CTL_COOPERATE);
|
|
|
|
xrdp_rdp_send_control(self, RDP_CTL_GRANT_CONTROL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING, "Received [MS-RDPBCGR] TS_CONTROL_PDU "
|
|
|
|
"action %d is unknown (skipped)", action);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_SYNCHRONIZE_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_data_sync(struct xrdp_rdp *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_SYNCHRONIZE_PDU - no-op");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2019-11-07 05:03:57 +03:00
|
|
|
/* 2.2.11.2.1 Refresh Rect PDU Data (TS_REFRESH_RECT_PDU) */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_screen_update(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2019-11-07 05:03:57 +03:00
|
|
|
int index;
|
|
|
|
int num_rects;
|
2012-09-20 07:51:34 +04:00
|
|
|
int left;
|
|
|
|
int top;
|
|
|
|
int right;
|
|
|
|
int bottom;
|
|
|
|
int cx;
|
|
|
|
int cy;
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPBCGR] TS_REFRESH_RECT_PDU"))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2019-11-07 05:03:57 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint8(s, num_rects);
|
|
|
|
in_uint8s(s, 3); /* pad */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_REFRESH_RECT_PDU "
|
|
|
|
"numberOfAreas %d", num_rects);
|
2019-11-07 05:03:57 +03:00
|
|
|
for (index = 0; index < num_rects; index++)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 8, "Parsing [MS-RDPBCGR] TS_RECTANGLE16"))
|
2019-11-07 05:03:57 +03:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Inclusive Rectangle (TS_RECTANGLE16) */
|
|
|
|
in_uint16_le(s, left);
|
|
|
|
in_uint16_le(s, top);
|
|
|
|
in_uint16_le(s, right);
|
|
|
|
in_uint16_le(s, bottom);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "With field [MS-RDPBCGR] TS_RECTANGLE16 "
|
|
|
|
"left %d, top %d, right %d, bottom %d",
|
2019-11-07 05:03:57 +03:00
|
|
|
left, top, right, bottom);
|
|
|
|
cx = (right - left) + 1;
|
|
|
|
cy = (bottom - top) + 1;
|
|
|
|
if (self->session->callback != 0)
|
|
|
|
{
|
|
|
|
self->session->callback(self->session->id, 0x4444,
|
|
|
|
left, top, cx, cy);
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"Bug: no callback registered for xrdp_rdp_process_screen_update");
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a [MS-RDPBCGR] TS_FONT_MAP_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2013-11-17 19:50:40 +04:00
|
|
|
xrdp_rdp_send_fontmap(struct xrdp_rdp *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_rdp_init_data(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"xrdp_rdp_send_fontmap: xrdp_rdp_init_data failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-17 19:50:40 +04:00
|
|
|
out_uint16_le(s, 0); /* numberEntries */
|
|
|
|
out_uint16_le(s, 0); /* totalNumEntries */
|
|
|
|
out_uint16_le(s, 0x3); /* mapFlags (sequence flags) */
|
|
|
|
out_uint16_le(s, 0x4); /* entrySize */
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
s_mark_end(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_FONT_MAP_PDU "
|
|
|
|
"numberEntries 0, totalNumEntries 0, mapFlags 0x0003, entrySize 4");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (xrdp_rdp_send_data(self, s, 0x28) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Sending [MS-RDPBCGR] TS_FONT_MAP_PDU failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-06-28 07:11:35 +04:00
|
|
|
|
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2014-03-08 00:45:33 +04:00
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_FONT_LIST_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int seq;
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 6, "Parsing [MS-RDPBCGR] TS_FONT_LIST_PDU"))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-17 18:56:27 +04:00
|
|
|
in_uint8s(s, 2); /* NumberFonts: 0x0, SHOULD be set to 0 */
|
|
|
|
in_uint8s(s, 2); /* TotalNumberFonts: 0x0, SHOULD be set to 0 */
|
|
|
|
in_uint16_le(s, seq); /* ListFlags */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_FONT_LIST_PDU "
|
|
|
|
"numberFonts (ignored), totalNumFonts (ignored), listFlags 0x%4.4x",
|
|
|
|
seq);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* 419 client sends Seq 1, then 2 */
|
|
|
|
/* 2600 clients sends only Seq 3 */
|
2021-02-04 13:11:54 +03:00
|
|
|
/* listFlags SHOULD be set to 0x0003, which is the logical OR'd value of
|
|
|
|
FONTLIST_FIRST (0x0001) and FONTLIST_LAST (0x0002) */
|
2012-09-20 07:51:34 +04:00
|
|
|
if (seq == 2 || seq == 3) /* after second font message, we are up and */
|
|
|
|
{
|
|
|
|
/* running */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG,
|
|
|
|
"Client sent FONTLIST_LAST, replying with server fontmap");
|
2013-11-17 19:50:40 +04:00
|
|
|
xrdp_rdp_send_fontmap(self);
|
2013-11-17 18:56:27 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
self->session->up_and_running = 1;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "yeah, up_and_running");
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_data_update_sync(self);
|
2018-10-12 08:09:20 +03:00
|
|
|
xrdp_channel_drdynvc_start(self->sec_layer->chan_layer);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Received [MS-RDPBCGR] TS_FONT_LIST_PDU "
|
|
|
|
"without FONTLIST_LAST in the listFlags field. Ignoring message.");
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a Sending [MS-RDPBCGR] TS_SHUTDOWN_DENIED_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_disconnect_query_response(struct xrdp_rdp *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_rdp_init_data(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"xrdp_rdp_send_disconnect_query_response: xrdp_rdp_init_data failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_mark_end(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_SHUTDOWN_DENIED_PDU");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (xrdp_rdp_send_data(self, s, PDUTYPE2_SHUTDOWN_DENIED) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Sending [MS-RDPBCGR] TS_SHUTDOWN_DENIED_PDU failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-06-28 07:11:35 +04:00
|
|
|
|
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* not used */
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Send a [MS-RDPBCGR] TS_SET_ERROR_INFO_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_disconnect_reason(struct xrdp_rdp *self, int reason)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_rdp_init_data(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"xrdp_rdp_send_disconnect_reason: xrdp_rdp_init_data failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_uint32_le(s, reason);
|
|
|
|
s_mark_end(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_SET_ERROR_INFO_PDU "
|
|
|
|
"errorInfo 0x%8.8x", reason);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_DISCONNECT) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Sending [MS-RDPBCGR] TS_SET_ERROR_INFO_PDU failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-06-28 07:11:35 +04:00
|
|
|
|
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-29 04:34:25 +03:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPRFX] TS_FRAME_ACKNOWLEDGE_PDU message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2015-03-29 04:34:25 +03:00
|
|
|
xrdp_rdp_process_frame_ack(struct xrdp_rdp *self, struct stream *s)
|
|
|
|
{
|
|
|
|
int frame_id;
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPRFX] TS_FRAME_ACKNOWLEDGE_PDU"))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2015-03-29 04:34:25 +03:00
|
|
|
in_uint32_le(s, frame_id);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPRFX] TS_FRAME_ACKNOWLEDGE_PDU "
|
|
|
|
"frameID %d", frame_id);
|
2015-03-29 04:34:25 +03:00
|
|
|
if (self->session->callback != 0)
|
|
|
|
{
|
|
|
|
/* call to xrdp_wm.c : callback */
|
|
|
|
self->session->callback(self->session->id, 0x5557, frame_id, 0,
|
|
|
|
0, 0);
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"Bug: no callback registered for xrdp_rdp_process_frame_ack");
|
|
|
|
}
|
2015-03-29 04:34:25 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-02 10:19:57 +03:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_SUPPRESS_OUTPUT_PDU message */
|
2019-04-02 10:19:57 +03:00
|
|
|
static int
|
|
|
|
xrdp_rdp_process_suppress(struct xrdp_rdp *self, struct stream *s)
|
|
|
|
{
|
|
|
|
int allowDisplayUpdates;
|
2019-04-04 05:42:16 +03:00
|
|
|
int left;
|
|
|
|
int top;
|
|
|
|
int right;
|
|
|
|
int bottom;
|
2019-04-02 10:19:57 +03:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 1, "Parsing [MS-RDPBCGR] TS_SUPPRESS_OUTPUT_PDU"))
|
2019-04-02 10:19:57 +03:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2019-04-04 05:42:16 +03:00
|
|
|
in_uint8(s, allowDisplayUpdates);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_SUPPRESS_OUTPUT_PDU "
|
|
|
|
"allowDisplayUpdates %d", allowDisplayUpdates);
|
2019-04-02 10:19:57 +03:00
|
|
|
switch (allowDisplayUpdates)
|
|
|
|
{
|
|
|
|
case 0: /* SUPPRESS_DISPLAY_UPDATES */
|
|
|
|
self->client_info.suppress_output = 1;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Client requested display output to be suppressed");
|
2019-04-08 03:56:05 +03:00
|
|
|
if (self->session->callback != 0)
|
|
|
|
{
|
|
|
|
self->session->callback(self->session->id, 0x5559, 1,
|
|
|
|
0, 0, 0);
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"Bug: no callback registered for xrdp_rdp_process_suppress");
|
|
|
|
}
|
2019-04-02 10:19:57 +03:00
|
|
|
break;
|
|
|
|
case 1: /* ALLOW_DISPLAY_UPDATES */
|
|
|
|
self->client_info.suppress_output = 0;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Client requested display output to be enabled");
|
|
|
|
if (!s_check_rem_and_log(s, 11, "Parsing [MS-RDPBCGR] Padding and TS_RECTANGLE16"))
|
2019-04-02 10:19:57 +03:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 3); /* pad */
|
2019-04-04 05:42:16 +03:00
|
|
|
in_uint16_le(s, left);
|
|
|
|
in_uint16_le(s, top);
|
|
|
|
in_uint16_le(s, right);
|
|
|
|
in_uint16_le(s, bottom);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_RECTANGLE16 "
|
|
|
|
"left %d, top %d, right %d, bottom %d",
|
2019-04-04 05:42:16 +03:00
|
|
|
left, top, right, bottom);
|
|
|
|
if (self->session->callback != 0)
|
|
|
|
{
|
2019-04-08 03:56:05 +03:00
|
|
|
self->session->callback(self->session->id, 0x5559, 0,
|
|
|
|
MAKELONG(left, top),
|
|
|
|
MAKELONG(right, bottom), 0);
|
2019-04-04 05:42:16 +03:00
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"Bug: no callback registered for xrdp_rdp_process_suppress");
|
|
|
|
}
|
2019-04-02 10:19:57 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_SHAREDATAHEADER message based on it's pduType2 */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_data(struct xrdp_rdp *self, struct stream *s)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2019-04-04 05:42:16 +03:00
|
|
|
int uncompressedLength;
|
|
|
|
int pduType2;
|
|
|
|
int compressedType;
|
|
|
|
int compressedLength;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 12, "Parsing [MS-RDPBCGR] TS_SHAREDATAHEADER"))
|
2019-04-04 05:42:16 +03:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint8s(s, 6); /* shareID (4 bytes), padding (1 byte), streamID (1 byte) */
|
|
|
|
in_uint16_le(s, uncompressedLength); /* shareID */
|
2019-04-04 05:42:16 +03:00
|
|
|
in_uint8(s, pduType2);
|
|
|
|
in_uint8(s, compressedType);
|
|
|
|
in_uint16_le(s, compressedLength);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_SHAREDATAHEADER "
|
|
|
|
"shareID (ignored), streamID (ignored), uncompressedLength %d, "
|
|
|
|
"pduType2 0x%2.2x, compressedType 0x%2.2x, compressedLength %d",
|
|
|
|
uncompressedLength, pduType2, compressedType, compressedLength);
|
|
|
|
|
2019-04-04 05:42:16 +03:00
|
|
|
if (compressedType != 0)
|
|
|
|
{
|
|
|
|
/* don't support compression */
|
2021-02-04 13:11:54 +03:00
|
|
|
/* PACKET_COMPR_TYPE_8K = 0x00 */
|
|
|
|
LOG(LOG_LEVEL_ERROR, "Only RDP 4.0 bulk compression "
|
|
|
|
"(PACKET_COMPR_TYPE_8K) is supported by XRDP");
|
2019-04-04 05:42:16 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (compressedLength > uncompressedLength)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "The compressed length %d is larger than "
|
|
|
|
"the uncompressed length %d, failing the processing of this "
|
|
|
|
"PDU", compressedLength, uncompressedLength);
|
2019-04-04 05:42:16 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2019-04-04 05:42:16 +03:00
|
|
|
switch (pduType2)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
case RDP_DATA_PDU_POINTER: /* 27(0x1b) */
|
|
|
|
xrdp_rdp_process_data_pointer(self, s);
|
|
|
|
break;
|
|
|
|
case RDP_DATA_PDU_INPUT: /* 28(0x1c) */
|
|
|
|
xrdp_rdp_process_data_input(self, s);
|
|
|
|
break;
|
|
|
|
case RDP_DATA_PDU_CONTROL: /* 20(0x14) */
|
|
|
|
xrdp_rdp_process_data_control(self, s);
|
|
|
|
break;
|
|
|
|
case RDP_DATA_PDU_SYNCHRONISE: /* 31(0x1f) */
|
|
|
|
xrdp_rdp_process_data_sync(self);
|
|
|
|
break;
|
2019-11-07 05:03:57 +03:00
|
|
|
case PDUTYPE2_REFRESH_RECT:
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_process_screen_update(self, s);
|
|
|
|
break;
|
2021-02-04 13:11:54 +03:00
|
|
|
case PDUTYPE2_SUPPRESS_OUTPUT: /* 35(0x23) */
|
2019-04-02 10:19:57 +03:00
|
|
|
xrdp_rdp_process_suppress(self, s);
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
2021-02-04 13:11:54 +03:00
|
|
|
case PDUTYPE2_SHUTDOWN_REQUEST: /* 36(0x24) ?? disconnect query? */
|
2012-09-20 07:51:34 +04:00
|
|
|
/* when this message comes, send a 37 back so the client */
|
|
|
|
/* is sure the connection is alive and it can ask if user */
|
|
|
|
/* really wants to disconnect */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_SHUTDOWN_REQ_PDU");
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_send_disconnect_query_response(self); /* send a 37 back */
|
|
|
|
break;
|
|
|
|
case RDP_DATA_PDU_FONT2: /* 39(0x27) */
|
|
|
|
xrdp_rdp_process_data_font(self, s);
|
|
|
|
break;
|
2015-03-29 04:34:25 +03:00
|
|
|
case 56: /* PDUTYPE2_FRAME_ACKNOWLEDGE 0x38 */
|
|
|
|
xrdp_rdp_process_frame_ack(self, s);
|
|
|
|
break;
|
2012-09-20 07:51:34 +04:00
|
|
|
default:
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING,
|
|
|
|
"Received unknown [MS-RDPBCGR] TS_SHAREDATAHEADER pduType2 %d (ignoring)",
|
|
|
|
pduType2);
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_rdp_disconnect(struct xrdp_rdp *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
return xrdp_sec_disconnect(self->sec_layer);
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2005-08-24 05:09:33 +04:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2016-05-03 23:07:13 +03:00
|
|
|
xrdp_rdp_send_deactivate(struct xrdp_rdp *self)
|
2005-08-24 05:09:33 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_rdp_init(self, s) != 0)
|
|
|
|
{
|
|
|
|
free_stream(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_deactivate: xrdp_rdp_init failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TODO: why are all the fields missing from the TS_DEACTIVATE_ALL_PDU? */
|
2012-09-20 07:51:34 +04:00
|
|
|
s_mark_end(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_DEACTIVATE_ALL_PDU "
|
|
|
|
"shareID <not set>, lengthSourceDescriptor <not set>, "
|
|
|
|
"sourceDescriptor <not set>");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2018-12-12 11:19:18 +03:00
|
|
|
if (xrdp_rdp_send(self, s, PDUTYPE_DEACTIVATEALLPDU) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
free_stream(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Sending [MS-RDPBCGR] TS_DEACTIVATE_ALL_PDU failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2005-08-24 05:09:33 +04:00
|
|
|
|
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-08-24 05:09:33 +04:00
|
|
|
}
|
2016-07-18 09:28:37 +03:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/** Send a [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA message.
|
|
|
|
*
|
|
|
|
* @param self
|
|
|
|
* @param data the data to send to the client in the
|
|
|
|
* TS_SAVE_SESSION_INFO_PDU_DATA message. The first 4 bytes of the data
|
|
|
|
* buffer MUST by the infoType value as specified in MS-RDPBCGR 2.2.10.1.1
|
|
|
|
* @param data_bytes the length of the data buffer
|
|
|
|
* @returns error code
|
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2016-07-18 09:28:37 +03:00
|
|
|
xrdp_rdp_send_session_info(struct xrdp_rdp *self, const char *data,
|
|
|
|
int data_bytes)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (data == NULL)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "data must not be null");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (data_bytes < 4)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "data_bytes must greater than or equal to 4");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-18 09:28:37 +03:00
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_rdp_init_data(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_rdp_send_session_info: xrdp_rdp_init_data failed");
|
2016-07-18 09:28:37 +03:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_out_and_log(s, data_bytes, "Sending [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA"))
|
2016-07-18 09:28:37 +03:00
|
|
|
{
|
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
out_uint8a(s, data, data_bytes);
|
2016-07-18 09:28:37 +03:00
|
|
|
s_mark_end(s);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA "
|
|
|
|
"infoType 0x%8.8x, infoData <omitted from log>",
|
|
|
|
*((unsigned int *) data));
|
2016-07-18 09:28:37 +03:00
|
|
|
|
2017-01-15 09:51:43 +03:00
|
|
|
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_LOGON) != 0)
|
2016-07-18 09:28:37 +03:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Sending [MS-RDPBCGR] TS_SAVE_SESSION_INFO_PDU_DATA failed");
|
2016-07-18 09:28:37 +03:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_stream(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|