From cf202d618bee80a49c4c0a7d541bb7f1e0820534 Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:28:58 +0100 Subject: [PATCH] Add AlwaysRunReconnect config option This allows the system administrator to specify whether the reconnectwm.sh script should only be run on reconnects, or should be run for all connections to a session. --- docs/man/sesman.ini.5.in | 5 +++++ sesman/libsesman/sesman_config.c | 7 +++++++ sesman/libsesman/sesman_config.h | 5 +++++ sesman/sesexec/ercp_server.c | 12 ++++++++++-- sesman/sesman.ini.in | 4 ++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/man/sesman.ini.5.in b/docs/man/sesman.ini.5.in index caebd2cd..a92e7b2f 100644 --- a/docs/man/sesman.ini.5.in +++ b/docs/man/sesman.ini.5.in @@ -86,6 +86,11 @@ to the existing session. If the path is not a full path, it will be resolved as relative path to \fI@xrdpconfdir@\fR. If not specified, defaults to \fI@xrdpconfdir@/reconnectwm.sh\fR. +.TP +\fBAlwaysRunReconnect\fR=\fI[yes|no]\fR +If set to \fB1\fR, \fBtrue\fR or \fByes\fR, the \fBReconnectScript\fR will +be run for the initial connection to a session, as well as all reconnects. + .SH "LOGGING" Following parameters can be used in the \fB[Logging]\fR and \fB[ChansrvLogging]\fR sections. diff --git a/sesman/libsesman/sesman_config.c b/sesman/libsesman/sesman_config.c index d2a28d9a..16219025 100644 --- a/sesman/libsesman/sesman_config.c +++ b/sesman/libsesman/sesman_config.c @@ -48,6 +48,7 @@ #define SESMAN_CFG_USERWM "UserWindowManager" #define SESMAN_CFG_AUTH_FILE_PATH "AuthFilePath" #define SESMAN_CFG_RECONNECT_SH "ReconnectScript" +#define SESMAN_CFG_ALWAYS_RUN_RECONNECT "AlwaysRunReconnect" #define SESMAN_CFG_XORG_PARAMS "Xorg" #define SESMAN_CFG_VNC_PARAMS "Xvnc" @@ -188,6 +189,7 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n, cf->default_wm = 0; cf->auth_file_path = 0; cf->reconnect_sh = 0; + cf->always_run_reconnect = 0; file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v); @@ -222,6 +224,10 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n, { cf->reconnect_sh = g_strdup(val); } + else if (g_strcasecmp(param, SESMAN_CFG_ALWAYS_RUN_RECONNECT) == 0) + { + cf->always_run_reconnect = g_text2bool(val); + } else if (0 == g_strcasecmp(param, SESMAN_CFG_ADDRESS)) { /* Config must be updated for Unix Domain Sockets */ @@ -676,6 +682,7 @@ config_dump(struct config_sesman *config) g_writeln(" UserWindowManager: %s", config->user_wm); g_writeln(" DefaultWindowManager: %s", config->default_wm); g_writeln(" ReconnectScript: %s", config->reconnect_sh); + g_writeln(" AlwaysRunReconnect: %d", config->always_run_reconnect); g_writeln(" AuthFilePath: %s", (config->auth_file_path ? config->auth_file_path : "disabled")); diff --git a/sesman/libsesman/sesman_config.h b/sesman/libsesman/sesman_config.h index be6e76e0..61aa6818 100644 --- a/sesman/libsesman/sesman_config.h +++ b/sesman/libsesman/sesman_config.h @@ -219,6 +219,11 @@ struct config_sesman * @brief Script executed when reconnected */ char *reconnect_sh; + /** + * @var always_run_reconnect + * @brief Do we run the reconnect script on a first connection? + */ + int always_run_reconnect; /** * @var auth_file_path * @brief Auth file path diff --git a/sesman/sesexec/ercp_server.c b/sesman/sesexec/ercp_server.c index 6dd551c6..539473b0 100644 --- a/sesman/sesexec/ercp_server.c +++ b/sesman/sesexec/ercp_server.c @@ -35,6 +35,7 @@ #include "sesexec.h" #include "os_calls.h" #include "session.h" +#include "sesman_config.h" #include "trans.h" #include "ercp.h" @@ -100,17 +101,24 @@ handle_connect_session_request(struct trans *self) if (rv == 0 && scp_status == E_SCP_SCONNECT_OK) { - // Don't run the reconnect script on the first connect + // Don't run the reconnect script on the first connect, + // unless we're configured to do so. if (session_increment_connect_count(g_session_data) == 0) { LOG(LOG_LEVEL_INFO, "User %s has connected to a session", g_login_info->username); + if (g_cfg->always_run_reconnect) + { + session_run_reconnect_script(g_login_info, + g_session_data); + } } else { LOG(LOG_LEVEL_INFO, "User %s has reconnected to a session", g_login_info->username); - session_run_reconnect_script(g_login_info, g_session_data); + session_run_reconnect_script(g_login_info, + g_session_data); } } diff --git a/sesman/sesman.ini.in b/sesman/sesman.ini.in index 23e70a72..ae9c6b0a 100644 --- a/sesman/sesman.ini.in +++ b/sesman/sesman.ini.in @@ -10,6 +10,10 @@ UserWindowManager=startwm.sh DefaultWindowManager=startwm.sh ; Give in full path or relative path to @sesmansysconfdir@ ReconnectScript=reconnectwm.sh +; Set this to 'yes' if you wish to reconnect script to be run on +; the first connection to a session. Normally the script is +; only run on reconnections. +#AlwaysRunReconnect=no [Security] AllowRootLogin=true