Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept full path for DefaultWindowManager #1147

Merged
merged 6 commits into from Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/man/Makefile.am
Expand Up @@ -17,7 +17,8 @@ SUBST_VARS = sed \
-e 's|@bindir[@]|$(bindir)|g' \
-e 's|@localstatedir[@]|$(localstatedir)|g' \
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@socketdir[@]|$(socketdir)|g'
-e 's|@socketdir[@]|$(socketdir)|g' \
-e 's|@xrdpconfdir[@]|$(sysconfdir)/xrdp|g'

subst_verbose = $(subst_verbose_@AM_V@)
subst_verbose_ = $(subst_verbose_@AM_DEFAULT_V@)
Expand Down
15 changes: 12 additions & 3 deletions docs/man/sesman.ini.5.in
Expand Up @@ -62,14 +62,23 @@ specified by \fBUserWindowManager\fR if it exists.

.TP
\fBUserWindowManager\fR=\fIfilename\fR
Name of the startup script relative to the user's home directory. If
Path of the startup script relative to the user's home directory. If
present and enabled by \fBEnableUserWindowManager\fR, that script is
executed instead of \fBDefaultWindowManager\fR.

.TP
\fBDefaultWindowManager\fR=\fIfilename\fR
Full path to the default startup script used by xrdp-sesman to start a
session if the user script is disabled or missing.
Full path or relative path of the default startup script used by xrdp-sesman
to start a 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@/startwm.sh\fR.

.TP
\fBReconnectScript\fR=\fIfilename\fR
Full path or relative path if the script which executed when users reconnects
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.

.SH "LOGGING"
Following parameters can be used in the \fB[Logging]\fR section.
Expand Down
54 changes: 50 additions & 4 deletions sesman/config.c
Expand Up @@ -105,6 +105,7 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n,
struct list *param_v)
{
int i;
int length;
char *buf;

list_clear(param_v);
Expand All @@ -115,8 +116,9 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n,
cf->listen_port[0] = '\0';
cf->enable_user_wm = 0;
cf->user_wm[0] = '\0';
cf->default_wm[0] = '\0';
cf->default_wm = 0;
cf->auth_file_path = 0;
cf->reconnect_sh = 0;

file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v);

Expand All @@ -126,7 +128,7 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n,

if (0 == g_strcasecmp(buf, SESMAN_CFG_DEFWM))
{
g_strncpy(cf->default_wm, (char *)list_get_item(param_v, i), 31);
cf->default_wm = g_strdup((char *)list_get_item(param_v, i));
}
else if (0 == g_strcasecmp(buf, SESMAN_CFG_USERWM))
{
Expand All @@ -148,6 +150,10 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n,
{
cf->auth_file_path = g_strdup((char *)list_get_item(param_v, i));
}
else if (g_strcasecmp(buf, SESMAN_CFG_RECONNECT_SH) == 0)
{
cf->reconnect_sh = g_strdup((char *)list_get_item(param_v, i));
}
}

/* checking for missing required parameters */
Expand All @@ -166,9 +172,46 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n,
cf->enable_user_wm = 0;
}

if ('\0' == cf->default_wm[0])
if (cf->default_wm == 0)
{
cf->default_wm = g_strdup("startwm.sh");
}
else if (g_strlen(cf->default_wm) == 0)
{
g_free(cf->default_wm);
cf->default_wm = g_strdup("startwm.sh");
}
/* if default_wm doesn't begin with '/', it's a relative path to XRDP_CFG_PATH */
if (cf->default_wm[0] != '/')
{
/* sizeof operator returns string length including null terminator */
length = sizeof(XRDP_CFG_PATH) + g_strlen(g_cfg->default_wm) + 1; /* '/' */
buf = (char *)g_malloc(length, 0);
g_sprintf(buf, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm);
g_free(g_cfg->default_wm);
g_cfg->default_wm = g_strdup(buf);
g_free(buf);
}

if (cf->reconnect_sh == 0)
{
cf->reconnect_sh = g_strdup("reconnectwm.sh");
}
else if (g_strlen(cf->reconnect_sh) == 0)
{
g_free(cf->reconnect_sh);
cf->reconnect_sh = g_strdup("reconnectwm.sh");
}
/* if reconnect_sh doesn't begin with '/', it's a relative path to XRDP_CFG_PATH */
if (cf->reconnect_sh[0] != '/')
{
g_strncpy(cf->default_wm, "startwm.sh", 11);
/* sizeof operator returns string length including null terminator */
length = sizeof(XRDP_CFG_PATH) + g_strlen(g_cfg->reconnect_sh) + 1; /* '/' */
buf = (char *)g_malloc(length, 0);
g_sprintf(buf, "%s/%s", XRDP_CFG_PATH, g_cfg->reconnect_sh);
g_free(g_cfg->reconnect_sh);
g_cfg->reconnect_sh = g_strdup(buf);
g_free(buf);
}

