diff --git a/common/xrdp_client_info.h b/common/xrdp_client_info.h index ca349f0a..3e999677 100644 --- a/common/xrdp_client_info.h +++ b/common/xrdp_client_info.h @@ -126,8 +126,11 @@ struct xrdp_client_info int capture_code; int capture_format; - char certificate[1024]; - char key_file[1024]; + char certificate[256]; + char key_file[256]; + char rsakeys_ini_file[256]; + char xrdp_keyboard_ini_file[256]; + char keymaps_path[256]; /* X11 keyboard layout - inferred from keyboard type/subtype */ char model[16]; diff --git a/docs/man/xrdp-sesrun.8.in b/docs/man/xrdp-sesrun.8.in index 86e9129d..abdbb76f 100644 --- a/docs/man/xrdp-sesrun.8.in +++ b/docs/man/xrdp-sesrun.8.in @@ -4,7 +4,7 @@ xrdp\-sesrun \- \fBsesman\fR(8) session launcher .SH "SYNTAX" .B xrdp\-sesrun -.I server username password width height bpp +.I sesman.ini server username password width height bpp .SH "DESCRIPTION" \fBxrdp\-sesrun\fR starts a session using \fBxrdp\-sesman\fR(8). @@ -13,6 +13,9 @@ This is a tool useful for testing, it simply behaves like xrdp when some user lo .SH "OPTIONS" .TP +.I sesman.ini +Path to sesman.ini (in most cases @sysconfdir@/xrdp/sesman.ini) +.TP .I server Server on which sesman is running .TP diff --git a/libxrdp/libxrdp.c b/libxrdp/libxrdp.c index f82ae953..b85b0fee 100644 --- a/libxrdp/libxrdp.c +++ b/libxrdp/libxrdp.c @@ -35,11 +35,12 @@ /******************************************************************************/ struct xrdp_session *EXPORT_CC -libxrdp_init(tbus id, struct trans *trans) +libxrdp_init(const char *xrdp_ini_file, tbus id, struct trans *trans) { struct xrdp_session *session; session = (struct xrdp_session *)g_malloc(sizeof(struct xrdp_session), 1); + session->xrdp_ini_file = xrdp_ini_file; session->id = id; session->trans = trans; session->rdp = xrdp_rdp_create(session, trans); diff --git a/libxrdp/libxrdpinc.h b/libxrdp/libxrdpinc.h index c236bec9..5b866a24 100644 --- a/libxrdp/libxrdpinc.h +++ b/libxrdp/libxrdpinc.h @@ -64,6 +64,7 @@ struct xrdp_session { tintptr id; struct trans *trans; + const char* xrdp_ini_file; int (*callback)(intptr_t id, int msg, intptr_t param1, intptr_t param2, intptr_t param3, intptr_t param4); void *rdp; @@ -85,7 +86,7 @@ struct xrdp_drdynvc_procs }; struct xrdp_session * -libxrdp_init(tbus id, struct trans *trans); +libxrdp_init(const char *xrdp_ini_file, tbus id, struct trans *trans); int libxrdp_exit(struct xrdp_session *session); int diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index e4ee660f..52bb4549 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -25,6 +25,7 @@ #include "libxrdp.h" #include "log.h" #include "ssl_calls.h" +#include #if defined(XRDP_NEUTRINORDP) #include @@ -41,27 +42,33 @@ /*****************************************************************************/ static int -xrdp_rdp_read_config(struct xrdp_client_info *client_info) +xrdp_rdp_read_config(const char *cfg_file, struct xrdp_client_info *client_info) { int index = 0; struct list *items = (struct list *)NULL; struct list *values = (struct list *)NULL; char *item = NULL; char *value = NULL; - char cfg_file[256]; + char cfg_dir[256]; int pos; char *tmp = NULL; int tmp_length = 0; - /* initialize (zero out) local variables: */ - g_memset(cfg_file, 0, sizeof(char) * 256); - items = list_create(); items->auto_free = 1; values = list_create(); values->auto_free = 1; - g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); + g_strncpy(cfg_dir, cfg_file, 255); + *(strrchr(cfg_dir, '/')) = 0; // cfg_file validated to contain '/' DEBUG(("cfg_file %s", cfg_file)); + + /* default location is next to xrdp.ini */ + g_snprintf(client_info->certificate, 255, "%s/cert.pem", cfg_dir); + g_snprintf(client_info->key_file, 255, "%s/key.pem", cfg_dir); + g_snprintf(client_info->xrdp_keyboard_ini_file, 255, "%s/xrdp_keyboard.ini", cfg_dir); + g_snprintf(client_info->rsakeys_ini_file, 255, "%s/rsakeys.ini", cfg_dir); + g_snprintf(client_info->keymaps_path, 255, "%s", cfg_dir); + file_by_name_read_section(cfg_file, "globals", items, values); for (index = 0; index < items->count; index++) @@ -215,20 +222,19 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) } else if (g_strcasecmp(item, "certificate") == 0) { - g_memset(client_info->certificate, 0, sizeof(char) * 1024); + g_memset(client_info->certificate, 0, sizeof(char) * 256); if (g_strlen(value) == 0) { /* default certificate path */ - g_snprintf(client_info->certificate, 1023, "%s/cert.pem", XRDP_CFG_PATH); + g_snprintf(client_info->certificate, 255, "%s/cert.pem", cfg_dir); log_message(LOG_LEVEL_INFO, "Using default X.509 certificate: %s", client_info->certificate); - } else if (value[0] != '/') { /* default certificate path */ - g_snprintf(client_info->certificate, 1023, "%s/cert.pem", XRDP_CFG_PATH); + g_snprintf(client_info->certificate, 255, "%s/cert.pem", cfg_dir); log_message(LOG_LEVEL_WARNING, "X.509 certificate should use absolute path, using " "default instead: %s", client_info->certificate); @@ -236,7 +242,7 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) else { /* use user defined certificate */ - g_strncpy(client_info->certificate, value, 1023); + g_strncpy(client_info->certificate, value, 255); } if (!g_file_readable(client_info->certificate)) @@ -247,18 +253,18 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) } else if (g_strcasecmp(item, "key_file") == 0) { - g_memset(client_info->key_file, 0, sizeof(char) * 1024); + g_memset(client_info->key_file, 0, sizeof(char) * 256); if (g_strlen(value) == 0) { /* default key_file path */ - g_snprintf(client_info->key_file, 1023, "%s/key.pem", XRDP_CFG_PATH); + g_snprintf(client_info->key_file, 255, "%s/key.pem", cfg_dir); log_message(LOG_LEVEL_INFO, "Using default X.509 key file: %s", client_info->key_file); } else if (value[0] != '/') { /* default key_file path */ - g_snprintf(client_info->key_file, 1023, "%s/key.pem", XRDP_CFG_PATH); + g_snprintf(client_info->key_file, 255, "%s/key.pem", cfg_dir); log_message(LOG_LEVEL_WARNING, "X.509 key file should use absolute path, using " "default instead: %s", client_info->key_file); @@ -266,7 +272,52 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) else { /* use user defined key_file */ - g_strncpy(client_info->key_file, value, 1023); + g_strncpy(client_info->key_file, value, 255); + } + } + else if (g_strcasecmp(item, "rsakeys_ini") == 0) + { + if (value[0] != '/') + { + g_snprintf(client_info->rsakeys_ini_file, 255, "%s/rsakeys.ini", cfg_dir); + log_message(LOG_LEVEL_WARNING, + "rsakeys.ini file should use absolute path, using " + "default instead: %s", client_info->rsakeys_ini_file); + } + else + { + /* use user defined rsakeys.ini */ + g_strncpy(client_info->rsakeys_ini_file, value, 255); + } + } + else if (g_strcasecmp(item, "xrdp_keyboard_ini") == 0) + { + if (value[0] != '/') + { + g_snprintf(client_info->xrdp_keyboard_ini_file, 255, "%s/xrdp_keyboard.ini", cfg_dir); + log_message(LOG_LEVEL_WARNING, + "xrdp_keyboard.ini file should use absolute path, using " + "default instead: %s", client_info->xrdp_keyboard_ini_file); + } + else + { + /* use user defined xrdp_keyboard.ini */ + g_strncpy(client_info->xrdp_keyboard_ini_file, value, 255); + } + } + else if (g_strcasecmp(item, "keymaps_path") == 0) + { + if (value[0] != '/') + { + g_snprintf(client_info->keymaps_path, 255, "%s", cfg_dir); + log_message(LOG_LEVEL_WARNING, + "keymaps_path should use absolute path, using " + "default instead: %s", client_info->keymaps_path); + } + else + { + /* use user defined xrdp_keyboard.ini */ + g_strncpy(client_info->keymaps_path, value, 255); } if (!g_file_readable(client_info->key_file)) @@ -349,7 +400,7 @@ xrdp_rdp_create(struct xrdp_session *session, struct trans *trans) self->session = session; self->share_id = 66538; /* read ini settings */ - xrdp_rdp_read_config(&self->client_info); + xrdp_rdp_read_config(session->xrdp_ini_file, &self->client_info); /* create sec layer */ self->sec_layer = xrdp_sec_create(self, trans); /* default 8 bit v1 color bitmap cache entries and size */ diff --git a/libxrdp/xrdp_sec.c b/libxrdp/xrdp_sec.c index 31197ab6..65fa1b0e 100644 --- a/libxrdp/xrdp_sec.c +++ b/libxrdp/xrdp_sec.c @@ -237,7 +237,6 @@ xrdp_load_keyboard_layout(struct xrdp_client_info *client_info) char *item = (char *)NULL; char *value = (char *)NULL; char *q = (char *)NULL; - char keyboard_cfg_file[256] = { 0 }; char rdp_layout[256] = { 0 }; LLOGLN(0, ("xrdp_load_keyboard_layout: keyboard_type [%d] keyboard_subtype [%d]", @@ -260,10 +259,9 @@ xrdp_load_keyboard_layout(struct xrdp_client_info *client_info) client_info->keyboard_subtype = 1; } - g_snprintf(keyboard_cfg_file, 255, "%s/xrdp_keyboard.ini", XRDP_CFG_PATH); - LLOGLN(10, ("keyboard_cfg_file %s", keyboard_cfg_file)); + LLOGLN(10, ("keyboard_cfg_file %s", client_info->xrdp_keyboard_ini_file)); - fd = g_file_open(keyboard_cfg_file); + fd = g_file_open(client_info->xrdp_keyboard_ini_file); if (fd >= 0) { @@ -435,7 +433,7 @@ xrdp_load_keyboard_layout(struct xrdp_client_info *client_info) else { LLOGLN(0, ("xrdp_load_keyboard_layout: error opening %s", - keyboard_cfg_file)); + client_info->xrdp_keyboard_ini_file)); } } @@ -2252,7 +2250,6 @@ xrdp_sec_incoming(struct xrdp_sec *self) int index = 0; char *item = NULL; char *value = NULL; - char key_file[256]; DEBUG((" in xrdp_sec_incoming:")); iso = self->mcs_layer->iso_layer; @@ -2296,19 +2293,17 @@ xrdp_sec_incoming(struct xrdp_sec *self) } if (self->crypt_method != CRYPT_METHOD_NONE) { - g_memset(key_file, 0, sizeof(char) * 256); g_random(self->server_random, 32); items = list_create(); items->auto_free = 1; values = list_create(); values->auto_free = 1; - g_snprintf(key_file, 255, "%s/rsakeys.ini", XRDP_CFG_PATH); - if (file_by_name_read_section(key_file, "keys", items, values) != 0) + if (file_by_name_read_section(self->rdp_layer->client_info.rsakeys_ini_file, "keys", items, values) != 0) { /* this is a show stopper */ log_message(LOG_LEVEL_ALWAYS, "XRDP cannot read file: %s " - "(check permissions)", key_file); + "(check permissions)", self->rdp_layer->client_info.rsakeys_ini_file); list_delete(items); list_delete(values); return 1; diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c index 7a0de556..e9960f6a 100644 --- a/sesman/chansrv/chansrv.c +++ b/sesman/chansrv/chansrv.c @@ -61,6 +61,7 @@ int g_rdpdr_chan_id = -1; /* rdpdr */ int g_rail_chan_id = -1; /* rail */ char *g_exec_name; +const char *g_sesman_ini_file; tbus g_exec_event; tbus g_exec_mutex; tbus g_exec_sem; @@ -1623,22 +1624,19 @@ main_cleanup(void) static int read_ini(void) { - char filename[256]; struct list *names; struct list *values; char *name; char *value; int index; - g_memset(filename, 0, (sizeof(char) * 256)); names = list_create(); names->auto_free = 1; values = list_create(); values->auto_free = 1; g_use_unix_socket = 0; - g_snprintf(filename, 255, "%s/sesman.ini", XRDP_CFG_PATH); - if (file_by_name_read_section(filename, "Globals", names, values) == 0) + if (file_by_name_read_section(g_sesman_ini_file, "Globals", names, values) == 0) { for (index = 0; index < names->count; index++) { @@ -1781,6 +1779,12 @@ main(int argc, char **argv) struct log_config logconfig; enum logLevels log_level; + if (argc < 2) { + g_writeln("usage: %s sesman.ini", argv[0]); + return 1; + } + g_sesman_ini_file = argv[1]; + g_init("xrdp-chansrv"); /* os_calls */ log_path[255] = 0; diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 1095b63e..b87ccde4 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -246,6 +246,7 @@ struct opendir_req static char g_fuse_mount_name[256] = "xrdp_client"; FIFO g_fifo_opendir; +extern const char *g_sesman_ini_file; /* in chansrv.c */ static struct list *g_req_list = 0; static struct xrdp_fs g_xrdp_fs; /* an inst of xrdp file system */ @@ -369,7 +370,6 @@ int load_fuse_config(void) { int index; - char cfg_file[256]; struct list *items; struct list *values; char *item; @@ -379,8 +379,7 @@ load_fuse_config(void) items->auto_free = 1; values = list_create(); values->auto_free = 1; - g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH); - file_by_name_read_section(cfg_file, "Chansrv", items, values); + file_by_name_read_section(g_sesman_ini_file, "Chansrv", items, values); for (index = 0; index < items->count; index++) { item = (char *)list_get_item(items, index); diff --git a/sesman/config.c b/sesman/config.c index 78949995..895320b5 100644 --- a/sesman/config.c +++ b/sesman/config.c @@ -33,6 +33,7 @@ #include "file.h" #include "sesman.h" #include "log.h" +#include extern struct config_sesman *g_cfg; /* in sesman.c */ @@ -40,15 +41,14 @@ extern struct config_sesman *g_cfg; /* in sesman.c */ /******************************************************************************/ int -config_read(struct config_sesman *cfg) +config_read(const char *cfg_file, struct config_sesman *cfg) { int fd; struct list *sec; struct list *param_n; struct list *param_v; - char cfg_file[256]; + char cfg_dir[256]; - g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH); fd = g_file_open(cfg_file); if (-1 == fd) @@ -76,7 +76,10 @@ config_read(struct config_sesman *cfg) param_v->auto_free = 1; /* read global config */ - config_read_globals(fd, cfg, param_n, param_v); + g_strcpy(cfg_dir, cfg_file); + *(strrchr(cfg_dir, '/')) = 0; // cfg_file validated to contain '/' + + config_read_globals(cfg_dir, fd, cfg, param_n, param_v); /* read Xvnc/X11rdp/Xorg parameter list */ config_read_vnc_params(fd, cfg, param_n, param_v); @@ -101,11 +104,10 @@ config_read(struct config_sesman *cfg) /******************************************************************************/ int -config_read_globals(int file, struct config_sesman *cf, struct list *param_n, +config_read_globals(const char *base_dir, int file, struct config_sesman *cf, struct list *param_n, struct list *param_v) { int i; - int length; char *buf; list_clear(param_v); @@ -181,13 +183,12 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n, 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 default_wm doesn't begin with '/', it's a relative path from base_dir */ 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); + buf = (char *)g_malloc(g_strlen(base_dir) + 1 + g_strlen(g_cfg->default_wm) + 1, 0); + g_sprintf(buf, "%s/%s", base_dir, g_cfg->default_wm); g_free(g_cfg->default_wm); g_cfg->default_wm = g_strdup(buf); g_free(buf); @@ -206,9 +207,8 @@ config_read_globals(int file, struct config_sesman *cf, struct list *param_n, if (cf->reconnect_sh[0] != '/') { /* 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); + buf = (char *)g_malloc(g_strlen(base_dir) + 1 + g_strlen(g_cfg->reconnect_sh) + 1, 0); + g_sprintf(buf, "%s/%s", base_dir, g_cfg->reconnect_sh); g_free(g_cfg->reconnect_sh); g_cfg->reconnect_sh = g_strdup(buf); g_free(buf); diff --git a/sesman/config.h b/sesman/config.h index 6e63fcef..f6a5fe13 100644 --- a/sesman/config.h +++ b/sesman/config.h @@ -197,14 +197,14 @@ struct config_sesman int enable_user_wm; /** * @var default_wm - * @brief Default window manager + * @brief Default window manager, absolute path */ char *default_wm; /** * @var user_wm - * @brief Default window manager + * @brief Default window manager, path relative to user's home */ - char user_wm[32]; + char user_wm[256]; /** * @var reconnect_sh * @brief Script executed when reconnected @@ -266,7 +266,7 @@ struct config_sesman * */ int -config_read(struct config_sesman* cfg); +config_read(const char *sesman_ini_file, struct config_sesman* cfg); /** * @@ -279,7 +279,7 @@ config_read(struct config_sesman* cfg); * */ int -config_read_globals(int file, struct config_sesman* cf, +config_read_globals(const char *base_dir, int file, struct config_sesman* cf, struct list* param_n, struct list* param_v); /** diff --git a/sesman/sesman.c b/sesman/sesman.c index 7aa098fc..fc74c5f9 100644 --- a/sesman/sesman.c +++ b/sesman/sesman.c @@ -34,6 +34,7 @@ int g_sck; int g_pid; unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; struct config_sesman *g_cfg; /* defined in config.h */ +char g_sesman_ini_file[256]; tintptr g_term_event = 0; @@ -185,6 +186,7 @@ print_usage(int retcode) g_printf("Usage: xrdp-sesman [options]\n"); g_printf(" -n, --nodaemon run as foreground process\n"); g_printf(" -k, --kill kill running xrdp-sesman\n"); + g_printf(" -c, --config config file (default '%s/sesman.ini')\n", XRDP_CFG_PATH); g_printf(" -h, --help show this help\n"); g_deinit(); g_exit(retcode); @@ -197,90 +199,98 @@ main(int argc, char **argv) int fd; enum logReturns log_error; int error; - int daemon = 1; + int index; + int daemon = 1; /* start in daemon mode if no cli options */ int pid; char pid_s[32]; char text[256]; char pid_file[256]; - char cfg_file[256]; g_init("xrdp-sesman"); g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH); + g_snprintf(g_sesman_ini_file, 255, "%s/sesman.ini", XRDP_CFG_PATH); - if (1 == argc) - { - /* start in daemon mode if no cli options */ - daemon = 1; - } - else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) || - (0 == g_strcasecmp(argv[1], "-nodaemon")) || - (0 == g_strcasecmp(argv[1], "-n")) || - (0 == g_strcasecmp(argv[1], "-ns")))) - { - /* starts sesman not daemonized */ - g_printf("starting sesman in foreground...\n"); - daemon = 0; - } - else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--help")) || - (0 == g_strcasecmp(argv[1], "-help")) || - (0 == g_strcasecmp(argv[1], "-h")))) - { - print_usage(0); - } - else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) || - (0 == g_strcasecmp(argv[1], "-kill")) || - (0 == g_strcasecmp(argv[1], "-k")))) - { - /* killing running sesman */ - /* check if sesman is running */ - if (!g_file_exist(pid_file)) + for (index = 1; index < argc; index ++) { + if ((0 == g_strcasecmp(argv[index], "--nodaemon")) || + (0 == g_strcasecmp(argv[index], "-nodaemon")) || + (0 == g_strcasecmp(argv[index], "-n")) || + (0 == g_strcasecmp(argv[index], "-ns"))) { - g_printf("sesman is not running (pid file not found - %s)\n", pid_file); - g_deinit(); - g_exit(1); + /* starts sesman not daemonized */ + g_printf("starting sesman in foreground...\n"); + daemon = 0; } - - fd = g_file_open(pid_file); - - if (-1 == fd) + else if ((0 == g_strcasecmp(argv[index], "--help")) || + (0 == g_strcasecmp(argv[index], "-help")) || + (0 == g_strcasecmp(argv[index], "-h"))) { - g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror()); - return 1; + print_usage(0); } - - g_memset(pid_s, 0, sizeof(pid_s)); - error = g_file_read(fd, pid_s, 31); - - if (-1 == error) + else if ((0 == g_strcasecmp(argv[index], "--kill")) || + (0 == g_strcasecmp(argv[index], "-kill")) || + (0 == g_strcasecmp(argv[index], "-k"))) { - g_printf("error reading pid file: %s\n", g_get_strerror()); + /* killing running sesman */ + /* check if sesman is running */ + if (!g_file_exist(pid_file)) + { + g_printf("sesman is not running (pid file not found - %s)\n", pid_file); + g_deinit(); + g_exit(1); + } + + fd = g_file_open(pid_file); + + if (-1 == fd) + { + g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror()); + return 1; + } + + g_memset(pid_s, 0, sizeof(pid_s)); + error = g_file_read(fd, pid_s, 31); + + if (-1 == error) + { + g_printf("error reading pid file: %s\n", g_get_strerror()); + g_file_close(fd); + g_deinit(); + g_exit(error); + } + g_file_close(fd); + pid = g_atoi(pid_s); + + error = g_sigterm(pid); + + if (0 != error) + { + g_printf("error killing sesman: %s\n", g_get_strerror()); + } + else + { + g_file_delete(pid_file); + } + g_deinit(); g_exit(error); } - - g_file_close(fd); - pid = g_atoi(pid_s); - - error = g_sigterm(pid); - - if (0 != error) + else if (index != argc-1 && ((0 == g_strcasecmp(argv[index], "--config")) || + (0 == g_strcasecmp(argv[index], "-c")))) { - g_printf("error killing sesman: %s\n", g_get_strerror()); + index++; + if (argv[index][0] != '/') { + g_writeln("invalid argument of --config: path must be absolute"); + return 1; + } + g_strncpy(g_sesman_ini_file, argv[index], 255); } else { - g_file_delete(pid_file); + /* there's something strange on the command line */ + g_printf("Error: invalid command line arguments\n\n"); + print_usage(1); } - - g_deinit(); - g_exit(error); - } - else - { - /* there's something strange on the command line */ - g_printf("Error: invalid command line arguments\n\n"); - print_usage(1); } if (g_file_exist(pid_file)) @@ -304,7 +314,7 @@ main(int argc, char **argv) } //g_cfg->log.fd = -1; /* don't use logging before reading its config */ - if (0 != config_read(g_cfg)) + if (0 != config_read(g_sesman_ini_file, g_cfg)) { g_printf("error reading config: %s\nquitting.\n", g_get_strerror()); g_deinit(); @@ -317,10 +327,8 @@ main(int argc, char **argv) config_dump(g_cfg); } - g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH); - /* starting logging subsystem */ - log_error = log_start(cfg_file, "xrdp-sesman"); + log_error = log_start(g_sesman_ini_file, "xrdp-sesman"); if (log_error != LOG_STARTUP_OK) { diff --git a/sesman/session.c b/sesman/session.c index 0d9fdc70..1f55dce1 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -50,6 +50,7 @@ extern unsigned char g_fixedkey[8]; extern struct config_sesman *g_cfg; /* in sesman.c */ extern int g_sck; /* in sesman.c */ +extern char g_sesman_ini_file[]; /* in sesman.c */ struct session_chain *g_sessions; int g_session_count; @@ -368,6 +369,7 @@ session_start_chansrv(char *username, int display) XRDP_SBIN_PATH); list_add_item(chansrv_params, (intptr_t) g_strdup(exe_path)); + list_add_item(chansrv_params, (intptr_t) g_strdup(g_sesman_ini_file)); list_add_item(chansrv_params, 0); /* mandatory */ env_set_user(username, 0, display, diff --git a/sesman/sig.c b/sesman/sig.c index 782e8fe2..bfb75966 100644 --- a/sesman/sig.c +++ b/sesman/sig.c @@ -35,6 +35,7 @@ extern int g_sck; extern int g_pid; extern struct config_sesman *g_cfg; /* in sesman.c */ +extern char g_sesman_ini_file[]; /* in sesman.c */ extern tbus g_term_event; /******************************************************************************/ @@ -67,7 +68,6 @@ sig_sesman_reload_cfg(int sig) { int error; struct config_sesman *cfg; - char cfg_file[256]; log_message(LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1); @@ -85,7 +85,7 @@ sig_sesman_reload_cfg(int sig) return; } - if (config_read(cfg) != 0) + if (config_read(g_sesman_ini_file, cfg) != 0) { log_message(LOG_LEVEL_ERROR, "error reading config - keeping old cfg"); g_free(cfg); @@ -101,10 +101,9 @@ sig_sesman_reload_cfg(int sig) /* replace old config with newly read one */ g_cfg = cfg; - g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH); /* start again logging subsystem */ - error = log_start(cfg_file, "xrdp-sesman"); + error = log_start(g_sesman_ini_file, "xrdp-sesman"); if (error != LOG_STARTUP_OK) { diff --git a/sesman/tools/sesrun.c b/sesman/tools/sesrun.c index 57335dd1..01dc78ea 100644 --- a/sesman/tools/sesrun.c +++ b/sesman/tools/sesrun.c @@ -49,31 +49,34 @@ main(int argc, char **argv) int session_code; struct stream *in_s; struct stream *out_s; + char *sesman_ini_file; char *username; char *password; long data; - if (0 != config_read(&g_cfg)) - { - g_printf("sesrun: error reading config. quitting.\n"); - return 1; - } if (argc == 1) { g_printf("xrdp session starter v0.1\n"); g_printf("\nusage:\n"); - g_printf("sesrun \n"); + g_printf("sesrun \n"); g_printf("session code 0 for Xvnc, 10 for X11RDP, 20 for Xorg\n"); } else if (argc == 8) { + sesman_ini_file = argv[1]; username = argv[2]; password = argv[3]; width = g_atoi(argv[4]); height = g_atoi(argv[5]); bpp = g_atoi(argv[6]); session_code = g_atoi(argv[7]); + + if (0 != config_read(sesman_ini_file, &g_cfg)) + { + g_printf("sesrun: error reading config. quitting.\n"); + return 1; + } make_stream(in_s); init_stream(in_s, 8192); make_stream(out_s); diff --git a/xrdp/lang.c b/xrdp/lang.c index ff242599..f219aa98 100644 --- a/xrdp/lang.c +++ b/xrdp/lang.c @@ -227,7 +227,7 @@ km_read_section(int fd, const char *section_name, struct xrdp_key_info *keymap) /*****************************************************************************/ int -get_keymaps(int keylayout, struct xrdp_keymap *keymap) +get_keymaps(const char* keymaps_path, int keylayout, struct xrdp_keymap *keymap) { int fd; int basic_key_layout = keylayout & 0x0000ffff; @@ -237,21 +237,21 @@ get_keymaps(int keylayout, struct xrdp_keymap *keymap) filename = (char *)g_malloc(256, 0); /* check if there is a keymap file e.g. km-e00100411.ini */ - g_snprintf(filename, 255, "%s/km-%08x.ini", XRDP_CFG_PATH, keylayout); + g_snprintf(filename, 255, "%s/km-%08x.ini", keymaps_path, keylayout); /* if the file does not exist, use only lower 16 bits instead */ if (!g_file_exist(filename)) { log_message(LOG_LEVEL_INFO, "Cannot find keymap file %s", filename); /* e.g. km-00000411.ini */ - g_snprintf(filename, 255, "%s/km-%08x.ini", XRDP_CFG_PATH, basic_key_layout); + g_snprintf(filename, 255, "%s/km-%08x.ini", keymaps_path, basic_key_layout); } /* finally, use 'en-us' */ if (!g_file_exist(filename)) { log_message(LOG_LEVEL_INFO, "Cannot find keymap file %s", filename); - g_snprintf(filename, 255, "%s/km-00000409.ini", XRDP_CFG_PATH); + g_snprintf(filename, 255, "%s/km-00000409.ini", keymaps_path); } if (g_file_exist(filename)) diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c index d2643e98..ba0f6052 100644 --- a/xrdp/xrdp.c +++ b/xrdp/xrdp.c @@ -74,6 +74,7 @@ print_help(void) g_writeln(" -h, --help show help"); g_writeln(" -n, --nodaemon don't fork into background"); g_writeln(" -k, --kill shut down xrdp"); + g_writeln(" -c, --config path to xrdp.ini (default '%s/xrdp.ini')", XRDP_CFG_PATH); g_writeln(" -p, --port tcp listen port"); g_writeln(" -f, --fork fork on new connection"); } @@ -263,70 +264,89 @@ xrdp_process_params(int argc, char **argv, struct xrdp_startup_params *startup_params) { int index; - char option[128]; - char value[128]; - index = 1; + // fill with defaults + startup_params->port[0] = 0; + startup_params->kill = 0; + startup_params->no_daemon = 0; + startup_params->help = 0; + startup_params->version = 0; + startup_params->fork = 0; + startup_params->send_buffer_bytes = 0; + startup_params->recv_buffer_bytes = 0; + g_sprintf(startup_params->xrdp_ini_file, "%s/xrdp.ini", XRDP_CFG_PATH); - while (index < argc) + for (index = 1; index < argc; index ++) { - g_strncpy(option, argv[index], 127); - - if (index + 1 < argc) - { - g_strncpy(value, argv[index + 1], 127); - } - else - { - value[0] = 0; - } - - if ((g_strncasecmp(option, "-help", 255)) == 0 || - (g_strncasecmp(option, "--help", 255)) == 0 || - (g_strncasecmp(option, "-h", 255)) == 0) + if ((g_strncasecmp(argv[index], "-help", 255)) == 0 || + (g_strncasecmp(argv[index], "--help", 255)) == 0 || + (g_strncasecmp(argv[index], "-h", 255)) == 0) { startup_params->help = 1; } - else if ((g_strncasecmp(option, "-kill", 255) == 0) || - (g_strncasecmp(option, "--kill", 255) == 0) || - (g_strncasecmp(option, "-k", 255) == 0)) + else if ((g_strncasecmp(argv[index], "-kill", 255) == 0) || + (g_strncasecmp(argv[index], "--kill", 255) == 0) || + (g_strncasecmp(argv[index], "-k", 255) == 0)) { startup_params->kill = 1; } - else if ((g_strncasecmp(option, "-nodaemon", 255) == 0) || - (g_strncasecmp(option, "--nodaemon", 255) == 0) || - (g_strncasecmp(option, "-n", 255) == 0) || - (g_strncasecmp(option, "-nd", 255) == 0) || - (g_strncasecmp(option, "--nd", 255) == 0) || - (g_strncasecmp(option, "-ns", 255) == 0) || - (g_strncasecmp(option, "--ns", 255) == 0)) + else if ((g_strncasecmp(argv[index], "-nodaemon", 255) == 0) || + (g_strncasecmp(argv[index], "--nodaemon", 255) == 0) || + (g_strncasecmp(argv[index], "-n", 255) == 0) || + (g_strncasecmp(argv[index], "-nd", 255) == 0) || + (g_strncasecmp(argv[index], "--nd", 255) == 0) || + (g_strncasecmp(argv[index], "-ns", 255) == 0) || + (g_strncasecmp(argv[index], "--ns", 255) == 0)) { startup_params->no_daemon = 1; } - else if ((g_strncasecmp(option, "-v", 255) == 0) || - (g_strncasecmp(option, "--version", 255) == 0)) + else if ((g_strncasecmp(argv[index], "-v", 255) == 0) || + (g_strncasecmp(argv[index], "--version", 255) == 0)) { startup_params->version = 1; } - else if ((g_strncasecmp(option, "-p", 255) == 0) || - (g_strncasecmp(option, "--port", 255) == 0)) + else if ((g_strncasecmp(argv[index], "-p", 255) == 0) || + (g_strncasecmp(argv[index], "--port", 255) == 0)) { index++; - g_strncpy(startup_params->port, value, 127); - if (g_strlen(startup_params->port) < 1) + if (index >= argc) { - g_writeln("error processing params, port [%s]", startup_params->port); + g_writeln("param requires after --port"); return 1; } - else + if (argv[index][0] == 0 || g_strlen(argv[index]) >= (int)sizeof(startup_params->port)-1) { - g_writeln("--port parameter found, ini override [%s]", - startup_params->port); + g_writeln("error processing params, port [%s]", argv[index]); + return 1; } + g_strncpy(startup_params->port, argv[index], sizeof(startup_params->port)-1); + g_writeln("--port parameter found, ini override [%s]", startup_params->port); } - else if ((g_strncasecmp(option, "-f", 255) == 0) || - (g_strncasecmp(option, "--fork", 255) == 0)) + else if ((g_strncasecmp(argv[index], "-c", 255) == 0) || + (g_strncasecmp(argv[index], "--config", 255) == 0)) + { + index++; + + if (index >= argc) + { + g_writeln("param requires after --config"); + return 1; + } + if (argv[index][0] == 0 || g_strlen(argv[index]) >= (int)sizeof(startup_params->xrdp_ini_file)-1) + { + g_writeln("error processing params, config [%s]", argv[index]); + return 1; + } + if (argv[index][0] != '/') { + g_writeln("invalid argument of --config: path must be absolute"); + return 1; + } + g_strncpy(startup_params->xrdp_ini_file, argv[index], (int)sizeof(startup_params->xrdp_ini_file)-1); + g_writeln("--config parameter found [%s]", startup_params->xrdp_ini_file); + } + else if ((g_strncasecmp(argv[index], "-f", 255) == 0) || + (g_strncasecmp(argv[index], "--fork", 255) == 0)) { startup_params->fork = 1; g_writeln("--fork parameter found, ini override"); @@ -335,8 +355,6 @@ xrdp_process_params(int argc, char **argv, { return index; } - - index++; } return 0; @@ -344,12 +362,11 @@ xrdp_process_params(int argc, char **argv, /*****************************************************************************/ /* Basic sanity checks before any forking */ -int +static int xrdp_sanity_check(void) { int intval = 1; int host_be; - char key_file[256]; /* check compiled endian with actual endian */ host_be = !((int)(*(unsigned char *)(&intval))); @@ -394,12 +411,6 @@ xrdp_sanity_check(void) return 1; } - g_snprintf(key_file, 255, "%s/rsakeys.ini", XRDP_CFG_PATH); - if (!g_file_exist(key_file)) - { - g_writeln("File %s is missing, create it using xrdp-keygen", key_file); - return 1; - } return 0; } @@ -410,7 +421,6 @@ main(int argc, char **argv) { int exit_status = 0; int test; - char cfg_file[256]; enum logReturns error; struct xrdp_startup_params *startup_params; int pid; @@ -428,8 +438,6 @@ main(int argc, char **argv) DEBUG(("Argument %i - %s", test, argv[test])); } - g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); - startup_params = (struct xrdp_startup_params *) g_malloc(sizeof(struct xrdp_startup_params), 1); @@ -508,7 +516,7 @@ main(int argc, char **argv) } /* starting logging subsystem */ - error = log_start(cfg_file, "xrdp"); + error = log_start(startup_params->xrdp_ini_file, "xrdp"); if (error != LOG_STARTUP_OK) { diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h index 5ed46a3a..39a51658 100644 --- a/xrdp/xrdp.h +++ b/xrdp/xrdp.h @@ -353,13 +353,13 @@ get_char_from_scan_code(int device_flags, int scan_code, int* keys, int caps_lock, int num_lock, int scroll_lock, struct xrdp_keymap* keymap); int -get_keymaps(int keylayout, struct xrdp_keymap* keymap); +get_keymaps(const char *keymaps_path, int keylayout, struct xrdp_keymap* keymap); /* xrdp_login_wnd.c */ int xrdp_login_wnd_create(struct xrdp_wm* self); int -load_xrdp_config(struct xrdp_config *config, int bpp); +load_xrdp_config(const char* xrdp_ini_file, struct xrdp_config *config, int bpp); /* xrdp_bitmap_compress.c */ int diff --git a/xrdp/xrdp.ini.in b/xrdp/xrdp.ini.in index bba2624e..2ea7615b 100644 --- a/xrdp/xrdp.ini.in +++ b/xrdp/xrdp.ini.in @@ -27,6 +27,13 @@ crypt_level=high ; openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365 certificate= key_file= +;directory with km-*.ini files; default is the directory of xrdp.ini +#keymaps_path= +;location of xrdp_keyboard_ini; default next to xrdp.ini +#xrdp_keyboard_ini= +;location of rsakeys.ini; default next to xrdp.ini +#rsakeys_ini= + ; set SSL protocols ; can be comma separated list of 'SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3' ssl_protocols=TLSv1.2, TLSv1.3 @@ -159,7 +166,7 @@ lib=libxup.@lib_extension@ username=ask password=ask ip=127.0.0.1 -port=-1 +sesmanport=3350 code=20 [Xvnc] @@ -168,7 +175,7 @@ lib=libvnc.@lib_extension@ username=ask password=ask ip=127.0.0.1 -port=-1 +sesmanport=3350 #xserverbpp=24 #delay_ms=2000 diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index 192b0786..c9c2f19c 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -162,15 +162,14 @@ xrdp_listen_get_port_address(char *port, int port_bytes, char *val; struct list *names; struct list *values; - char cfg_file[256]; /* default to port 3389 */ g_strncpy(port, "3389", port_bytes - 1); /* Default to all */ g_strncpy(address, "0.0.0.0", address_bytes - 1); /* see if port or address is in xrdp.ini file */ - g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); - fd = g_file_open(cfg_file); + + fd = g_file_open(startup_param->xrdp_ini_file); *mode = TRANS_MODE_TCP; *tcp_nodelay = 0 ; *tcp_keepalive = 0 ; diff --git a/xrdp/xrdp_login_wnd.c b/xrdp/xrdp_login_wnd.c index c09f8002..aba5b5ec 100644 --- a/xrdp/xrdp_login_wnd.c +++ b/xrdp/xrdp_login_wnd.c @@ -559,7 +559,6 @@ xrdp_wm_login_fill_in_combo(struct xrdp_wm *self, struct xrdp_bitmap *b) char *q; char *r; char name[256]; - char cfg_file[256]; struct xrdp_mod_data *mod_data; sections = list_create(); @@ -568,12 +567,11 @@ xrdp_wm_login_fill_in_combo(struct xrdp_wm *self, struct xrdp_bitmap *b) section_names->auto_free = 1; section_values = list_create(); section_values->auto_free = 1; - g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); - fd = g_file_open(cfg_file); /* xrdp.ini */ + fd = g_file_open(self->pro_layer->lis_layer->startup_params->xrdp_ini_file); /* xrdp.ini */ if (fd < 0) { - log_message(LOG_LEVEL_ERROR, "Could not read xrdp ini file %s", cfg_file); + log_message(LOG_LEVEL_ERROR, "Could not read xrdp ini file %s", self->pro_layer->lis_layer->startup_params->xrdp_ini_file); list_delete(sections); list_delete(section_names); list_delete(section_values); @@ -832,7 +830,7 @@ xrdp_login_wnd_create(struct xrdp_wm *self) * @return 0 on success, -1 on failure *****************************************************************************/ int -load_xrdp_config(struct xrdp_config *config, int bpp) +load_xrdp_config(const char *xrdp_ini_file, struct xrdp_config *config, int bpp) { struct xrdp_cfg_globals *globals; @@ -841,7 +839,6 @@ load_xrdp_config(struct xrdp_config *config, int bpp) char *n; char *v; - char buf[256]; int fd; int i; @@ -873,11 +870,10 @@ load_xrdp_config(struct xrdp_config *config, int bpp) globals->ls_btn_cancel_height = 30; /* open xrdp.ini file */ - g_snprintf(buf, 255, "%s/xrdp.ini", XRDP_CFG_PATH); - if ((fd = g_file_open(buf)) < 0) + if ((fd = g_file_open(xrdp_ini_file)) < 0) { log_message(LOG_LEVEL_ERROR,"load_config: Could not read " - "xrdp.ini file %s", buf); + "xrdp.ini file %s", xrdp_ini_file); return -1; } @@ -893,7 +889,7 @@ load_xrdp_config(struct xrdp_config *config, int bpp) list_delete(values); g_file_close(fd); log_message(LOG_LEVEL_ERROR,"load_config: Could not read globals " - "section from xrdp.ini file %s", buf); + "section from xrdp.ini file %s", xrdp_ini_file); return -1; } diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index 7d204b5b..378a3973 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -1586,64 +1586,6 @@ xrdp_mm_process_login_response(struct xrdp_mm *self, struct stream *s) return rv; } -/*****************************************************************************/ -static int -xrdp_mm_get_sesman_port(char *port, int port_bytes) -{ - int fd; - int error; - int index; - char *val; - char cfg_file[256]; - struct list *names; - struct list *values; - - g_memset(cfg_file, 0, sizeof(char) * 256); - /* default to port 3350 */ - g_strncpy(port, "3350", port_bytes - 1); - /* see if port is in sesman.ini file */ - g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH); - fd = g_file_open(cfg_file); - - if (fd >= 0) - { - names = list_create(); - names->auto_free = 1; - values = list_create(); - values->auto_free = 1; - - if (file_read_section(fd, "Globals", names, values) == 0) - { - for (index = 0; index < names->count; index++) - { - val = (char *)list_get_item(names, index); - - if (val != 0) - { - if (g_strcasecmp(val, "ListenPort") == 0) - { - val = (char *)list_get_item(values, index); - error = g_atoi(val); - - if ((error > 0) && (error < 65000)) - { - g_strncpy(port, val, port_bytes - 1); - } - - break; - } - } - } - } - - list_delete(names); - list_delete(values); - g_file_close(fd); - } - - return 0; -} - /*****************************************************************************/ /* returns error data coming from client that need to go to channel handler */ @@ -1751,7 +1693,7 @@ xrdp_mm_sesman_data_in(struct trans *trans) /*********************************************************************/ /* return 0 on success */ static int -access_control(char *username, char *password, char *srv) +access_control(char *username, char *password, char *srv, char *sesmanport) { int reply; int rec = 32+1; /* 32 is reserved for PAM failures this means connect failure */ @@ -1764,13 +1706,11 @@ access_control(char *username, char *password, char *srv) unsigned long size; int index; int socket = g_tcp_socket(); - char port[8]; if (socket != -1) { - xrdp_mm_get_sesman_port(port, sizeof(port)); /* we use a blocking socket here */ - reply = g_tcp_connect(socket, srv, port); + reply = g_tcp_connect(socket, srv, sesmanport); if (reply == 0) { @@ -2139,7 +2079,7 @@ xrdp_mm_connect(struct xrdp_mm *self) char *name; char *value; char ip[256]; - char port[8]; + char sesmanport[8]; char chansrvport[256]; #ifndef USE_NOPAM int use_pam_auth = 0; @@ -2155,7 +2095,7 @@ xrdp_mm_connect(struct xrdp_mm *self) /* make sure we start in correct state */ cleanup_states(self); g_memset(ip, 0, sizeof(ip)); - g_memset(port, 0, sizeof(port)); + g_memset(sesmanport, 0, sizeof(sesmanport)); g_memset(chansrvport, 0, sizeof(chansrvport)); rv = 0; /* success */ names = self->login_names; @@ -2171,12 +2111,10 @@ xrdp_mm_connect(struct xrdp_mm *self) { g_strncpy(ip, value, 255); } - else if (g_strcasecmp(name, "port") == 0) + else if (g_strcasecmp(name, "sesmanport") == 0) { - if (g_strcasecmp(value, "-1") == 0) - { - self->sesman_controlled = 1; - } + g_strncpy(sesmanport, value, 7); + self->sesman_controlled = 1; } #ifndef USE_NOPAM @@ -2232,7 +2170,7 @@ xrdp_mm_connect(struct xrdp_mm *self) } /* access_control return 0 on success */ - reply = access_control(pam_auth_username, pam_auth_password, pam_auth_sessionIP); + reply = access_control(pam_auth_username, pam_auth_password, pam_auth_sessionIP, sesmanport); xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, "Reply from access control: %s", @@ -2258,9 +2196,8 @@ xrdp_mm_connect(struct xrdp_mm *self) trans_delete(self->sesman_trans); self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); self->sesman_trans->is_term = g_is_term; - xrdp_mm_get_sesman_port(port, sizeof(port)); xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG, - "connecting to sesman ip %s port %s", ip, port); + "connecting to sesman ip %s port %s", ip, sesmanport); /* xrdp_mm_sesman_data_in is the callback that is called when data arrives */ self->sesman_trans->trans_data_in = xrdp_mm_sesman_data_in; self->sesman_trans->header_size = 8; @@ -2269,7 +2206,7 @@ xrdp_mm_connect(struct xrdp_mm *self) /* try to connect up to 4 times */ for (index = 0; index < 4; index++) { - if (trans_connect(self->sesman_trans, ip, port, 3000) == 0) + if (trans_connect(self->sesman_trans, ip, sesmanport, 3000) == 0) { self->sesman_trans_up = 1; ok = 1; @@ -2292,7 +2229,7 @@ xrdp_mm_connect(struct xrdp_mm *self) { xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR, "Error connecting to sesman: %s port: %s", - ip, port); + ip, sesmanport); trans_delete(self->sesman_trans); self->sesman_trans = 0; self->sesman_trans_up = 0; diff --git a/xrdp/xrdp_process.c b/xrdp/xrdp_process.c index 2b6c9a62..9bc83883 100644 --- a/xrdp/xrdp_process.c +++ b/xrdp/xrdp_process.c @@ -235,7 +235,7 @@ xrdp_process_main_loop(struct xrdp_process *self) self->server_trans->trans_data_in = xrdp_process_data_in; self->server_trans->callback_data = self; init_stream(self->server_trans->in_s, 8192 * 4); - self->session = libxrdp_init((tbus)self, self->server_trans); + self->session = libxrdp_init(self->lis_layer->startup_params->xrdp_ini_file, (tbus)self, self->server_trans); self->server_trans->si = &(self->session->si); self->server_trans->my_source = XRDP_SOURCE_CLIENT; /* this callback function is in xrdp_wm.c */ diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h index 7e416125..a34150c5 100644 --- a/xrdp/xrdp_types.h +++ b/xrdp/xrdp_types.h @@ -533,6 +533,7 @@ struct xrdp_startup_params int fork; int send_buffer_bytes; int recv_buffer_bytes; + char xrdp_ini_file[256]; }; /* diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index fd7b13b8..0ac718d8 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -72,7 +72,7 @@ xrdp_wm_create(struct xrdp_process *owner, self->mm = xrdp_mm_create(self); self->default_font = xrdp_font_create(self); /* this will use built in keymap or load from file */ - get_keymaps(self->session->client_info->keylayout, &(self->keymap)); + get_keymaps(client_info->keymaps_path, self->session->client_info->keylayout, &(self->keymap)); xrdp_wm_set_login_mode(self, 0); self->target_surface = self->screen; self->current_surface_index = 0xffff; /* screen */ @@ -395,7 +395,6 @@ xrdp_wm_load_static_colors_plus(struct xrdp_wm *self, char *autorun_name) char *val; struct list *names; struct list *values; - char cfg_file[256]; if (autorun_name != 0) { @@ -414,8 +413,7 @@ xrdp_wm_load_static_colors_plus(struct xrdp_wm *self, char *autorun_name) self->background = HCOLOR(self->screen->bpp, 0x000000); /* now load them from the globals in xrdp.ini if defined */ - g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); - fd = g_file_open(cfg_file); + fd = g_file_open(self->pro_layer->lis_layer->startup_params->xrdp_ini_file); if (fd >= 0) { @@ -506,7 +504,7 @@ xrdp_wm_load_static_colors_plus(struct xrdp_wm *self, char *autorun_name) } else { - log_message(LOG_LEVEL_ERROR,"xrdp_wm_load_static_colors: Could not read xrdp.ini file %s", cfg_file); + log_message(LOG_LEVEL_ERROR,"xrdp_wm_load_static_colors: Could not read xrdp.ini file %s", self->pro_layer->lis_layer->startup_params->xrdp_ini_file); } if (self->screen->bpp == 8) @@ -568,20 +566,18 @@ xrdp_wm_init(struct xrdp_wm *self) char param[256]; char default_section_name[256]; char section_name[256]; - char cfg_file[256]; char autorun_name[256]; g_writeln("in xrdp_wm_init: "); - load_xrdp_config(self->xrdp_config, self->screen->bpp); + load_xrdp_config(self->pro_layer->lis_layer->startup_params->xrdp_ini_file, self->xrdp_config, self->screen->bpp); /* global channels allow */ names = list_create(); names->auto_free = 1; values = list_create(); values->auto_free = 1; - g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); - if (file_by_name_read_section(cfg_file, "Channels", names, values) == 0) + if (file_by_name_read_section(self->pro_layer->lis_layer->startup_params->xrdp_ini_file, "Channels", names, values) == 0) { int error; int ii; @@ -648,8 +644,7 @@ xrdp_wm_init(struct xrdp_wm *self) * NOTE: this should eventually be accessed from self->xrdp_config */ - g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); - fd = g_file_open(cfg_file); /* xrdp.ini */ + fd = g_file_open(self->pro_layer->lis_layer->startup_params->xrdp_ini_file); /* xrdp.ini */ if (fd != -1) { names = list_create(); @@ -789,7 +784,7 @@ xrdp_wm_init(struct xrdp_wm *self) } else { - log_message(LOG_LEVEL_ERROR,"xrdp_wm_init: Could not read xrdp.ini file %s", cfg_file); + log_message(LOG_LEVEL_ERROR,"xrdp_wm_init: Could not read xrdp.ini file %s", self->pro_layer->lis_layer->startup_params->xrdp_ini_file); } } else diff --git a/xup/xup.c b/xup/xup.c index 91eb0563..3245548c 100644 --- a/xup/xup.c +++ b/xup/xup.c @@ -1363,7 +1363,7 @@ lib_send_client_info(struct mod *mod) g_writeln("lib_send_client_info:"); make_stream(s); - init_stream(s, 8192); + init_stream(s, (int)sizeof(mod->client_info) < 8192 ? 8192 : (int)sizeof(mod->client_info)); s_push_layer(s, iso_hdr, 4); out_uint16_le(s, 104); g_memcpy(s->p, &(mod->client_info), sizeof(mod->client_info));