diff --git a/sesman/Makefile b/sesman/Makefile index e55d6029..773a2a47 100644 --- a/sesman/Makefile +++ b/sesman/Makefile @@ -1,5 +1,9 @@ -SESMANOBJ = sesman.o ../common/os_calls.o ../common/d3des.o +SESMANOBJ = sesman.o config.o \ + ../common/os_calls.o \ + ../common/d3des.o \ + ../common/list.o \ + ../common/file.o CFLAGS = -Wall -O2 -I../common LDFLAGS = -L /usr/gnu/lib diff --git a/sesman/config.c b/sesman/config.c new file mode 100644 index 00000000..20cd1638 --- /dev/null +++ b/sesman/config.c @@ -0,0 +1,91 @@ +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + xrdp: A Remote Desktop Protocol server. + Copyright (C) Jay Sorg 2005 + + session manager - read config file +*/ + +#include "os_calls.h" +#include "list.h" +#include "file.h" +#include "arch.h" +#include "config.h" + +/******************************************************************************/ +/* returns error */ +int DEFAULT_CC +config_read(struct sesman_config* cfg) +{ + int i; + int fd; + struct list* sec; + struct list* param_n; + struct list* param_v; + char* buf; + + fd = g_file_open(SESMAN_CFG_FILE); + if (-1 == fd) + { + g_printf("sesman: error reading config: %s\n\r", SESMAN_CFG_FILE); + return 1; + } + g_memset(cfg, 0, sizeof(struct sesman_config)); + sec = list_create(); + sec->auto_free = 1; + file_read_sections(fd, sec); + param_n = list_create(); + param_n->auto_free = 1; + param_v = list_create(); + param_v->auto_free = 1; + file_read_section(fd, SESMAN_CFG_GLOBALS, param_n, param_v); + for (i = 0; i < param_n->count; i++) + { + buf = (char*)list_get_item(param_n, i); + if (0 == g_strncasecmp(buf, SESMAN_CFG_DEFWM, 20)) + { + g_strncpy(cfg->default_wm, (char*)list_get_item(param_v, i), 31); + } + else if (0 == g_strncasecmp(buf, SESMAN_CFG_USERWM, 20)) + { + g_strncpy(cfg->user_wm, (char*)list_get_item(param_v, i), 31); + } + else if (0 == g_strncasecmp(buf, SESMAN_CFG_ENABLE_USERWM, 20)) + { + buf = (char*)list_get_item(param_v, i); + if (0 == g_strncasecmp(buf, "1", 1) || + 0 == g_strncasecmp(buf, "true", 4) || + 0 == g_strncasecmp(buf, "yes", 3)) + { + cfg->enable_user_wm = 1; + } + } + else if (0 == g_strncasecmp(buf, SESMAN_CFG_PORT, 20)) + { + g_strncpy(cfg->listen_port, (char*)list_get_item(param_v, i), 15); + } + } + g_printf("sesman config:\n\r"); + g_printf("\tListenPort: %s\n\r", cfg->listen_port); + g_printf("\tEnableUserWindowManager: %i\n\r", cfg->enable_user_wm); + g_printf("\tUserWindowManager: %s\n\r", cfg->user_wm); + g_printf("\tDefaultWindowManager: %s\n\r", cfg->default_wm); + /* cleanup */ + list_delete(sec); + list_delete(param_v); + list_delete(param_n); + return 0; +} diff --git a/sesman/config.h b/sesman/config.h new file mode 100644 index 00000000..544707c3 --- /dev/null +++ b/sesman/config.h @@ -0,0 +1,43 @@ +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + xrdp: A Remote Desktop Protocol server. + Copyright (C) Jay Sorg 2005 + + session manager - read config file +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +#define SESMAN_CFG_FILE "./sesman.ini" +#define SESMAN_CFG_GLOBALS "Globals" +#define SESMAN_CFG_DEFWM "DefaultWindowManager" +#define SESMAN_CFG_PORT "ListenPort" +#define SESMAN_CFG_ENABLE_USERWM "EnableUserWindowManager" +#define SESMAN_CFG_USERWM "UserWindowManager" + +struct sesman_config +{ + char listen_port[16]; + int enable_user_wm; + char default_wm[32]; + char user_wm[32]; +}; + +int DEFAULT_CC +config_read(struct sesman_config* cfg); + +#endif diff --git a/sesman/sesman.c b/sesman/sesman.c index f1866cda..b7e3f92e 100644 --- a/sesman/sesman.c +++ b/sesman/sesman.c @@ -22,37 +22,17 @@ */ #include "d3des.h" - #include "arch.h" #include "parse.h" #include "os_calls.h" - -long DEFAULT_CC -auth_userpass(char* user, char* pass); -int DEFAULT_CC -auth_start_session(long in_val, int in_display); -int DEFAULT_CC -auth_end(long in_val); -int DEFAULT_CC -auth_set_env(long in_val); +#include "sesman.h" +#include "config.h" static int g_sck; static int g_pid; - -struct session_item -{ - char name[256]; - int pid; /* pid of sesman waiting for wm to end */ - int display; - int width; - int height; - int bpp; - long data; -}; - -static unsigned char s_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; - -static struct session_item session_items[100]; +static unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; +static struct session_item g_session_items[100]; /* sesman.h */ +static struct sesman_config g_cfg; /* config.h */ /*****************************************************************************/ static int DEFAULT_CC @@ -128,12 +108,12 @@ find_session_item(char* name, int width, int height, int bpp) for (i = 0; i < 100; i++) { - if (g_strcmp(name, session_items[i].name) == 0 && - session_items[i].width == width && - session_items[i].height == height && - session_items[i].bpp == bpp) + if (g_strncmp(name, g_session_items[i].name, 255) == 0 && + g_session_items[i].width == width && + g_session_items[i].height == height && + g_session_items[i].bpp == bpp) { - return session_items + i; + return g_session_items + i; } } return 0; @@ -166,9 +146,9 @@ cterm(int s) { for (i = 0; i < 100; i++) { - if (session_items[i].pid == pid) + if (g_session_items[i].pid == pid) { - g_memset(session_items + i, 0, sizeof(struct session_item)); + g_memset(g_session_items + i, 0, sizeof(struct session_item)); } } } @@ -183,7 +163,7 @@ check_password_file(char* filename, char* password) g_memset(encryptedPasswd, 0, 16); g_strncpy(encryptedPasswd, password, 8); - rfbDesKey(s_fixedkey, 0); + rfbDesKey(g_fixedkey, 0); rfbDes(encryptedPasswd, encryptedPasswd); fd = g_file_open(filename); if (fd == 0) @@ -292,11 +272,24 @@ start_session(int width, int height, int bpp, char* username, char* password, if (x_server_running(display)) { auth_set_env(data); - g_sprintf(text, "%s/startwm.sh", cur_dir); - g_execlp3(text, "startwm.sh", 0); + /* try to execute user window manager if enabled */ + if (g_cfg.enable_user_wm) + { + g_sprintf(text,"%s/%s", g_getenv("HOME"), g_cfg.user_wm); + if (g_file_exist(text)) + { + g_execlp3(text, g_cfg.user_wm, 0); + } + } + /* if we're here something happened to g_execlp3 + so we try running the default window manager */ + g_sprintf(text, "%s/%s", cur_dir, g_cfg.default_wm); + g_execlp3(text, g_cfg.default_wm, 0); + /* still a problem starting window manager just start xterm */ + g_execlp3("xterm", "xterm", 0); /* should not get here */ } - g_printf("error\n"); + g_printf("error starting window manager\n"); g_exit(0); } else /* parent */ @@ -328,13 +321,13 @@ start_session(int width, int height, int bpp, char* username, char* password, } else /* parent */ { - session_items[display].pid = pid; - g_strcpy(session_items[display].name, username); - session_items[display].display = display; - session_items[display].width = width; - session_items[display].height = height; - session_items[display].bpp = bpp; - session_items[display].data = data; + g_session_items[display].pid = pid; + g_strcpy(g_session_items[display].name, username); + g_session_items[display].display = display; + g_session_items[display].width = width; + g_session_items[display].height = height; + g_session_items[display].bpp = bpp; + g_session_items[display].data = data; g_sleep(5000); } return display; @@ -353,6 +346,26 @@ sesman_shutdown(int sig) g_tcp_close(g_sck); } +/******************************************************************************/ +void DEFAULT_CC +sesman_reload_cfg(int sig) +{ + struct sesman_config cfg; + + if (g_getpid() != g_pid) + { + return; + } + g_printf("sesman: received SIGHUP\n\r"); + if (config_read(&cfg) != 0) + { + g_printf("sesman: error reading config. keeping old cfg.\n\r"); + return; + } + g_cfg = cfg; + g_printf("sesman: configuration reloaded\n\r"); +} + /******************************************************************************/ int DEFAULT_CC main(int argc, char** argv) @@ -377,8 +390,14 @@ main(int argc, char** argv) struct session_item* s_item; long data; - g_memset(&session_items, 0, sizeof(session_items)); + if (0 != config_read(&g_cfg)) + { + g_printf("sesman: error reading config. quitting.\n\r"); + return 1; + } + g_memset(&g_session_items, 0, sizeof(g_session_items)); g_pid = g_getpid(); + g_signal(1, sesman_reload_cfg); /* SIGHUP */ g_signal(2, sesman_shutdown); /* SIGINT */ g_signal(9, sesman_shutdown); /* SIGKILL */ g_signal(15, sesman_shutdown); /* SIGTERM */ @@ -391,7 +410,7 @@ main(int argc, char** argv) g_printf("sesman server username password width height bpp - \ start session\n"); } - else if (argc == 2 && g_strcmp(argv[1], "wait") == 0) + else if (argc == 2 && g_strncmp(argv[1], "wait", 255) == 0) { make_stream(in_s); init_stream(in_s, 8192); @@ -400,7 +419,7 @@ start session\n"); g_printf("listening\n"); g_sck = g_tcp_socket(); g_tcp_set_non_blocking(g_sck); - error = g_tcp_bind(g_sck, "3350"); + error = g_tcp_bind(g_sck, g_cfg.listen_port); if (error == 0) { error = g_tcp_listen(g_sck); diff --git a/sesman/sesman.h b/sesman/sesman.h new file mode 100644 index 00000000..8378f68a --- /dev/null +++ b/sesman/sesman.h @@ -0,0 +1,45 @@ +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + xrdp: A Remote Desktop Protocol server. + Copyright (C) Jay Sorg 2005 + + session manager - main header +*/ + +#ifndef SESMAN_H +#define SESMAN_H + +long DEFAULT_CC +auth_userpass(char* user, char* pass); +int DEFAULT_CC +auth_start_session(long in_val, int in_display); +int DEFAULT_CC +auth_end(long in_val); +int DEFAULT_CC +auth_set_env(long in_val); + +struct session_item +{ + char name[256]; + int pid; /* pid of sesman waiting for wm to end */ + int display; + int width; + int height; + int bpp; + long data; +}; + +#endif diff --git a/sesman/sesman.ini b/sesman/sesman.ini index d01e8d2f..079f99d5 100644 --- a/sesman/sesman.ini +++ b/sesman/sesman.ini @@ -1,5 +1,5 @@ - -[globals] -auth=pam -xserver=Xvnc :%d -geometry %dx%d -depth %d -bs -wm=startkde +[Globals] +ListenPort=3350 +EnableUserWindowManager=1 +UserWindowManager=startwm.sh +DefaultWindowManager=startwm.sh