From e4857b13fa679bb2b865db66c8d4f8b4bb9c2e70 Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Wed, 30 May 2018 02:32:44 +0900
Subject: [PATCH 1/5] sesman: config_read_logging function no longer exists
---
sesman/config.c | 3 ---
sesman/config.h | 14 --------------
2 files changed, 17 deletions(-)
diff --git a/sesman/config.c b/sesman/config.c
index 0363b330..d2768612 100644
--- a/sesman/config.c
+++ b/sesman/config.c
@@ -83,9 +83,6 @@ config_read(struct config_sesman *cfg)
config_read_rdp_params(fd, cfg, param_n, param_v);
config_read_xorg_params(fd, cfg, param_n, param_v);
- /* read logging config */
- // config_read_logging(fd, &(cfg->log), param_n, param_v);
-
/* read security config */
config_read_security(fd, &(cfg->sec), param_n, param_v);
diff --git a/sesman/config.h b/sesman/config.h
index 6bc10852..b26ab64f 100644
--- a/sesman/config.h
+++ b/sesman/config.h
@@ -276,20 +276,6 @@ int
config_read_globals(int file, struct config_sesman* cf,
struct list* param_n, struct list* param_v);
-/**
- *
- * @brief Reads sesman [logging] configuration section
- * @param file configuration file descriptor
- * @param lc pointer to a log_config struct
- * @param param_n parameter name list
- * @param param_v parameter value list
- * @return 0 on success, 1 on failure
- *
- */
-int
-config_read_logging(int file, struct log_config* lc, struct list* param_n,
- struct list* param_v);
-
/**
*
* @brief Reads sesman [Security] configuration section
From de33a7832e493ea0ad3aa01cb95f3b3cc154c6a4 Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Wed, 30 May 2018 02:34:48 +0900
Subject: [PATCH 2/5] sesman: s/XOrg/Xorg/g, no logic change
X.Org is usually spelled X.Org or Xorg.
---
sesman/config.c | 6 +++---
sesman/config.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/sesman/config.c b/sesman/config.c
index d2768612..1fedbf30 100644
--- a/sesman/config.c
+++ b/sesman/config.c
@@ -78,7 +78,7 @@ config_read(struct config_sesman *cfg)
/* read global config */
config_read_globals(fd, cfg, param_n, param_v);
- /* read Xvnc/X11rdp/XOrg parameter list */
+ /* read Xvnc/X11rdp/Xorg parameter list */
config_read_vnc_params(fd, cfg, param_n, param_v);
config_read_rdp_params(fd, cfg, param_n, param_v);
config_read_xorg_params(fd, cfg, param_n, param_v);
@@ -416,8 +416,8 @@ config_read_xorg_params(int file, struct config_sesman *cs,
(long) g_strdup((char *) list_get_item(param_v, i)));
}
- /* printing XOrg parameters */
- g_printf("XOrg parameters:\r\n");
+ /* printing Xorg parameters */
+ g_printf("Xorg parameters:\r\n");
for (i = 0; i < cs->xorg_params->count; i++)
{
diff --git a/sesman/config.h b/sesman/config.h
index b26ab64f..ef188715 100644
--- a/sesman/config.h
+++ b/sesman/config.h
@@ -320,7 +320,7 @@ config_read_rdp_params(int file, struct config_sesman* cs, struct list* param_n,
/**
*
- * @brief Reads sesman [XOrg] configuration section
+ * @brief Reads sesman [Xorg] configuration section
* @param file configuration file descriptor
* @param cs pointer to a config_sesman struct
* @param param_n parameter name list
From 19fa26a27ebf9e1294a7b242ec34d089ee4580a2 Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Wed, 30 May 2018 03:48:04 +0900
Subject: [PATCH 3/5] sesman: don't print config in reader function
reader function should just read. Add config_dump function to print read
config.
---
sesman/config.c | 178 ++++++++++++++++++++++++++++--------------------
sesman/config.h | 8 +++
2 files changed, 112 insertions(+), 74 deletions(-)
diff --git a/sesman/config.c b/sesman/config.c
index 1fedbf30..9eb3b07a 100644
--- a/sesman/config.c
+++ b/sesman/config.c
@@ -171,15 +171,6 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n,
g_strncpy(cf->default_wm, "startwm.sh", 11);
}
- /* showing read config */
- g_printf("sesman config:\r\n");
- g_printf("\tListenAddress: %s\r\n", cf->listen_address);
- g_printf("\tListenPort: %s\r\n", cf->listen_port);
- g_printf("\tEnableUserWindowManager: %i\r\n", cf->enable_user_wm);
- g_printf("\tUserWindowManager: %s\r\n", cf->user_wm);
- g_printf("\tDefaultWindowManager: %s\r\n", cf->default_wm);
- g_printf("\tAuthFilePath: %s\r\n", ((cf->auth_file_path) ? (cf->auth_file_path) : ("disabled")));
-
return 0;
}
@@ -241,30 +232,6 @@ config_read_security(int file, struct config_security *sc,
}
}
- /* printing security config */
- g_printf("security configuration:\r\n");
- g_printf("\tAllowRootLogin: %i\r\n", sc->allow_root);
- g_printf("\tMaxLoginRetry: %i\r\n", sc->login_retry);
- g_printf("\tAlwaysGroupCheck: %i\r\n", sc->ts_always_group_check);
-
- if (sc->ts_users_enable)
- {
- g_printf("\tTSUsersGroup: %i\r\n", sc->ts_users);
- }
- else
- {
- g_printf("\tNo TSUsersGroup defined\r\n");
- }
-
- if (sc->ts_admins_enable)
- {
- g_printf("\tTSAdminsGroup: %i\r\n", sc->ts_admins);
- }
- else
- {
- g_printf("\tNo TSAdminsGroup defined\r\n");
- }
-
return 0;
}
@@ -352,15 +319,6 @@ config_read_sessions(int file, struct config_sessions *se, struct list *param_n,
}
}
- /* printing session config */
- g_printf("session configuration:\r\n");
- g_printf("\tMaxSessions: %i\r\n", se->max_sessions);
- g_printf("\tX11DisplayOffset: %i\r\n", se->x11_display_offset);
- g_printf("\tKillDisconnected: %i\r\n", se->kill_disconnected);
- g_printf("\tIdleTimeLimit: %i\r\n", se->max_idle_time);
- g_printf("\tDisconnectedTimeLimit: %i\r\n", se->max_disc_time);
- g_printf("\tPolicy: %i\r\n", se->policy);
-
return 0;
}
@@ -384,14 +342,6 @@ config_read_rdp_params(int file, struct config_sesman *cs, struct list *param_n,
list_add_item(cs->rdp_params, (long)g_strdup((char *)list_get_item(param_v, i)));
}
- /* printing X11rdp parameters */
- g_printf("X11rdp parameters:\r\n");
-
- for (i = 0; i < cs->rdp_params->count; i++)
- {
- g_printf("\tParameter %02d %s\r\n", i, (char *)list_get_item(cs->rdp_params, i));
- }
-
return 0;
}
@@ -416,15 +366,6 @@ config_read_xorg_params(int file, struct config_sesman *cs,
(long) g_strdup((char *) list_get_item(param_v, i)));
}
- /* printing Xorg parameters */
- g_printf("Xorg parameters:\r\n");
-
- for (i = 0; i < cs->xorg_params->count; i++)
- {
- g_printf("\tParameter %02d %s\r\n",
- i, (char *) list_get_item(cs->xorg_params, i));
- }
-
return 0;
}
@@ -448,14 +389,6 @@ config_read_vnc_params(int file, struct config_sesman *cs, struct list *param_n,
list_add_item(cs->vnc_params, (long)g_strdup((char *)list_get_item(param_v, i)));
}
- /* printing Xvnc parameters */
- g_printf("Xvnc parameters:\r\n");
-
- for (i = 0; i < cs->vnc_params->count; i++)
- {
- g_printf("\tParameter %02d %s\r\n", i, (char *)list_get_item(cs->vnc_params, i));
- }
-
return 0;
}
@@ -484,17 +417,114 @@ config_read_session_variables(int file, struct config_sesman *cs,
(tintptr) g_strdup((char *) list_get_item(param_v, i)));
}
- /* printing session variables */
- g_writeln("%s parameters:", SESMAN_CFG_SESSION_VARIABLES);
+ return 0;
+}
- for (i = 0; i < cs->env_names->count; i++)
+void
+config_dump(struct config_sesman *config)
+{
+ int i;
+ struct config_sessions *se;
+ struct config_security *sc;
+ se = &(config->sess);
+ sc = &(config->sec);
+
+ /* Global sesman configuration */
+ g_writeln("Global configuration:");
+ g_writeln(" ListenAddress: %s", config->listen_address);
+ g_writeln(" ListenPort: %s", config->listen_port);
+ g_writeln(" EnableUserWindowManager: %d", config->enable_user_wm);
+ g_writeln(" UserWindowManager: %s", config->user_wm);
+ g_writeln(" DefaultWindowManager: %s", config->default_wm);
+ g_writeln(" AuthFilePath: %s",
+ ((config->auth_file_path) ? (config->auth_file_path) : ("disabled")));
+
+ /* Session configuration */
+ g_writeln("Session configuration:");
+ g_writeln(" MaxSessions: %d", se->max_sessions);
+ g_writeln(" X11DisplayOffset: %d", se->x11_display_offset);
+ g_writeln(" KillDisconnected: %d", se->kill_disconnected);
+ g_writeln(" IdleTimeLimit: %d", se->max_idle_time);
+ g_writeln(" DisconnectedTimeLimit: %d", se->max_disc_time);
+ g_writeln(" Policy: %d", se->policy);
+
+ /* Security configuration */
+ g_writeln("Security configuration:");
+ g_writeln(" AllowRootLogin: %d", sc->allow_root);
+ g_writeln(" MaxLoginRetry: %d", sc->login_retry);
+ g_writeln(" AlwaysGroupCheck: %d", sc->ts_always_group_check);
+
+ g_printf( " TSUsersGroup: ");
+ if (sc->ts_users_enable)
{
- g_writeln(" Parameter %02d %s=%s", i,
- (char *) list_get_item(cs->env_names, i),
- (char *) list_get_item(cs->env_values, i));
+ g_printf("%d", sc->ts_users);
+ }
+ else
+ {
+ g_printf("(not defined)");
+ }
+ g_writeln("%s", "");
+
+ g_printf( " TSAdminsGroup: ");
+ if (sc->ts_admins_enable)
+ {
+ g_printf("%d", sc->ts_admins);
+ }
+ else
+ {
+ g_printf("(not defined)");
+ }
+ g_writeln("%s", "");
+
+
+ /* Xorg */
+ if (config->xorg_params->count)
+ {
+ g_writeln("Xorg parameters:");
}
- return 0;
+ for (i = 0; i < config->xorg_params->count; i++)
+ {
+ g_writeln(" Parameter %02d %s",
+ i, (char *) list_get_item(config->xorg_params, i));
+ }
+
+ /* Xvnc */
+ if (config->vnc_params->count)
+ {
+ g_writeln("Xvnc parameters:");
+ }
+
+ for (i = 0; i < config->vnc_params->count; i++)
+ {
+ g_writeln(" Parameter %02d %s",
+ i, (char *)list_get_item(config->vnc_params, i));
+ }
+
+ /* X11rdp */
+ if (config->rdp_params->count)
+ {
+ g_writeln("X11rdp parameters:");
+ }
+
+ for (i = 0; i < config->rdp_params->count; i++)
+ {
+ g_writeln(" Parameter %02d %s",
+ i, (char *)list_get_item(config->rdp_params, i));
+ }
+
+ /* SessionVariables */
+ if (config->env_names->count)
+ {
+ g_writeln("%s parameters:", SESMAN_CFG_SESSION_VARIABLES);
+ }
+
+ for (i = 0; i < config->env_names->count; i++)
+ {
+ g_writeln(" Parameter %02d %s=%s",
+ i, (char *) list_get_item(config->env_names, i),
+ (char *) list_get_item(config->env_values, i));
+ }
}
void
diff --git a/sesman/config.h b/sesman/config.h
index ef188715..c7cb50fd 100644
--- a/sesman/config.h
+++ b/sesman/config.h
@@ -349,6 +349,14 @@ config_read_vnc_params(int file, struct config_sesman* cs, struct list* param_n,
int
config_read_session_variables(int file, struct config_sesman *cs,
struct list *param_n, struct list *param_v);
+/**
+ *
+ * @brief Dumps configuration
+ * @param pointer to a config_sesman struct
+ *
+ */
+void
+config_dump(struct config_sesman *config);
void
config_free(struct config_sesman *cs);
From 6ae3052a0f0c87393977264f9d19f168e4bfe02a Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Wed, 30 May 2018 04:10:06 +0900
Subject: [PATCH 4/5] sesman: don't spit on the console when starting
As the Debian patch[1] expresses, spitting messages on the console when
a process starts in background is a bad idea. Everything should be
written to log file and daemon should start silently. This is a first
step to shut up daemons.
Got some idea from Debian Remote Maintainers and Thorsten Glaser,
thanks!
[1] https://salsa.debian.org/debian-remote-team/xrdp/blob/2751ad4d62b1f63dbc2e4b8fa1580fa54b0f5460/debian/patches/shutup-daemon.diff
---
sesman/sesman.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/sesman/sesman.c b/sesman/sesman.c
index a89d2f55..8abdc4ac 100644
--- a/sesman/sesman.c
+++ b/sesman/sesman.c
@@ -209,8 +209,7 @@ main(int argc, char **argv)
if (1 == argc)
{
- /* no options on command line. normal startup */
- g_printf("starting sesman...\n");
+ /* start in daemon mode if no cli options */
daemon = 1;
}
else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) ||
@@ -312,6 +311,12 @@ main(int argc, char **argv)
g_exit(1);
}
+ /* not to spit on the console, show config summary only when running in foreground */
+ if (!daemon)
+ {
+ config_dump(g_cfg);
+ }
+
g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH);
/* starting logging subsystem */
From 2262f1361f86292e767f9a62c4ee42d65a3485cb Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Fri, 1 Jun 2018 22:44:51 +0900
Subject: [PATCH 5/5] sesman: close stdout/stderr earlier
not to spit on the console
---
sesman/sesman.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/sesman/sesman.c b/sesman/sesman.c
index 8abdc4ac..7aa098fc 100644
--- a/sesman/sesman.c
+++ b/sesman/sesman.c
@@ -342,9 +342,18 @@ main(int argc, char **argv)
g_exit(1);
}
+ if (daemon)
+ {
+ /* not to spit on the console, shut up stdout/stderr before anything's logged */
+ g_file_close(0);
+ g_file_close(1);
+ g_file_close(2);
+ }
+
/* libscp initialization */
scp_init();
+
if (daemon)
{
/* start of daemonizing code */
@@ -363,10 +372,6 @@ main(int argc, char **argv)
g_exit(0);
}
- g_file_close(0);
- g_file_close(1);
- g_file_close(2);
-
if (g_file_open("/dev/null") < 0)
{
}