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.
This commit is contained in:
matt335672
2024-09-13 12:08:31 +01:00
parent 661885f71d
commit c46eece00f
4 changed files with 130 additions and 3 deletions
+58
View File
@@ -45,6 +45,9 @@
#include "xrdp_sockets.h"
#include "audin.h"
#include "scp.h"
#include "scp_sync.h"
#include "ms-rdpbcgr.h"
#define MAX_PATH 260
@@ -1763,6 +1766,54 @@ run_exec(void)
return 0;
}
/*****************************************************************************/
/**
* Make sure XRDP_SOCKET_PATH exists
*
* We can't do anything without XRDP_SOCKET_PATH existing.
*
* Normally this is done by sesman before chansrv starts. If we're running
* standalone however (i.e. with x11vnc) this won't be done. We don't have the
* privilege to create the directory, so we have to ask sesman to do it
* for us.
*/
static int
chansrv_create_xrdp_socket_path(void)
{
char xrdp_socket_path[XRDP_SOCKETS_MAXPATH];
int rv = 1;
/* Use our UID to qualify XRDP_SOCKET_PATH */
g_snprintf(xrdp_socket_path, sizeof(xrdp_socket_path),
XRDP_SOCKET_PATH, g_getuid());
if (g_directory_exist(xrdp_socket_path))
{
rv = 0;
}
else
{
LOG(LOG_LEVEL_INFO, "%s doesn't exist - asking sesman to create it",
xrdp_socket_path);
struct trans *t = NULL;
if (!(t = scp_connect(g_cfg->listen_port, "xrdp-chansrv", g_is_term)))
{
LOG(LOG_LEVEL_ERROR, "Can't connect to sesman");
}
else if (scp_sync_uds_login_request(t) == 0 &&
scp_sync_create_sockdir_request(t) == 0)
{
rv = 0;
(void)scp_send_close_connection_request(t);
}
trans_delete(t);
}
return rv;
}
/*****************************************************************************/
int
main(int argc, char **argv)
@@ -1855,6 +1906,13 @@ main(int argc, char **argv)
}
LOG_DEVEL(LOG_LEVEL_INFO, "main: app started pid %d(0x%8.8x)", pid, pid);
if (chansrv_create_xrdp_socket_path() != 0)
{
main_cleanup();
return 1;
}
/* set up signal handler */
g_signal_terminate(term_signal_handler); /* SIGTERM */
g_signal_user_interrupt(term_signal_handler); /* SIGINT */