Merge pull request #3509 from matt335672/devel_sps_investigations

Refactor static channel name handling
This commit is contained in:
matt335672
2025-04-28 10:48:35 +01:00
committed by GitHub
7 changed files with 27 additions and 32 deletions
+1 -1
View File
@@ -1297,7 +1297,7 @@ libxrdp_query_channel(struct xrdp_session *session, int channel_id,
if (channel_name != 0) if (channel_name != 0)
{ {
g_strncpy(channel_name, channel_item->name, 8); strlcpy(channel_name, channel_item->name, CHANNEL_NAME_LEN + 1);
LOG(LOG_LEVEL_DEBUG, "libxrdp_query_channel - Channel %d name %s", LOG(LOG_LEVEL_DEBUG, "libxrdp_query_channel - Channel %d name %s",
channel_id, channel_name); channel_id, channel_name);
} }
+1 -1
View File
@@ -50,7 +50,7 @@ struct xrdp_iso
/* used in mcs */ /* used in mcs */
struct mcs_channel_item struct mcs_channel_item
{ {
char name[16]; char name[CHANNEL_NAME_LEN + 1];
int flags; int flags;
int chanid; int chanid;
int disabled; int disabled;
+11 -23
View File
@@ -1924,31 +1924,19 @@ xrdp_sec_process_mcs_data_channels(struct xrdp_sec *self, struct stream *s)
g_free(channel_item); g_free(channel_item);
return 1; return 1;
} }
in_uint8a(s, channel_item->name, 8);
in_uint8a(s, channel_item->name, CHANNEL_NAME_LEN + 1);
// The channel name *should* be null-terminated. Add a back-stop
// terminator in case it isn't.
channel_item->name[CHANNEL_NAME_LEN] = '\0';
in_uint32_le(s, channel_item->flags); in_uint32_le(s, channel_item->flags);
if (g_strlen(channel_item->name) > 0 && g_strlen(channel_item->name) < 8) channel_item->chanid = next_mcs_channel_id++;
{ list_add_item(self->mcs_layer->channel_list,
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] " (intptr_t) channel_item);
"TS_UD_CS_NET.CHANNEL_DEF %d, name %s, options 0x%8.8x", LOG(LOG_LEVEL_DEBUG,
index, channel_item->name, channel_item->flags); "Adding channel: name %s, channel id %d, flags 0x%8.8x",
channel_item->chanid = next_mcs_channel_id++; channel_item->name, channel_item->chanid, channel_item->flags);
list_add_item(self->mcs_layer->channel_list,
(intptr_t) channel_item);
LOG(LOG_LEVEL_DEBUG,
"Adding channel: name %s, channel id %d, flags 0x%8.8x",
channel_item->name, channel_item->chanid, channel_item->flags);
}
else
{
LOG_DEVEL(LOG_LEVEL_WARNING, "Received [MS-RDPBCGR] "
"TS_UD_CS_NET.CHANNEL_DEF %d, skipped because of "
"malformed channel name.", index);
LOG_DEVEL_HEXDUMP(LOG_LEVEL_WARNING,
"[MS-RDPBCGR] TS_UD_CS_NET.CHANNEL_DEF name",
channel_item->name, 8);
g_free(channel_item);
}
} }
/* Set the user channel as well */ /* Set the user channel as well */
+1 -1
View File
@@ -1800,7 +1800,7 @@ lfreerdp_pre_connect(freerdp *instance)
int num_chans; int num_chans;
int target_chan; int target_chan;
int ch_flags; int ch_flags;
char ch_name[256]; char ch_name[CHANNEL_NAME_LEN + 1];
const char *ch_names[MAX_FREERDP_CHANNELS]; const char *ch_names[MAX_FREERDP_CHANNELS];
char *dst_ch_name; char *dst_ch_name;
+1 -1
View File
@@ -371,7 +371,7 @@ process_message_channel_setup(struct stream *s)
{ {
ci = &(g_chan_items[g_num_chan_items]); ci = &(g_chan_items[g_num_chan_items]);
g_memset(ci->name, 0, sizeof(ci->name)); g_memset(ci->name, 0, sizeof(ci->name));
in_uint8a(s, ci->name, 8); in_uint8a(s, ci->name, CHANNEL_NAME_LEN + 1);
in_uint16_le(s, ci->id); in_uint16_le(s, ci->id);
in_uint16_le(s, ci->flags); in_uint16_le(s, ci->flags);
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_channel_setup: chan name '%s' " LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_channel_setup: chan name '%s' "
+2 -4
View File
@@ -634,9 +634,7 @@ xrdp_mm_trans_send_channel_setup(struct xrdp_mm *self, struct trans *trans)
int chan_flags; int chan_flags;
int size; int size;
struct stream *s; struct stream *s;
char chan_name[256]; char chan_name[CHANNEL_NAME_LEN + 1];
g_memset(chan_name, 0, sizeof(char) * 256);
s = trans_get_out_s(trans, 8192); s = trans_get_out_s(trans, 8192);
@@ -656,7 +654,7 @@ xrdp_mm_trans_send_channel_setup(struct xrdp_mm *self, struct trans *trans)
if (libxrdp_query_channel(self->wm->session, chan_id, chan_name, if (libxrdp_query_channel(self->wm->session, chan_id, chan_name,
&chan_flags) == 0) &chan_flags) == 0)
{ {
out_uint8a(s, chan_name, 8); out_uint8a(s, chan_name, CHANNEL_NAME_LEN + 1);
out_uint16_le(s, chan_id); out_uint16_le(s, chan_id);
out_uint16_le(s, chan_flags); out_uint16_le(s, chan_flags);
++output_chan_count; ++output_chan_count;
+10 -1
View File
@@ -48,11 +48,12 @@ xrdp_wm_load_channel_config(struct xrdp_wm *self)
for (chan_id = 0 ; chan_id < chan_count ; ++chan_id) for (chan_id = 0 ; chan_id < chan_count ; ++chan_id)
{ {
char chan_name[16]; char chan_name[CHANNEL_NAME_LEN + 1];
if (libxrdp_query_channel(self->session, chan_id, chan_name, if (libxrdp_query_channel(self->session, chan_id, chan_name,
NULL) == 0) NULL) == 0)
{ {
int disabled = 1; /* Channels disabled if not found */ int disabled = 1; /* Channels disabled if not found */
int found = 0;
int index; int index;
for (index = 0; index < names->count; index++) for (index = 0; index < names->count; index++)
@@ -61,10 +62,18 @@ xrdp_wm_load_channel_config(struct xrdp_wm *self)
const char *r = (const char *)list_get_item(values, index); const char *r = (const char *)list_get_item(values, index);
if (g_strcasecmp(q, chan_name) == 0) if (g_strcasecmp(q, chan_name) == 0)
{ {
found = 1;
disabled = !g_text2bool(r); disabled = !g_text2bool(r);
break; break;
} }
} }
if (!found)
{
LOG(LOG_LEVEL_WARNING,
"Static channel '%s' from the client"
" is not named in the [Channels] section",
chan_name);
}
disabled_str = (disabled) ? "disabled" : "enabled"; disabled_str = (disabled) ? "disabled" : "enabled";
LOG(LOG_LEVEL_DEBUG, "xrdp_wm_load_channel_config: " LOG(LOG_LEVEL_DEBUG, "xrdp_wm_load_channel_config: "
"channel %s channel id %d is %s", "channel %s channel id %d is %s",