return 0;
Expand Down Expand Up @@ -436,6 +479,7 @@ config_dump(struct config_sesman *config)
g_writeln(" EnableUserWindowManager: %d", config->enable_user_wm);
g_writeln(" UserWindowManager: %s", config->user_wm);
g_writeln(" DefaultWindowManager: %s", config->default_wm);
g_writeln(" ReconnectScript: %s", config->reconnect_sh);
g_writeln(" AuthFilePath: %s",
((config->auth_file_path) ? (config->auth_file_path) : ("disabled")));

Expand Down Expand Up @@ -530,6 +574,8 @@ config_dump(struct config_sesman *config)
void
config_free(struct config_sesman *cs)
{
g_free(cs->default_wm);
g_free(cs->reconnect_sh);
g_free(cs->auth_file_path);
list_delete(cs->rdp_params);
list_delete(cs->vnc_params);
Expand Down
8 changes: 7 additions & 1 deletion sesman/config.h
Expand Up @@ -39,6 +39,7 @@
#define SESMAN_CFG_USERWM "UserWindowManager"
#define SESMAN_CFG_MAX_SESSION "MaxSessions"
#define SESMAN_CFG_AUTH_FILE_PATH "AuthFilePath"
#define SESMAN_CFG_RECONNECT_SH "ReconnectScript"

#define SESMAN_CFG_RDP_PARAMS "X11rdp"
#define SESMAN_CFG_XORG_PARAMS "Xorg"
Expand Down Expand Up @@ -198,12 +199,17 @@ struct config_sesman
* @var default_wm
* @brief Default window manager
*/
char default_wm[32];
char *default_wm;
/**
* @var user_wm
* @brief Default window manager
*/
char user_wm[32];
/**
* @var reconnect_sh
* @brief Script executed when reconnected
*/
char *reconnect_sh;
/**
* @var auth_file_path
* @brief Auth file path
Expand Down
6 changes: 6 additions & 0 deletions sesman/sesman.ini.in
@@ -1,9 +1,15 @@
;; See `man 5 sesman.ini` for details

[Globals]
ListenAddress=127.0.0.1
ListenPort=3350
EnableUserWindowManager=true
; Give in relative path to user's home directory
UserWindowManager=startwm.sh
; Give in full path or relative path to @sesmansysconfdir@
DefaultWindowManager=startwm.sh
; Give in full path or relative path to @sesmansysconfdir@
ReconnectScript=reconnectwm.sh

[Security]
AllowRootLogin=true
Expand Down
11 changes: 4 additions & 7 deletions sesman/session.c
Expand Up @@ -575,8 +575,7 @@ session_start_fork(tbus data, tui8 type, struct SCP_CONNECTION *c,
}
/* if we're here something happened to g_execlp3
so we try running the default window manager */
g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm);
g_execlp3(text, g_cfg->default_wm, 0);
g_execlp3(g_cfg->default_wm, g_cfg->default_wm, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should change the log message properly

                log_message(LOG_LEVEL_DEBUG, "        argv[0] = %s",
                            text);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


log_message(LOG_LEVEL_ALWAYS, "error starting default "
"wm for user %s - pid %d", s->username, g_getpid());
Expand All @@ -585,7 +584,7 @@ session_start_fork(tbus data, tui8 type, struct SCP_CONNECTION *c,
"%s", g_get_errno(), g_get_strerror());
log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:");
log_message(LOG_LEVEL_DEBUG, " argv[0] = %s",
text);
g_cfg->default_wm);
log_message(LOG_LEVEL_DEBUG, " argv[1] = %s",
g_cfg->default_wm);

Expand Down Expand Up @@ -863,7 +862,6 @@ static int
session_reconnect_fork(int display, char *username, long data)
{
int pid;
char text[256];

pid = g_fork();

Expand All @@ -878,11 +876,10 @@ session_reconnect_fork(int display, char *username, long data)
g_cfg->env_names,
g_cfg->env_values);
auth_set_env(data);
g_snprintf(text, 255, "%s/%s", XRDP_CFG_PATH, "reconnectwm.sh");

if (g_file_exist(text))
if (g_file_exist(g_cfg->reconnect_sh))
{
g_execlp3(text, g_cfg->default_wm, 0);
g_execlp3(g_cfg->reconnect_sh, g_cfg->reconnect_sh, 0);
}

g_exit(0);
Expand Down