Skip to content

Commit c6f2154

Browse files
committed
parse monitor/display info
1 parent 62befaa commit c6f2154

File tree

3 files changed

+109
-4
lines changed

3 files changed

+109
-4
lines changed

common/ms-rdpbcgr.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#define SEC_TAG_CLI_CHANNELS 0xc003 /* CS_CHANNELS? */
5858
#define SEC_TAG_CLI_4 0xc004 /* CS_CLUSTER? */
5959
#define SEC_TAG_CLI_MONITOR 0xc005 /* CS_MONITOR */
60+
#define SEC_TAG_CLI_MONITOR_EX 0xc008 /* CS_MONITOR_EX */
6061

6162
/* Client Core Data: colorDepth, postBeta2ColorDepth (2.2.1.3.2) */
6263
#define RNS_UD_COLOR_4BPP 0xCA00

common/xrdp_client_info.h

+14
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@
2323
#if !defined(XRDP_CLIENT_INFO_H)
2424
#define XRDP_CLIENT_INFO_H
2525

26+
/* 2.2.1.3.6.1 Monitor Definition (TS_MONITOR_DEF)
27+
* 2.2.1.3.9.1 Monitor Attributes (TS_MONITOR_ATTRIBUTES)
28+
*/
2629
struct monitor_info
2730
{
2831
int left;
2932
int top;
3033
int right;
3134
int bottom;
3235
int is_primary;
36+
int physical_width;
37+
int physical_height;
38+
int orientation;
39+
int desktop_scale_factor;
40+
int device_scale_factor;
3341
};
3442

3543
struct xrdp_client_info
@@ -162,6 +170,12 @@ struct xrdp_client_info
162170

163171
int enable_token_login;
164172
char domain_user_separator[16];
173+
174+
int physical_width;
175+
int physical_height;
176+
int orientation;
177+
int desktop_scale_factor;
178+
int device_scale_factor;
165179
};
166180

167181
#endif

libxrdp/xrdp_sec.c

+94-4
Original file line numberDiff line numberDiff line change
@@ -1744,19 +1744,31 @@ xrdp_sec_process_mcs_data_CS_CORE(struct xrdp_sec* self, struct stream* s)
17441744
{
17451745
return 0;
17461746
}
1747-
in_uint8s(s, 4); /* desktopPhysicalWidth */
1747+
in_uint32_le(s, self->rdp_layer->client_info.physical_width); /* desktopPhysicalWidth */
17481748

17491749
if (!s_check_rem(s, 4))
17501750
{
17511751
return 0;
17521752
}
1753-
in_uint8s(s, 4); /* desktopPhysicalHeight */
1753+
in_uint32_le(s, self->rdp_layer->client_info.physical_height); /* desktopPhysicalHeight */
17541754

17551755
if (!s_check_rem(s, 2))
17561756
{
17571757
return 0;
17581758
}
1759-
in_uint8s(s, 2); /* reserved */
1759+
in_uint16_le(s, self->rdp_layer->client_info.orientation); /* desktopOrientation */
1760+
1761+
if (!s_check_rem(s, 4))
1762+
{
1763+
return 0;
1764+
}
1765+
in_uint32_le(s, self->rdp_layer->client_info.desktop_scale_factor);
1766+
1767+
if (!s_check_rem(s, 4))
1768+
{
1769+
return 0;
1770+
}
1771+
in_uint32_le(s, self->rdp_layer->client_info.device_scale_factor);
17601772

17611773
return 0;
17621774
}
@@ -2046,6 +2058,79 @@ xrdp_sec_process_mcs_data_monitors(struct xrdp_sec *self, struct stream *s)
20462058
return 0;
20472059
}
20482060

