Skip to content

Commit c46eece

Browse files
committed
Add support for creating sockdir to chansrv
Chansrv now checks for the user sockdir being present. If it isn't, it connects to chansrv and requests it be created. This also needs the sesman port to be added to the chansrv config struct.
1 parent 661885f commit c46eece

File tree

4 files changed

+129
-2
lines changed

4 files changed

+129
-2
lines changed

sesman/chansrv/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-DXRDP_PID_PATH=\"${localstatedir}/run\" \
1111
-DXRDP_SOCKET_ROOT_PATH=\"${socketdir}\" \
1212
-I$(top_srcdir)/sesman/libsesman \
13-
-I$(top_srcdir)/common
13+
-I$(top_srcdir)/common \
14+
-I$(top_srcdir)/libipm
1415

1516
CHANSRV_EXTRA_LIBS =
1617

sesman/chansrv/chansrv.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#include "xrdp_sockets.h"
4646
#include "audin.h"
4747

48+
#include "scp.h"
49+
#include "scp_sync.h"
50+
4851
#include "ms-rdpbcgr.h"
4952

5053
#define MAX_PATH 260
@@ -1763,6 +1766,54 @@ run_exec(void)
17631766
return 0;
17641767
}
17651768

1769+
/*****************************************************************************/
1770+
/**
1771+
* Make sure XRDP_SOCKET_PATH exists
1772+
*
1773+
* We can't do anything without XRDP_SOCKET_PATH existing.
1774+
*
1775+
* Normally this is done by sesman before chansrv starts. If we're running
1776+
* standalone however (i.e. with x11vnc) this won't be done. We don't have the
1777+
* privilege to create the directory, so we have to ask sesman to do it
1778+
* for us.
1779+
*/
1780+
static int
1781+
chansrv_create_xrdp_socket_path(void)
1782+
{
1783+
char xrdp_socket_path[XRDP_SOCKETS_MAXPATH];
1784+
int rv = 1;
1785+
1786+
/* Use our UID to qualify XRDP_SOCKET_PATH */
1787+
g_snprintf(xrdp_socket_path, sizeof(xrdp_socket_path),
1788+
XRDP_SOCKET_PATH, g_getuid());
1789+
1790+
if (g_directory_exist(xrdp_socket_path))
1791+
{
1792+
rv = 0;
1793+
}
1794+
else
1795+
{
1796+
LOG(LOG_LEVEL_INFO, "%s doesn't exist - asking sesman to create it",
1797+
xrdp_socket_path);
1798+
1799+
struct trans *t = NULL;
1800+
1801+
if (!(t = scp_connect(g_cfg->listen_port, "xrdp-chansrv", g_is_term)))
1802+
{
1803+
LOG(LOG_LEVEL_ERROR, "Can't connect to sesman");
1804+
}
1805+
else if (scp_sync_uds_login_request(t) == 0 &&
1806+
scp_sync_create_sockdir_request(t) == 0)
1807+
{
1808+
rv = 0;
1809+
(void)scp_send_close_connection_request(t);
1810+
}
1811+
trans_delete(t);
1812+
}
1813+
1814+
return rv;
1815+
}
1816+
17661817
/*****************************************************************************/
17671818
int
17681819
main(int argc, char **argv)
@@ -1855,6 +1906,13 @@ main(int argc, char **argv)
18551906
}
18561907

18571908
LOG_DEVEL(LOG_LEVEL_INFO, "main: app started pid %d(0x%8.8x)", pid, pid);
1909+
1910+
if (chansrv_create_xrdp_socket_path() != 0)
1911+
{
1912+
main_cleanup();
1913+
return 1;
1914+
}
1915+
18581916
/* set up signal handler */
18591917
g_signal_terminate(term_signal_handler); /* SIGTERM */
18601918
g_signal_user_interrupt(term_signal_handler); /* SIGINT */

sesman/chansrv/chansrv_config.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,61 @@ log_to_stdout(const enum logLevels lvl, const char *msg, ...)
7373
return LOG_STARTUP_OK;
7474
}
7575

