diff --git a/sesman/access.c b/sesman/access.c index 96750c3f..bbb14fcc 100644 --- a/sesman/access.c +++ b/sesman/access.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 authenticate user @@ -22,63 +22,54 @@ #include "sesman.h" -#define _XOPEN_SOURCE -#include -#include -#include - extern struct config_sesman g_cfg; /******************************************************************************/ +/* returns non zero if allowed */ int DEFAULT_CC access_login_allowed(char* user) { - int i; - struct group* groups; - struct passwd* pwd; + int gid; + int ok; - if ((0==g_strncmp(user, "root",5)) && (0==g_cfg.sec.allow_root)) + if ((0 == g_strncmp(user, "root", 5)) && (0 == g_cfg.sec.allow_root)) { - log_message(LOG_LEVEL_WARNING, "ROOT login attempted, but root login is disabled"); + log_message(LOG_LEVEL_WARNING, + "ROOT login attempted, but root login is disabled"); return 0; } - - if (0==g_cfg.sec.ts_users_enable) + + if (0 == g_cfg.sec.ts_users_enable) { - LOG_DBG("Terminal Server Users group is disabled, allowing authentication",1); + LOG_DBG("Terminal Server Users group is disabled, allowing authentication", + 1); return 1; } - - groups = getgrgid(g_cfg.sec.ts_users); - if (0==groups) - { - log_message(LOG_LEVEL_ERROR,"Cannot read group info! - login denied"); - return 0; - } - - pwd = getpwnam(user); - if (0==pwd) + if (0 != g_getuser_info(user, &gid, 0, 0, 0, 0)) { log_message(LOG_LEVEL_ERROR, "Cannot read user info! - login denied"); return 0; } - - if (g_cfg.sec.ts_users==pwd->pw_gid) + + if (g_cfg.sec.ts_users == gid) { - LOG_DBG("ts_users is user's primary group",1); + LOG_DBG("ts_users is user's primary group", 1); return 1; } - - i=0; - while (0!=groups->gr_mem[i]) + + if (0 != g_check_user_in_group(user, g_cfg.sec.ts_users, &ok)) + { + log_message(LOG_LEVEL_ERROR, "Cannot read group info! - login denied"); + return 0; + } + + if (ok) { - LOG_DBG("user: %s", groups->gr_mem[i]); - if (0==g_strcmp(groups->gr_mem[i], user)) return 1; - i++; + return 1; } - + log_message(LOG_LEVEL_INFO, "login denied for user %s", user); - + return 0; } diff --git a/sesman/access.h b/sesman/access.h index 342431d5..86fac552 100644 --- a/sesman/access.h +++ b/sesman/access.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager - access control header */ diff --git a/sesman/auth.h b/sesman/auth.h index a2c35765..fe1a258b 100644 --- a/sesman/auth.h +++ b/sesman/auth.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager - main header */ diff --git a/sesman/config.c b/sesman/config.c index 5dd0d748..a2f0922e 100644 --- a/sesman/config.c +++ b/sesman/config.c @@ -14,14 +14,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager - read config file */ -#include "sys/types.h" -#include "grp.h" - #include "arch.h" #include "list.h" #include "file.h" @@ -31,9 +28,9 @@ static int APP_CC text2bool(char* s) { - if (0 == g_strncasecmp(s, "1", 1) || - 0 == g_strncasecmp(s, "true", 4) || - 0 == g_strncasecmp(s, "yes", 3)) + if (0 == g_strcasecmp(s, "1") || + 0 == g_strcasecmp(s, "true") || + 0 == g_strcasecmp(s, "yes")) { return 1; } @@ -94,49 +91,49 @@ config_read_globals(int file, struct config_sesman* cf, struct list* param_n, list_clear(param_v); list_clear(param_n); - + /* resetting the struct */ - cf->listen_port[0]='\0'; - cf->enable_user_wm=0; - cf->user_wm[0]='\0'; - cf->default_wm[0]='\0'; + cf->listen_port[0] = '\0'; + cf->enable_user_wm = 0; + cf->user_wm[0] = '\0'; + cf->default_wm[0] = '\0'; file_read_section(file, 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)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_DEFWM)) { g_strncpy(cf->default_wm, (char*)list_get_item(param_v, i), 31); } - else if (0 == g_strncasecmp(buf, SESMAN_CFG_USERWM, 20)) + else if (0 == g_strcasecmp(buf, SESMAN_CFG_USERWM)) { g_strncpy(cf->user_wm, (char*)list_get_item(param_v, i), 31); } - else if (0 == g_strncasecmp(buf, SESMAN_CFG_ENABLE_USERWM, 20)) + else if (0 == g_strcasecmp(buf, SESMAN_CFG_ENABLE_USERWM)) { - cf->enable_user_wm = text2bool((char*) list_get_item(param_v, i)); + cf->enable_user_wm = text2bool((char*)list_get_item(param_v, i)); } - else if (0 == g_strncasecmp(buf, SESMAN_CFG_PORT, 20)) + else if (0 == g_strcasecmp(buf, SESMAN_CFG_PORT)) { g_strncpy(cf->listen_port, (char*)list_get_item(param_v, i), 15); } } /* checking for missing required parameters */ - if ('\0'==cf->listen_port[0]) + if ('\0' == cf->listen_port[0]) { g_strncpy(cf->listen_port, "3350", 5); } - if ('\0'==cf->user_wm[0]) + if ('\0' == cf->user_wm[0]) { - cf->enable_user_wm=0; + cf->enable_user_wm = 0; } - if ('\0'==cf->default_wm[0]) + if ('\0' == cf->default_wm[0]) { g_strncpy(cf->default_wm, "startwm.sh", 11); } - + /* showing read config */ g_printf("sesman config:\r\n"); g_printf("\tListenPort: %s\r\n", cf->listen_port); @@ -170,29 +167,29 @@ config_read_logging(int file, struct log_config* lc, struct list* param_n, for (i = 0; i < param_n->count; i++) { buf = (char*)list_get_item(param_n, i); - if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_FILE, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_FILE)) { lc->log_file = g_strdup((char*)list_get_item(param_v, i)); } - if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_LEVEL, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_LEVEL)) { lc->log_level = log_text2level((char*)list_get_item(param_v, i)); } - if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_ENABLE_SYSLOG, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_ENABLE_SYSLOG)) { lc->enable_syslog = text2bool((char*)list_get_item(param_v, i)); } - if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_SYSLOG_LEVEL, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_SYSLOG_LEVEL)) { lc->syslog_level = log_text2level((char*)list_get_item(param_v, i)); } } - if (0==lc->log_file) + if (0 == lc->log_file) { lc->log_file=g_strdup("./sesman.log"); } - + g_printf("logging configuration:\r\n"); g_printf("\tLogFile: %s\r\n",lc->log_file); g_printf("\tLogLevel: %i\r\n", lc->log_level); @@ -204,45 +201,44 @@ config_read_logging(int file, struct log_config* lc, struct list* param_n, /******************************************************************************/ int DEFAULT_CC -config_read_security(int file, struct config_security* sc, struct list* param_n, - struct list* param_v) +config_read_security(int file, struct config_security* sc, + struct list* param_n, + struct list* param_v) { int i; + int gid; char* buf; - struct group* g; list_clear(param_v); list_clear(param_n); /* setting defaults */ - sc->allow_root=0; - sc->ts_users_enable=0; - sc->ts_admins_enable=0; + sc->allow_root = 0; + sc->ts_users_enable = 0; + sc->ts_admins_enable = 0; file_read_section(file, SESMAN_CFG_SECURITY, 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_SEC_ALLOW_ROOT, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ALLOW_ROOT)) { sc->allow_root = text2bool((char*)list_get_item(param_v, i)); } - if (0 == g_strncasecmp(buf, SESMAN_CFG_SEC_USR_GROUP, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_USR_GROUP)) { - g=getgrnam((char*)list_get_item(param_v, i)); - if (0!=g) + if (g_getgroup_info((char*)list_get_item(param_v, i), &gid) == 0) { - sc->ts_users_enable=1; - sc->ts_users=g->gr_gid; + sc->ts_users_enable = 1; + sc->ts_users = gid; } } - if (0 == g_strncasecmp(buf, SESMAN_CFG_SEC_ADM_GROUP, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ADM_GROUP)) { - g=getgrnam((char*)list_get_item(param_v, i)); - if (0!=g) + if (g_getgroup_info((char*)list_get_item(param_v, i), &gid) == 0) { - sc->ts_admins_enable=1; - sc->ts_admins=g->gr_gid; + sc->ts_admins_enable = 1; + sc->ts_admins = gid; } } } @@ -291,19 +287,19 @@ config_read_sessions(int file, struct config_sessions* se, struct list* param_n, for (i = 0; i < param_n->count; i++) { buf = (char*)list_get_item(param_n, i); - if (0 == g_strncasecmp(buf, SESMAN_CFG_SESS_MAX, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_MAX)) { se->max_sessions = g_atoi((char*)list_get_item(param_v, i)); } - if (0 == g_strncasecmp(buf, SESMAN_CFG_SESS_KILL_DISC, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_KILL_DISC)) { se->kill_disconnected = text2bool((char*)list_get_item(param_v, i)); } - if (0 == g_strncasecmp(buf, SESMAN_CFG_SESS_IDLE_LIMIT, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_IDLE_LIMIT)) { se->max_idle_time=g_atoi((char*)list_get_item(param_v, i)); } - if (0 == g_strncasecmp(buf, SESMAN_CFG_SESS_DISC_LIMIT, 20)) + if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_DISC_LIMIT)) { se->max_disc_time=g_atoi((char*)list_get_item(param_v, i)); } diff --git a/sesman/config.h b/sesman/config.h index 6f66d579..efe8bdb4 100644 --- a/sesman/config.h +++ b/sesman/config.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager - read config file */ @@ -22,7 +22,6 @@ #ifndef CONFIG_H #define CONFIG_H -#include "sys/types.h" #include "arch.h" #include "list.h" #include "log.h" @@ -31,7 +30,7 @@ * * @def SESMAN_CFG_FILE * @brief Configuration file path - * + * */ #ifndef SESMAN_CFG_FILE #define SESMAN_CFG_FILE "./sesman.ini" @@ -52,7 +51,7 @@ #define SESMAN_CFG_SECURITY "Security" #define SESMAN_CFG_SEC_ALLOW_ROOT "AllowRootLogin" -#define SESMAN_CFG_SEC_USR_GROUP "TerminalServerUsers" +#define SESMAN_CFG_SEC_USR_GROUP "TerminalServerUsers" #define SESMAN_CFG_SEC_ADM_GROUP "TerminalServerAdmins" #define SESMAN_CFG_SESSIONS "Sessions" @@ -71,7 +70,7 @@ struct config_security { /** * @var allow_root - * @brief + * @brief */ int allow_root; /** @@ -79,13 +78,13 @@ struct config_security * @brief Terminal Server Users group */ int ts_users_enable; - gid_t ts_users; + int ts_users; /** * @var ts_admins * @brief Terminal Server Adminnistrators group */ int ts_admins_enable; - gid_t ts_admins; + int ts_admins; }; /** @@ -152,7 +151,7 @@ struct config_sesman char user_wm[32]; /** * @var log - * @brief Log configuration \t struct + * @brief Log configuration \t struct */ struct log_config log; /** @@ -174,7 +173,7 @@ struct config_sesman * @param cfg pointer to configuration object to be replaced * * @return 0 on success, 1 on failure - * + * */ int DEFAULT_CC config_read(struct config_sesman* cfg); @@ -186,10 +185,11 @@ config_read(struct config_sesman* cfg); * @param cfg pointer to configuration object to be replaced * * @return 0 on success, 1 on failure - * + * */ int DEFAULT_CC -config_read_globals(int file, struct config_sesman* cf, struct list* param_n, struct list* param_v); +config_read_globals(int file, struct config_sesman* cf, + struct list* param_n, struct list* param_v); /** * @@ -198,10 +198,11 @@ config_read_globals(int file, struct config_sesman* cf, struct list* param_n, st * @param cfg pointer to configuration object to be replaced * * @return 0 on success, 1 on failure - * + * */ int DEFAULT_CC -config_read_logging(int file, struct log_config* lc, struct list* param_n, struct list* param_v); +config_read_logging(int file, struct log_config* lc, struct list* param_n, + struct list* param_v); /** * @@ -210,10 +211,11 @@ config_read_logging(int file, struct log_config* lc, struct list* param_n, struc * @param cfg pointer to configuration object to be replaced * * @return 0 on success, 1 on failure - * + * */ int DEFAULT_CC -config_read_security(int file, struct config_security* sc, struct list* param_n, struct list* param_v); +config_read_security(int file, struct config_security* sc, + struct list* param_n, struct list* param_v); /** * @@ -222,9 +224,10 @@ config_read_security(int file, struct config_security* sc, struct list* param_n, * @param cfg pointer to configuration object to be replaced * * @return 0 on success, 1 on failure - * + * */ int DEFAULT_CC -config_read_sessions(int file, struct config_sessions* ss, struct list* param_n, struct list* param_v); +config_read_sessions(int file, struct config_sessions* ss, + struct list* param_n, struct list* param_v); #endif diff --git a/sesman/env.c b/sesman/env.c index 453591a6..84562ee0 100644 --- a/sesman/env.c +++ b/sesman/env.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only diff --git a/sesman/env.h b/sesman/env.h index be8c0a4e..aa0d3d32 100644 --- a/sesman/env.h +++ b/sesman/env.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only diff --git a/sesman/sesman.c b/sesman/sesman.c index f2d51da0..9101e22c 100644 --- a/sesman/sesman.c +++ b/sesman/sesman.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only @@ -23,12 +23,6 @@ #include "sesman.h" -#include -#include -#include -#include -#include - int g_sck; int g_pid; unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; @@ -44,7 +38,7 @@ struct config_sesman g_cfg; /* config.h */ * trigger when a child process (a session) dies * * @param s received signal - * + * */ static void DEFAULT_CC cterm(int s) @@ -106,7 +100,7 @@ sesman_main_loop() init_stream(in_s, 8192); make_stream(out_s); init_stream(out_s, 8192); - + log_message(LOG_LEVEL_INFO, "listening..."); g_sck = g_tcp_socket(); g_tcp_set_non_blocking(g_sck); @@ -162,26 +156,27 @@ sesman_main_loop() else { g_printf("pre auth"); - if (1==access_login_allowed(user)) + if (1 == access_login_allowed(user)) { - log_message(LOG_LEVEL_INFO, "granted TS access to user %s", user); - if (0 == code) - { - log_message(LOG_LEVEL_INFO, "starting Xvnc session..."); + log_message(LOG_LEVEL_INFO, + "granted TS access to user %s", user); + if (0 == code) + { + log_message(LOG_LEVEL_INFO, "starting Xvnc session..."); display = session_start(width, height, bpp, user, pass, data, SESMAN_SESSION_TYPE_XVNC); } else - { - log_message(LOG_LEVEL_INFO, "starting Xrdp session..."); + { + log_message(LOG_LEVEL_INFO, "starting Xrdp session..."); display = session_start(width, height, bpp, user, pass, data, SESMAN_SESSION_TYPE_XRDP); } - } - else + } + else { - display=0; - } + display = 0; + } } if (display == 0) { @@ -231,23 +226,25 @@ main(int argc, char** argv) { int fd; int error; - int daemon=1; + int daemon = 1; int pid; char pid_s[8]; - - if (1==argc) + + if (1 == argc) { /* no options on command line. normal startup */ g_printf("starting sesman...\n"); - daemon=1; + daemon = 1; } - else if ( (2==argc) && ( (0 == g_strncasecmp(argv[1],"--nodaemon",11)) || (0 == g_strncasecmp(argv[1],"-n",11)) ) ) + else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) || + (0 == g_strcasecmp(argv[1], "-n")) ) ) { /* starts sesman not daemonized */ g_printf("starting sesman in foregroud...\n"); daemon=0; } - else if ( (2==argc) && ( (0 == g_strncasecmp(argv[1],"--help",7)) || (0 == g_strncasecmp(argv[1],"-h",2)) ) ) + else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--help")) || + (0 == g_strcasecmp(argv[1], "-h")))) { /* help screen */ g_printf("sesman - xrdp session manager\n\n"); @@ -259,31 +256,33 @@ main(int argc, char** argv) g_printf("if no command is specified, sesman is started in background"); g_exit(0); } - else if ( (2==argc) && ( (0 == g_strncasecmp(argv[1],"--kill",11)) || (0 == g_strncasecmp(argv[1],"-k",11)) ) ) + else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) || + (0 == g_strcasecmp(argv[1], "-k")))) { /* killing running sesman */ /* check if sesman is running */ if (!g_file_exist(SESMAN_PID_FILE)) { - g_printf("sesman is not running (pid file not found - %s)\n", SESMAN_PID_FILE); + g_printf("sesman is not running (pid file not found - %s)\n", + SESMAN_PID_FILE); g_exit(1); } - + fd = g_file_open(SESMAN_PID_FILE); if (-1 == fd) { - g_printf("error opening pid file: %s\n", strerror(errno)); + g_printf("error opening pid file: %s\n", g_get_strerror()); return 1; } - + error = g_file_read(fd, pid_s, 7); - sscanf(pid_s, "%i", &pid); - + pid = g_atoi(pid_s); + error = g_sigterm(pid); if (0 != error) { - g_printf("error killing sesman: %s\n", strerror(errno)); + g_printf("error killing sesman: %s\n", g_get_strerror()); } else { @@ -301,7 +300,6 @@ main(int argc, char** argv) g_exit(1); } - if (g_file_exist(SESMAN_PID_FILE)) { g_printf("sesman is already running.\n"); @@ -310,26 +308,29 @@ main(int argc, char** argv) g_printf("\n"); g_exit(1); } - + /* reading config */ if (0 != config_read(&g_cfg)) { - g_printf("error reading config: %s\nquitting.\n", strerror(errno)); + g_printf("error reading config: %s\nquitting.\n", g_get_strerror()); g_exit(1); } - + /* starting logging subsystem */ - error = log_start(g_cfg.log.program_name, g_cfg.log.log_file, g_cfg.log.log_level, - g_cfg.log.enable_syslog, g_cfg.log.syslog_level); - + error = log_start(g_cfg.log.program_name, g_cfg.log.log_file, + g_cfg.log.log_level, g_cfg.log.enable_syslog, + g_cfg.log.syslog_level); + if (error != LOG_STARTUP_OK) { switch (error) { case LOG_ERROR_MALLOC: g_printf("error on malloc. cannot start logging. quitting.\n"); + break; case LOG_ERROR_FILE_OPEN: g_printf("error opening log file. quitting.\n"); + break; } g_exit(1); } @@ -368,7 +369,8 @@ main(int argc, char** argv) fd = g_file_open(SESMAN_PID_FILE); if (-1 == fd) { - log_message(LOG_LEVEL_ERROR, "error opening pid file: %s", strerror(errno)); + log_message(LOG_LEVEL_ERROR, "error opening pid file: %s", + g_get_strerror()); log_end(); g_exit(1); } diff --git a/sesman/sesman.h b/sesman/sesman.h index 8dd95226..f44f22f4 100644 --- a/sesman/sesman.h +++ b/sesman/sesman.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager - main header */ diff --git a/sesman/sesrun.c b/sesman/sesrun.c index c630de08..c352ff93 100644 --- a/sesman/sesrun.c +++ b/sesman/sesrun.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only diff --git a/sesman/session.c b/sesman/session.c index 86ecf8af..5a856081 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -14,15 +14,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only */ -#include - #include "sesman.h" extern unsigned char g_fixedkey[8]; @@ -140,22 +138,25 @@ session_start(int width, int height, int bpp, char* username, char* password, /* check to limit concurrent sessions */ if (g_session_count >= g_cfg.sess.max_sessions) { - log_message(LOG_LEVEL_INFO, "max concurrent session limit exceeded. login for user %s denied", username); + log_message(LOG_LEVEL_INFO, "max concurrent session limit exceeded. login \ +for user %s denied", username); return 0; } #ifndef OLDSESSION - temp=malloc(sizeof(struct session_chain)); + temp = (struct session_chain*)g_malloc(sizeof(struct session_chain), 0); if (temp == 0) { - log_message(LOG_LEVEL_ERROR, "cannot create new chain element - user %s", username); + log_message(LOG_LEVEL_ERROR, "cannot create new chain element - user %s", + username); return 0; } - temp->item = malloc(sizeof(struct session_item)); + temp->item = (struct session_item*)g_malloc(sizeof(struct session_item), 0); if (temp->item == 0) { - free(temp); - log_message(LOG_LEVEL_ERROR, "cannot create new session item - user %s", username); + g_free(temp); + log_message(LOG_LEVEL_ERROR, "cannot create new session item - user %s", + username); return 0; } #endif @@ -215,7 +216,8 @@ session_start(int width, int height, int bpp, char* username, char* password, g_execlp3("xterm", "xterm", 0); /* should not get here */ } - log_message(LOG_LEVEL_ALWAYS,"error starting window manager %s - pid %d", username, g_getpid()); + log_message(LOG_LEVEL_ALWAYS,"error starting window manager %s - pid %d", + username, g_getpid()); g_exit(0); } else /* parent */ @@ -238,13 +240,15 @@ session_start(int width, int height, int bpp, char* username, char* password, g_execlp11("Xrdp", "Xrdp", screen, "-geometry", geometry, "-depth", depth, "-bs", 0, 0, 0); } - else + else { - log_message(LOG_LEVEL_ALWAYS, "bad session type - user %s - pid %d", username, g_getpid()); - g_exit(1); + log_message(LOG_LEVEL_ALWAYS, "bad session type - user %s - pid %d", + username, g_getpid()); + g_exit(1); } /* should not get here */ - log_message(LOG_LEVEL_ALWAYS,"error doing execve for user %s - pid %d",username,g_getpid()); + log_message(LOG_LEVEL_ALWAYS,"error doing execve for user %s - pid %d", + username, g_getpid()); g_exit(1); } else /* parent */ @@ -272,7 +276,7 @@ session_start(int width, int height, int bpp, char* username, char* password, g_session_items[display].connect_time=g_time1(); g_session_items[display].disconnect_time=(time_t) 0; g_session_items[display].idle_time=(time_t) 0; - + i/*if (type==0) { g_session_items[display].type=SESMAN_SESSION_TYPE_XVNC; @@ -281,22 +285,22 @@ session_start(int width, int height, int bpp, char* username, char* password, { g_session_items[display].type=SESMAN_SESSION_TYPE_XRDP; }*/ - g_session_items[display].type=type; - g_session_items[display].status=SESMAN_SESSION_STATUS_ACTIVE; - + g_session_items[display].type = type; + g_session_items[display].status = SESMAN_SESSION_STATUS_ACTIVE; + g_session_count++; #else - temp->item->pid=pid; - temp->item->display=display; - temp->item->width=width; - temp->item->height=height; - temp->item->bpp=bpp; - temp->item->data=data; + temp->item->pid = pid; + temp->item->display = display; + temp->item->width = width; + temp->item->height = height; + temp->item->bpp = bpp; + temp->item->data = data; g_strncpy(temp->item->name, username, 255); - temp->item->connect_time=g_time1(); - temp->item->disconnect_time=(time_t) 0; - temp->item->idle_time=(time_t) 0; + temp->item->connect_time = g_time1(); + temp->item->disconnect_time = 0; + temp->item->idle_time = 0; /* if (type==0) { @@ -306,10 +310,10 @@ session_start(int width, int height, int bpp, char* username, char* password, { temp->item->type=SESMAN_SESSION_TYPE_XRDP; }*/ - + temp->item->type=type; temp->item->status=SESMAN_SESSION_STATUS_ACTIVE; - + /*THREAD-FIX lock the chain*/ temp->next=g_sessions; g_sessions=temp; @@ -375,10 +379,12 @@ session_kill(int pid) { if (tmp->item == 0) { - log_message(LOG_LEVEL_ERROR, "session descriptor for pid %d is null!", pid); + log_message(LOG_LEVEL_ERROR, "session descriptor for pid %d is null!", + pid); if (prev == 0) { - /* prev does no exist, so it's the first element - so we set g_sessions */ + /* prev does no exist, so it's the first element - so we set + g_sessions */ g_sessions = tmp->next; } else @@ -391,29 +397,31 @@ session_kill(int pid) if (tmp->item->pid == pid) { - /* deleting the session */ - log_message(LOG_LEVEL_INFO, "session %d - user %s - terminated", tmp->item->pid, tmp->item->name); - free(tmp->item); + /* deleting the session */ + log_message(LOG_LEVEL_INFO, "session %d - user %s - terminated", + tmp->item->pid, tmp->item->name); + g_free(tmp->item); if (prev == 0) { - /* prev does no exist, so it's the first element - so we set g_sessions */ - g_sessions = tmp->next; + /* prev does no exist, so it's the first element - so we set + g_sessions */ + g_sessions = tmp->next; } else { prev->next = tmp->next; } - free(tmp); + g_free(tmp); g_session_count--; /*THREAD-FIX release chain lock */ return SESMAN_SESSION_KILL_OK; } - + /* go on */ prev = tmp; tmp=tmp->next; } - + /*THREAD-FIX release chain lock */ return SESMAN_SESSION_KILL_NOTFOUND; } @@ -423,18 +431,19 @@ struct session_item* DEFAULT_CC session_get_bypid(int pid) { struct session_chain* tmp; - + /*THREAD-FIX require chain lock */ - tmp=g_sessions; + tmp = g_sessions; while (tmp != 0) { if (tmp->item == 0) { - log_message(LOG_LEVEL_ERROR, "session descriptor for pid %d is null!", pid); + log_message(LOG_LEVEL_ERROR, "session descriptor for pid %d is null!", + pid); /*THREAD-FIX release chain lock */ return 0; } - + if (tmp->item->pid == pid) { /*THREAD-FIX release chain lock */ @@ -444,7 +453,7 @@ session_get_bypid(int pid) /* go on */ tmp=tmp->next; } - + /*THREAD-FIX release chain lock */ return 0; } diff --git a/sesman/session.h b/sesman/session.h index a38300c8..86e00a39 100644 --- a/sesman/session.h +++ b/sesman/session.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only @@ -51,11 +51,11 @@ struct session_item /* status info */ unsigned char status; unsigned char type; - + /* time data */ - time_t connect_time; - time_t disconnect_time; - time_t idle_time; + int connect_time; + int disconnect_time; + int idle_time; }; struct session_chain diff --git a/sesman/sig.c b/sesman/sig.c index 140a48f9..d6a507b3 100644 --- a/sesman/sig.c +++ b/sesman/sig.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only @@ -38,14 +38,14 @@ extern struct config_sesman g_cfg; void DEFAULT_CC sig_sesman_shutdown(int sig) { - log_message(LOG_LEVEL_INFO, "shutting down sesman %d",1); - + log_message(LOG_LEVEL_INFO, "shutting down sesman %d", 1); + if (g_getpid() != g_pid) { LOG_DBG("g_getpid() [%d] differs from g_pid [%d]", (g_getpid()), g_pid); return; } - + LOG_DBG(" - getting signal %d pid %d", sig, g_getpid()); g_tcp_close(g_sck); @@ -58,7 +58,7 @@ void DEFAULT_CC sig_sesman_reload_cfg(int sig) { struct config_sesman cfg; - + log_message(LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1); if (g_getpid() != g_pid) diff --git a/sesman/sig.h b/sesman/sig.h index 07e2e6dd..bff92988 100644 --- a/sesman/sig.h +++ b/sesman/sig.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only diff --git a/sesman/tcp.c b/sesman/tcp.c index 54bbacea..d5164cb1 100644 --- a/sesman/tcp.c +++ b/sesman/tcp.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only diff --git a/sesman/tcp.h b/sesman/tcp.h index dfb6d6d1..3acefe61 100644 --- a/sesman/tcp.h +++ b/sesman/tcp.h @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 session manager linux only diff --git a/sesman/verify_user.c b/sesman/verify_user.c index 5e9203c2..8db05871 100644 --- a/sesman/verify_user.c +++ b/sesman/verify_user.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 authenticate user diff --git a/sesman/verify_user_kerberos.c b/sesman/verify_user_kerberos.c index e9751532..a8f1d5ea 100644 --- a/sesman/verify_user_kerberos.c +++ b/sesman/verify_user_kerberos.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 authenticate user using kerberos diff --git a/sesman/verify_user_pam.c b/sesman/verify_user_pam.c index e2b58032..8c736d69 100644 --- a/sesman/verify_user_pam.c +++ b/sesman/verify_user_pam.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 authenticate user diff --git a/sesman/verify_user_pam_userpass.c b/sesman/verify_user_pam_userpass.c index bc133139..7c2a2318 100644 --- a/sesman/verify_user_pam_userpass.c +++ b/sesman/verify_user_pam_userpass.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005 + Copyright (C) Jay Sorg 2005-2006 authenticate user