2061+
static int
2062+
xrdp_sec_process_msc_data_monitorex(struct xrdp_sec *self, struct stream* s)
2063+
{
2064+
uint32_t flags;
2065+
uint32_t size;
2066+
uint32_t count;
2067+
uint32_t index;
2068+
struct xrdp_client_info *client_info = &self->rdp_layer->client_info;
2069+
2070+
if (client_info->multimon != 1) {
2071+
LLOGLN(0, ("[INFO] xrdp_sec_process_msc_data_monitorex: multimon is not "
2072+
"allowed, skipping"));
2073+
return 0;
2074+
}
2075+
in_uint32_le(s, flags);
2076+
if (flags != 0) {
2077+
LLOGLN(0, ("[ERROR] xrdp_sec_process_msc_data_monitorex: flags MUST be "
2078+
"zero, detected: 0x%x", flags));
2079+
return 1;
2080+
}
2081+
in_uint32_le(s, size);
2082+
if (size != 20) {
2083+
LLOGLN(0, ("[ERROR] xrdp_sec_process_msc_data_monitorex: monitorAttributeSize MUST be "
2084+
"20, detected: %u", size));
2085+
return 1;
2086+
}
2087+
in_uint32_le(s, count);
2088+
if (count > 16)
2089+
{
2090+
LLOGLN(0, ("[ERROR] xrdp_sec_process_msc_data_monitorex: max allowed "
2091+
"monitors is 16, detected: %d", count));
2092+
return 1;
2093+
}
2094+
2095+
for (index = 0; index < count; index++)
2096+
{
2097+
in_uint32_le(s, client_info->minfo[index].physical_width);
2098+
if (client_info->minfo[index].physical_width < 10 ||
2099+
client_info->minfo[index].physical_width > 10000) {
2100+
LLOGLN(0, ("[INFO] xrdp_sec_process_msc_data_monitorex: ignore "
2101+
"invalid physical_width: %d",
2102+
client_info->minfo[index].physical_width));
2103+
client_info->minfo[index].physical_width = 0;
2104+
}
2105+
in_uint32_le(s, client_info->minfo[index].physical_height);
2106+
if (client_info->minfo[index].physical_height < 10 ||
2107+
client_info->minfo[index].physical_height > 10000) {
2108+
LLOGLN(0, ("[INFO] xrdp_sec_process_msc_data_monitorex: ignore "
2109+
"invalid physical_height: %d",
2110+
client_info->minfo[index].physical_height));
2111+
client_info->minfo[index].physical_height = 0;
2112+
}
2113+
in_uint32_le(s, client_info->minfo[index].orientation);
2114+
switch (client_info->minfo[index].orientation) {
2115+
case 0:
2116+
case 90:
2117+
case 180:
2118+
case 270:
2119+
break;
2120+
default:
2121+
LLOGLN(0, ("[INFO] xrdp_sec_process_msc_data_monitorex: ignore "
2122+
"invalid orientation: %d",
2123+
client_info->minfo[index].orientation));
2124+
client_info->minfo[index].orientation = 0;
2125+
break;
2126+
}
2127+
in_uint32_le(s, client_info->minfo[index].desktop_scale_factor);
2128+
in_uint32_le(s, client_info->minfo[index].device_scale_factor);
2129+
}
2130+
2131+
return 0;
2132+
}
2133+
20492134
/*****************************************************************************/
20502135
/* process client mcs data, we need some things in here to create the server
20512136
mcs data */
@@ -2108,9 +2193,14 @@ xrdp_sec_process_mcs_data(struct xrdp_sec *self)
21082193
{
21092194
return 1;
21102195
}
2196+
break;
2197+
case SEC_TAG_CLI_MONITOR_EX:
2198+
if (xrdp_sec_process_msc_data_monitorex(self, s) != 0)
2199+
{
2200+
return 1;
2201+
}
21112202
break;
21122203
/* CS_MCS_MSGCHANNEL 0xC006
2113-
CS_MONITOR_EX 0xC008
21142204
CS_MULTITRANSPORT 0xC00A
21152205
SC_CORE 0x0C01
21162206
SC_SECURITY 0x0C02

0 commit comments

Comments
 (0)