76+
/***************************************************************************//**
77+
* Reads the config values we need from the [Globals] section
78+
*
79+
* @param logmsg Function to use to log messages
80+
* @param names List of definitions in the section
81+
* @params values List of corresponding values for the names
82+
* @params cfg Pointer to structure we're filling in
83+
*
84+
* @return 0 for success
85+
*/
86+
static int
87+
read_config_globals(log_func_t logmsg,
88+
struct list *names, struct list *values,
89+
struct config_chansrv *cfg)
90+
{
91+
int error = 0;
92+
int index;
93+
94+
for (index = 0; index < names->count; ++index)
95+
{
96+
const char *name = (const char *)list_get_item(names, index);
97+
const char *value = (const char *)list_get_item(values, index);
98+
99+
char unrecognised[256];
100+
if (g_strcasecmp(name, "ListenPort") == 0)
101+
{
102+
char *listen_port = strdup(value);
103+
if (listen_port == NULL)
104+
{
105+
LOG(LOG_LEVEL_WARNING,
106+
"Can't allocate config memory for ListenPort");
107+
}
108+
else
109+
{
110+
g_free(cfg->listen_port);
111+
cfg->listen_port = listen_port;
112+
}
113+
}
114+
if (g_strcasecmp(name, "RestrictInboundClipboard") == 0)
115+
{
116+
cfg->restrict_inbound_clipboard =
117+
sesman_clip_restrict_string_to_bitmask(
118+
value, unrecognised, sizeof(unrecognised));
119+
if (unrecognised[0] != '\0')
120+
{
121+
LOG(LOG_LEVEL_WARNING,
122+
"Unrecognised tokens parsing 'RestrictInboundClipboard' %s",
123+
unrecognised);
124+
}
125+
}
126+
}
127+
128+
return error;
129+
}
130+
76131
/***************************************************************************//**
77132
* Reads the config values we need from the [Security] section
78133
*
@@ -213,6 +268,7 @@ new_config(void)
213268
}
214269
else
215270
{
271+
cfg->listen_port = NULL;
216272
cfg->enable_fuse_mount = DEFAULT_ENABLE_FUSE_MOUNT;
217273
cfg->restrict_outbound_clipboard = DEFAULT_RESTRICT_OUTBOUND_CLIPBOARD;
218274
cfg->restrict_inbound_clipboard = DEFAULT_RESTRICT_INBOUND_CLIPBOARD;
@@ -258,6 +314,11 @@ config_read(int use_logger, const char *sesman_ini)
258314
names->auto_free = 1;
259315
values->auto_free = 1;
260316

317+
if (!error && file_read_section(fd, "Globals", names, values) == 0)
318+
{
319+
error = read_config_globals(logmsg, names, values, cfg);
320+
}
321+
261322
if (!error && file_read_section(fd, "Security", names, values) == 0)
262323
{
263324
error = read_config_security(logmsg, names, values, cfg);
@@ -288,9 +349,12 @@ config_read(int use_logger, const char *sesman_ini)
288349
void
289350
config_dump(struct config_chansrv *config)
290351
{
352+
char buf[256];
353+
291354
g_writeln("Global configuration:");
355+
g_writeln(" xrdp-sesman ListenPort: %s",
356+
(config->listen_port) ? config->listen_port : "<default>");
292357

293-
char buf[256];
294358
g_writeln("\nSecurity configuration:");
295359
sesman_clip_restrict_mask_to_string(
296360
config->restrict_outbound_clipboard,
@@ -319,6 +383,7 @@ config_free(struct config_chansrv *cc)
319383
{
320384
if (cc != NULL)
321385
{
386+
g_free(cc->listen_port);
322387
g_free(cc->fuse_mount_name);
323388
g_free(cc);
324389
}

sesman/chansrv/chansrv_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
struct config_chansrv
2525
{
26+
/** sesman listening port */
27+
char *listen_port;
28+
2629
/** Whether the FUSE mount is enabled or not */
2730
int enable_fuse_mount;
2831

0 commit comments

Comments
 (0)