Skip to content

Commit bd9147d

Browse files
committed
Updating to refactor xrdp_client_info
- Eliminate duplicaiton for display_size_description - monitorCount needs to be uint32_t - width/height -> session_width/session_height - Update CLIENT_INFO_CURRENT_VERSION - Also some misc unit test updates. - Minor log updates.
1 parent 4a0db63 commit bd9147d

15 files changed

+603
-137
lines changed

common/xrdp_client_info.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ struct monitor_info
3939
int flags;
4040

4141
/* From 2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT */
42-
int physical_width;
43-
int physical_height;
44-
int orientation;
45-
int desktop_scale_factor;
46-
int device_scale_factor;
42+
unsigned int physical_width;
43+
unsigned int physical_height;
44+
unsigned int orientation;
45+
unsigned int desktop_scale_factor;
46+
unsigned int device_scale_factor;
4747

4848
/* Derived setting */
49-
int is_primary;
49+
unsigned int is_primary;
5050
};
5151

5252
/* xrdp keyboard overrids */
@@ -59,11 +59,11 @@ struct xrdp_keyboard_overrides
5959

6060
struct display_size_description
6161
{
62-
int monitorCount; /* number of monitors detected (max = 16) */
62+
unsigned int monitorCount; /* 2.2.2.2 DISPLAYCONTROL_MONITOR_LAYOUT_PDU: number of monitors detected (max = 16) */
6363
struct monitor_info minfo[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS]; /* client monitor data */
6464
struct monitor_info minfo_wm[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS]; /* client monitor data, non-negative values */
65-
int session_width;
66-
int session_height;
65+
unsigned int session_width;
66+
unsigned int session_height;
6767
};
6868

6969
/**
@@ -79,8 +79,6 @@ struct xrdp_client_info
7979
int size; /* bytes for this structure */
8080
int version; /* Should be CLIENT_INFO_CURRENT_VERSION */
8181
int bpp;
82-
int width;
83-
int height;
8482
/* bitmap cache info */
8583
int cache1_entries;
8684
int cache1_size;
@@ -153,9 +151,7 @@ struct xrdp_client_info
153151

154152
int security_layer; /* 0 = rdp, 1 = tls , 2 = hybrid */
155153
int multimon; /* 0 = deny , 1 = allow */
156-
int monitorCount; /* number of monitors detected (max = 16) */
157-
struct monitor_info minfo[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS]; /* client monitor data */
158-
struct monitor_info minfo_wm[CLIENT_MONITOR_DATA_MAXIMUM_MONITORS]; /* client monitor data, non-negative values */
154+
struct display_size_description display_sizes;
159155

160156
int keyboard_type;
161157
int keyboard_subtype;
@@ -211,6 +207,6 @@ struct xrdp_client_info
211207
};
212208

213209
/* yyyymmdd of last incompatible change to xrdp_client_info */
214-
#define CLIENT_INFO_CURRENT_VERSION 20210723
210+
#define CLIENT_INFO_CURRENT_VERSION 20220320
215211

216212
#endif

