Allow DISPLAY=:0 for chansrv and in other modules

This commit is contained in:
matt335672
2021-03-31 11:31:41 +01:00
parent ab203f9fc3
commit e7cb5bd64a
3 changed files with 50 additions and 68 deletions
+35 -61
View File
@@ -17,6 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include <ctype.h>
#if defined(HAVE_CONFIG_H) #if defined(HAVE_CONFIG_H)
#include <config_ac.h> #include <config_ac.h>
#endif #endif
@@ -61,7 +63,7 @@ static tbus g_thread_done_event = 0;
struct config_chansrv *g_cfg = NULL; struct config_chansrv *g_cfg = NULL;
int g_display_num = 0; int g_display_num = -1;
int g_cliprdr_chan_id = -1; /* cliprdr */ int g_cliprdr_chan_id = -1; /* cliprdr */
int g_rdpsnd_chan_id = -1; /* rdpsnd */ int g_rdpsnd_chan_id = -1; /* rdpsnd */
int g_rdpdr_chan_id = -1; /* rdpdr */ int g_rdpdr_chan_id = -1; /* rdpdr */
@@ -1559,61 +1561,30 @@ x_server_fatal_handler(void)
/*****************************************************************************/ /*****************************************************************************/
static int static int
get_display_num_from_display(char *display_text) get_display_num_from_display(const char *display_text)
{ {
int index; int rv = -1;
int mode; const char *p;
int host_index;
int disp_index;
int scre_index;
char host[256];
char disp[256];
char scre[256];
g_memset(host, 0, 256); /* Skip over the hostname part of the DISPLAY */
g_memset(disp, 0, 256); if ((p = g_strchr(display_text, ':')) != NULL)
g_memset(scre, 0, 256);
index = 0;
host_index = 0;
disp_index = 0;
scre_index = 0;
mode = 0;
while (display_text[index] != 0)
{ {
if (display_text[index] == ':') ++p; /* Skip the ':' */
/* Cater for the (still supported) double-colon. See
* https://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html */
if (*p == ':')
{ {
mode = 1; ++p;
}
else if (display_text[index] == '.')
{
mode = 2;
}
else if (mode == 0)
{
host[host_index] = display_text[index];
host_index++;
}
else if (mode == 1)
{
disp[disp_index] = display_text[index];
disp_index++;
}
else if (mode == 2)
{
scre[scre_index] = display_text[index];
scre_index++;
} }
index++; if (isdigit(*p))
{
rv = g_atoi(p);
}
} }
host[host_index] = 0; return rv;
disp[disp_index] = 0;
scre[scre_index] = 0;
g_display_num = g_atoi(disp);
return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -1728,7 +1699,7 @@ main(int argc, char **argv)
char text[256]; char text[256];
const char *config_path; const char *config_path;
char log_path[256]; char log_path[256];
char *display_text; const char *display_text;
char log_file[256]; char log_file[256];
enum logReturns error; enum logReturns error;
struct log_config *logconfig; struct log_config *logconfig;
@@ -1743,6 +1714,21 @@ main(int argc, char **argv)
return 1; return 1;
} }
display_text = g_getenv("DISPLAY");
if (display_text == NULL)
{
g_writeln("DISPLAY is not set");
main_cleanup();
return 1;
}
g_display_num = get_display_num_from_display(display_text);
if (g_display_num < 0)
{
g_writeln("Unable to get display from DISPLAY='%s'", display_text);
main_cleanup();
return 1;
}
/* /*
* The user is unable at present to override the sysadmin-provided * The user is unable at present to override the sysadmin-provided
* sesman.ini location */ * sesman.ini location */
@@ -1755,11 +1741,6 @@ main(int argc, char **argv)
config_dump(g_cfg); config_dump(g_cfg);
pid = g_getpid(); pid = g_getpid();
display_text = g_getenv("DISPLAY");
if (display_text != NULL)
{
get_display_num_from_display(display_text);
}
/* starting logging subsystem */ /* starting logging subsystem */
g_snprintf(log_file, 255, "%s/xrdp-chansrv.%d.log", log_path, g_display_num); g_snprintf(log_file, 255, "%s/xrdp-chansrv.%d.log", log_path, g_display_num);
@@ -1813,13 +1794,6 @@ main(int argc, char **argv)
LOG_DEVEL(LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text); LOG_DEVEL(LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text);
if (g_display_num == 0)
{
LOG_DEVEL(LOG_LEVEL_ERROR, "main: error, display is zero");
main_cleanup();
return 1;
}
LOG_DEVEL(LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num); LOG_DEVEL(LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num);
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid); g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
g_term_event = g_create_wait_obj(text); g_term_event = g_create_wait_obj(text);
+8 -4
View File
@@ -194,6 +194,10 @@ get_display_num_from_display(const char *display_text)
} }
else if (mode == 1) else if (mode == 1)
{ {
if (display_text[index] < '0' || display_text[index] > '9')
{
return -1;
}
disp[disp_index] = display_text[index]; disp[disp_index] = display_text[index];
disp_index++; disp_index++;
} }
@@ -209,7 +213,7 @@ get_display_num_from_display(const char *display_text)
scre[scre_index] = 0; scre[scre_index] = 0;
LLOGLN(10, ("get_display_num_from_display: host [%s] disp [%s] scre [%s]", LLOGLN(10, ("get_display_num_from_display: host [%s] disp [%s] scre [%s]",
host, disp, scre)); host, disp, scre));
rv = atoi(disp); rv = (disp_index== 0) ? -1 : atoi(disp);
return rv; return rv;
} }
@@ -253,10 +257,10 @@ connect_to_chansrv(void)
return 1; return 1;
} }
dis = get_display_num_from_display(xrdp_display); dis = get_display_num_from_display(xrdp_display);
if (dis < 10) if (dis < 0)
{ {
/* DISPLAY must be > 9 */ LLOGLN(0, ("connect_to_chansrv: error, don't understand DISPLAY='%s'",
LLOGLN(0, ("connect_to_chansrv: error, display not > 9 %d", dis)); xrdp_display));
return 1; return 1;
} }
g_sck = socket(PF_LOCAL, SOCK_STREAM, 0); g_sck = socket(PF_LOCAL, SOCK_STREAM, 0);
+7 -3
View File
@@ -120,9 +120,9 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,
wts->display_num = get_display_num_from_display(display_text); wts->display_num = get_display_num_from_display(display_text);
} }
if (wts->display_num <= 0) if (wts->display_num < 0)
{ {
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: fatal error; display is <= 0"); LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: fatal error; invalid DISPLAY");
free(wts); free(wts);
return NULL; return NULL;
} }
@@ -552,6 +552,10 @@ get_display_num_from_display(char *display_text)
} }
else if (mode == 1) else if (mode == 1)
{ {
if (display_text[index] < '0' || display_text[index] > '9')
{
return -1;
}
disp[disp_index] = display_text[index]; disp[disp_index] = display_text[index];
disp_index++; disp_index++;
} }
@@ -559,5 +563,5 @@ get_display_num_from_display(char *display_text)
} }
disp[disp_index] = 0; disp[disp_index] = 0;
return atoi(disp); return (disp_index== 0) ? -1 : atoi(disp);
} }