Pick up the first section if given section(domain) doesn't match anything

As some clinents (AFAIK Windows 10) always send domain name, the backend
module is not selected properly. This causes the default usage with
Windows 10 fails with 'xrdp_wm_log_msg: Section "XXX" not configured'.
This commit is contained in:
Koichiro IWAO 2017-05-23 18:31:03 +09:00 committed by metalefty
parent 0e7844ab02
commit 84596e7392

View File

@ -554,6 +554,7 @@ xrdp_wm_init(struct xrdp_wm *self)
char *q; char *q;
const char *r; const char *r;
char param[256]; char param[256];
char default_section_name[256];
char section_name[256]; char section_name[256];
char cfg_file[256]; char cfg_file[256];
char autorun_name[256]; char autorun_name[256];
@ -581,6 +582,22 @@ xrdp_wm_init(struct xrdp_wm *self)
values = list_create(); values = list_create();
values->auto_free = 1; values->auto_free = 1;
/* pick up the first section name except for 'globals', 'Logging', 'channels'
* in xrdp.ini and use it as default section name */
file_read_sections(fd, names);
default_section_name[0] = '\0';
for (index = 0; index < names->count; index++)
{
q = (char *)list_get_item(names, index);
if ((g_strncasecmp("globals", q, 8) != 0) &&
(g_strncasecmp("Logging", q, 8) != 0) &&
(g_strncasecmp("channels", q, 9) != 0))
{
g_strncpy(default_section_name, q, 255);
break;
}
}
/* look for module name to be loaded */ /* look for module name to be loaded */
if (autorun_name[0] != 0) if (autorun_name[0] != 0)
{ {
@ -594,34 +611,36 @@ xrdp_wm_init(struct xrdp_wm *self)
* simplify for the user in a proxy setup */ * simplify for the user in a proxy setup */
/* we use the domain name as the module name to be loaded */ /* we use the domain name as the module name to be loaded */
g_strncpy(section_name, self->session->client_info->domain, g_strncpy(section_name,
255); self->session->client_info->domain, 255);
} }
else else
{ {
/* if no domain is passed, and no autorun in xrdp.ini, /* if no domain is given, and autorun is not specified in xrdp.ini
use the first item in the xrdp.ini * use default_section_name as section_name */
file that's not named g_strncpy(section_name, default_section_name, 255);
'globals' or 'Logging' or 'channels' */
/* TODO: change this and have an 'autologin'
line in globals section */
file_read_sections(fd, names);
section_name[0] = '\0';
for (index = 0; index < names->count; index++)
{
q = (char *)list_get_item(names, index);
if ((g_strncasecmp("globals", q, 8) != 0) &&
(g_strncasecmp("Logging", q, 8) != 0) &&
(g_strncasecmp("channels", q, 9) != 0))
{
g_strncpy(section_name, q, 255);
break;
}
}
} }
list_clear(names); list_clear(names);
/* if given section name doesn't match any sections configured
* in xrdp.ini, fallback to default_section_name */
if (file_read_section(fd, section_name, names, values) != 0)
{
log_message(LOG_LEVEL_INFO,
"Module \"%s\" specified by %s from %s port %s "
"is not configured. Using \"%s\" instead.",
section_name,
self->session->client_info->username,
self->session->client_info->client_addr,
self->session->client_info->client_port,
default_section_name);
list_clear(names);
list_clear(values);
g_strncpy(section_name, default_section_name, 255);
}
/* look for the required module in xrdp.ini, fetch its parameters */ /* look for the required module in xrdp.ini, fetch its parameters */
if (file_read_section(fd, section_name, names, values) == 0) if (file_read_section(fd, section_name, names, values) == 0)
{ {
@ -684,10 +703,9 @@ xrdp_wm_init(struct xrdp_wm *self)
} }
else else
{ {
/* requested module name not found in xrdp.ini */ /* Hopefully, we never reach here. */
xrdp_wm_log_msg(self, LOG_LEVEL_ERROR, log_message(LOG_LEVEL_DEBUG,
"Section \"%s\" not configured in xrdp.ini", "Control should never reach %s:%d", __FILE__, __LINE__);
section_name);
} }
list_delete(names); list_delete(names);