libxrdp/libxrdp.c

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ libxrdp_orders_send_font(struct xrdp_session *session,
11341134
* to a single monitor */
11351135
int EXPORT_CC
11361136
libxrdp_reset(struct xrdp_session *session,
1137-
int width, int height, int bpp)
1137+
unsigned int width, unsigned int height, int bpp)
11381138
{
11391139
if (session->client_info != 0)
11401140
{
@@ -1147,18 +1147,18 @@ libxrdp_reset(struct xrdp_session *session,
11471147
}
11481148

11491149
/* if same (and only one monitor on client) don't need to do anything */
1150-
if (client_info->width == width &&
1151-
client_info->height == height &&
1150+
if (client_info->display_sizes.session_width == width &&
1151+
client_info->display_sizes.session_height == height &&
11521152
client_info->bpp == bpp &&
1153-
(client_info->monitorCount == 0 || client_info->multimon == 0))
1153+
(client_info->display_sizes.monitorCount == 0 || client_info->multimon == 0))
11541154
{
11551155
return 0;
11561156
}
11571157

1158-
client_info->width = width;
1159-
client_info->height = height;
1158+
client_info->display_sizes.session_width = width;
1159+
client_info->display_sizes.session_height = height;
1160+
client_info->display_sizes.monitorCount = 0;
11601161
client_info->bpp = bpp;
1161-
client_info->monitorCount = 0;
11621162
client_info->multimon = 0;
11631163
}
11641164
else
@@ -1908,8 +1908,39 @@ libxrdp_process_monitor_stream(struct stream *s,
19081908
in_uint32_le(s, monitor_layout->physical_width);
19091909
in_uint32_le(s, monitor_layout->physical_height);
19101910

1911+
/* Per spec (2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT),
1912+
* if EITHER physical_width or physical_height are
1913+
* out of range, BOTH must be ignored.
1914+
*/
1915+
if (monitor_layout->physical_width > 10000
1916+
|| monitor_layout->physical_width < 10)
1917+
{
1918+
LOG(LOG_LEVEL_WARNING, "libxrdp_process_monitor_stream:"
1919+
" physical_width is not within valid range."
1920+
" Setting physical_width to 0mm,"
1921+
" Setting physical_height to 0mm,"
1922+
" physical_width was: %d",
1923+
monitor_layout->physical_width);
1924+
monitor_layout->physical_width = 0;
1925+
monitor_layout->physical_height = 0;
1926+
}
1927+
1928+
if (monitor_layout->physical_height > 10000
1929+
|| monitor_layout->physical_height < 10)
1930+
{
1931+
LOG(LOG_LEVEL_WARNING, "libxrdp_process_monitor_stream:"
1932+
" physical_height is not within valid range."
1933+
" Setting physical_width to 0mm,"
1934+
" Setting physical_height to 0mm,"
1935+
" physical_height was: %d",
1936+
monitor_layout->physical_height);
1937+
monitor_layout->physical_width = 0;
1938+
monitor_layout->physical_height = 0;
1939+
}
1940+
19111941
in_uint32_le(s, monitor_layout->orientation);
1912-
switch (monitor_layout->orientation) {
1942+
switch (monitor_layout->orientation)
1943+
{
19131944
case ORIENTATION_LANDSCAPE:
19141945
case ORIENTATION_PORTRAIT:
19151946
case ORIENTATION_LANDSCAPE_FLIPPED:
@@ -1918,21 +1949,47 @@ libxrdp_process_monitor_stream(struct stream *s,
19181949
default:
19191950
LOG(LOG_LEVEL_WARNING, "libxrdp_process_monitor_stream:"
19201951
" Orientation is not one of %d, %d, %d, or %d."
1921-
" Value was %d and ignored.",
1952+
" Value was %d and ignored and set to default value of LANDSCAPE.",
19221953
ORIENTATION_LANDSCAPE,
19231954
ORIENTATION_PORTRAIT,
19241955
ORIENTATION_LANDSCAPE_FLIPPED,
19251956
ORIENTATION_PORTRAIT_FLIPPED,
19261957
monitor_layout->orientation);
1958+
monitor_layout->orientation = ORIENTATION_LANDSCAPE;
19271959
}
19281960

19291961
in_uint32_le(s, monitor_layout->desktop_scale_factor);
1962+
if (monitor_layout->desktop_scale_factor < 100
1963+
|| monitor_layout->desktop_scale_factor > 500
1964+
|| (monitor_layout->desktop_scale_factor != 100
1965+
&& monitor_layout->desktop_scale_factor != 140
1966+
&& monitor_layout->desktop_scale_factor != 180))
1967+
{
1968+
LOG(LOG_LEVEL_WARNING, "libxrdp_process_monitor_stream:"
1969+
" desktop_scale_factor is not within valid range. Assuming 100."
1970+
" Value was: %d",
1971+
monitor_layout->desktop_scale_factor);
1972+
monitor_layout->desktop_scale_factor = 100;
1973+
}
1974+
19301975
in_uint32_le(s, monitor_layout->device_scale_factor);
1976+
if (monitor_layout->device_scale_factor < 100
1977+
|| monitor_layout->device_scale_factor > 500
1978+
|| (monitor_layout->device_scale_factor != 100
1979+
&& monitor_layout->device_scale_factor != 140
1980+
&& monitor_layout->device_scale_factor != 180))
1981+
{
1982+
LOG(LOG_LEVEL_WARNING, "libxrdp_process_monitor_stream:"
1983+
" device_scale_factor is not within valid range. Assuming 100."
1984+
" Value was: %d",
1985+
monitor_layout->device_scale_factor);
1986+
monitor_layout->device_scale_factor = 100;
1987+
}
19311988

19321989
/*
19331990
* 2.2.2.2.1 DISPLAYCONTROL_MONITOR_LAYOUT
19341991
*/
1935-
LOG_DEVEL(LOG_LEVEL_TRACE, "libxrdp_process_monitor_stream:"
1992+
LOG_DEVEL(LOG_LEVEL_INFO, "libxrdp_process_monitor_stream:"
19361993
" Received [MS-RDPEDISP] 2.2.2.2.1"
19371994
" DISPLAYCONTROL_MONITOR_LAYOUT_PDU"
19381995
".DISPLAYCONTROL_MONITOR_LAYOUT"

libxrdp/libxrdp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,10 @@ xrdp_mcs_disconnect(struct xrdp_mcs *self);
361361
/* xrdp_sec.c */
362362

363363
/*
364-
These are return values for xrdp_sec_process_mcs_data_monitors
365-
to clarify any reason for a non-zero response code.
364+
These are error return codes for both:
365+
1. xrdp_sec_process_mcs_data_monitors
366+
2. libxrdp_process_monitor_stream
367+
To clarify any reason for a non-zero response code.
366368
*/
367369
#define SEC_PROCESS_MONITORS_ERR 1
368370
#define SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS 2

libxrdp/libxrdpinc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ libxrdp_orders_send_font(struct xrdp_session *session,
193193
int font_index, int char_index);
194194
int
195195
libxrdp_reset(struct xrdp_session *session,
196-
int width, int height, int bpp);
196+
unsigned int width, unsigned int height, int bpp);
197197
int
198198
libxrdp_orders_send_raw_bitmap2(struct xrdp_session *session,
199199
int width, int height, int bpp, char *data,

libxrdp/xrdp_caps.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ static int
4545
xrdp_caps_send_monitorlayout(struct xrdp_rdp *self)
4646
{
4747
struct stream *s;
48-
int i;
48+
uint32_t i;
49+
struct display_size_description *description;
4950

5051
make_stream(s);
5152
init_stream(s, 8192);
@@ -56,16 +57,18 @@ xrdp_caps_send_monitorlayout(struct xrdp_rdp *self)
5657
return 1;
5758
}
5859

59-
out_uint32_le(s, self->client_info.monitorCount); /* monitorCount (4 bytes) */
60+
description = &self->client_info.display_sizes;
61+
62+
out_uint32_le(s, description->monitorCount); /* monitorCount (4 bytes) */
6063

6164
/* TODO: validate for allowed monitors in terminal server (maybe by config?) */
62-
for (i = 0; i < self->client_info.monitorCount; i++)
65+
for (i = 0; i < description->monitorCount; i++)
6366
{
64-
out_uint32_le(s, self->client_info.minfo[i].left);
65-
out_uint32_le(s, self->client_info.minfo[i].top);
66-
out_uint32_le(s, self->client_info.minfo[i].right);
67-
out_uint32_le(s, self->client_info.minfo[i].bottom);
68-
out_uint32_le(s, self->client_info.minfo[i].is_primary);
67+
out_uint32_le(s, description->minfo[i].left);
68+
out_uint32_le(s, description->minfo[i].top);
69+
out_uint32_le(s, description->minfo[i].right);
70+
out_uint32_le(s, description->minfo[i].bottom);
71+
out_uint32_le(s, description->minfo[i].is_primary);
6972
}
7073

7174
s_mark_end(s);
@@ -883,8 +886,8 @@ unsigned int calculate_multifragmentupdate_len(const struct xrdp_rdp *self)
883886
{
884887
unsigned int result = MAX_MULTIFRAGMENTUPDATE_SIZE;
885888

886-
unsigned int x_tiles = (self->client_info.width + 63) / 64;
887-
unsigned int y_tiles = (self->client_info.height + 63) / 64;
889+
unsigned int x_tiles = (self->client_info.display_sizes.session_width + 63) / 64;
890+
unsigned int y_tiles = (self->client_info.display_sizes.session_height + 63) / 64;
888891

889892
/* Check for overflow on calculation if bad parameters are supplied */
890893
if ((x_tiles * y_tiles + 1) < (UINT_MAX / 16384))
@@ -979,8 +982,8 @@ xrdp_caps_send_demand_active(struct xrdp_rdp *self)
979982
out_uint16_le(s, 1); /* Receive 1 BPP */
980983
out_uint16_le(s, 1); /* Receive 4 BPP */
981984
out_uint16_le(s, 1); /* Receive 8 BPP */
982-
out_uint16_le(s, self->client_info.width); /* width */
983-
out_uint16_le(s, self->client_info.height); /* height */
985+
out_uint16_le(s, self->client_info.display_sizes.session_width); /* width */
986+
out_uint16_le(s, self->client_info.display_sizes.session_height); /* height */
984987
out_uint16_le(s, 0); /* Pad */
985988
out_uint16_le(s, 1); /* Allow resize */
986989
out_uint16_le(s, 1); /* bitmap compression */
@@ -1242,7 +1245,7 @@ xrdp_caps_send_demand_active(struct xrdp_rdp *self)
12421245
}
12431246

12441247
/* send Monitor Layout PDU for dual monitor */
1245-
if (self->client_info.monitorCount > 0 &&
1248+
if (self->client_info.display_sizes.monitorCount > 0 &&
12461249
self->client_info.multimon == 1)
12471250
{
12481251
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_caps_send_demand_active: sending monitor layout pdu");

libxrdp/xrdp_sec.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,8 +1953,8 @@ xrdp_sec_process_mcs_data_CS_CORE(struct xrdp_sec *self, struct stream *s)
19531953

19541954
/* TS_UD_CS_CORE requiered fields */
19551955
in_uint8s(s, 4); /* version */
1956-
in_uint16_le(s, self->rdp_layer->client_info.width);
1957-
in_uint16_le(s, self->rdp_layer->client_info.height);
1956+
in_uint16_le(s, self->rdp_layer->client_info.display_sizes.session_width);
1957+
in_uint16_le(s, self->rdp_layer->client_info.display_sizes.session_height);
19581958
in_uint16_le(s, colorDepth);
19591959
switch (colorDepth)
19601960
{
@@ -1981,8 +1981,8 @@ xrdp_sec_process_mcs_data_CS_CORE(struct xrdp_sec *self, struct stream *s)
19811981
"clientName %s, keyboardType (ignored), "
19821982
"keyboardSubType (ignored), keyboardFunctionKey (ignored), "
19831983
"imeFileName (ignroed)",
1984-
self->rdp_layer->client_info.width,
1985-
self->rdp_layer->client_info.height,
1984+
self->rdp_layer->client_info.display_sizes.session_width,
1985+
self->rdp_layer->client_info.display_sizes.session_height,
19861986
(colorDepth == 0xca00 ? "RNS_UD_COLOR_4BPP" :
19871987
colorDepth == 0xca01 ? "RNS_UD_COLOR_8BPP" : "unknown"),
19881988
clientName);
@@ -2370,17 +2370,17 @@ xrdp_sec_process_mcs_data_monitors(struct xrdp_sec *self, struct stream *s)
23702370
error = libxrdp_process_monitor_stream(s, description, 0);
23712371
if (error == 0)
23722372
{
2373-
client_info->monitorCount = description->monitorCount;
2373+
client_info->display_sizes.monitorCount = description->monitorCount;
23742374

23752375
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_sec_process_mcs_data_monitors:"
23762376
" Received [MS-RDPBCGR] TS_UD_CS_MONITOR"
23772377
" flags 0x%8.8x, monitorCount %d",
23782378
flags, description->monitorCount);
23792379

2380-
client_info->width = description->session_width;
2381-
client_info->height = description->session_height;
2382-
g_memcpy(client_info->minfo, description->minfo, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);
2383-
g_memcpy(client_info->minfo_wm, description->minfo_wm, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);
2380+
client_info->display_sizes.session_width = description->session_width;
2381+
client_info->display_sizes.session_height = description->session_height;
2382+
g_memcpy(client_info->display_sizes.minfo, description->minfo, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);
2383+
g_memcpy(client_info->display_sizes.minfo_wm, description->minfo_wm, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);
23842384
}
23852385

23862386
g_free(description);

tests/libxrdp/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ check_PROGRAMS = test_libxrdp
1414
test_libxrdp_SOURCES = \
1515
test_libxrdp.h \
1616
test_libxrdp_main.c \
17-
test_monitor_processing.c
17+
test_libxrdp_process_monitor_stream.c \
18+
test_xrdp_sec_process_mcs_data_monitors.c
1819

1920
test_libxrdp_CFLAGS = \
2021
@CHECK_CFLAGS@

tests/libxrdp/test_libxrdp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <check.h>
55

6+
Suite *make_suite_test_xrdp_sec_process_mcs_data_monitors(void);
67
Suite *make_suite_test_monitor_processing(void);
78

89
#endif /* TEST_LIBXRDP_H */

tests/libxrdp/test_libxrdp_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ int main (void)
1111
int number_failed;
1212
SRunner *sr;
1313

14-
sr = srunner_create (make_suite_test_monitor_processing());
15-
// srunner_add_suite(sr, make_list_suite());
14+
sr = srunner_create(make_suite_test_xrdp_sec_process_mcs_data_monitors());
15+
srunner_add_suite(sr, make_suite_test_monitor_processing());
1616

1717
srunner_set_tap(sr, "-");
1818
srunner_run_all (sr, CK_ENV);

0 commit comments

Comments
 (0)