diff --git a/sesman/auth.h b/sesman/auth.h index 39acc0b8..e06b9eb3 100644 --- a/sesman/auth.h +++ b/sesman/auth.h @@ -49,6 +49,16 @@ auth_userpass(char* user, char* pass, int *errorcode); int DEFAULT_CC auth_start_session(long in_val, int in_display); +/** + * + * @brief FIXME + * @param in_val + * @return 0 on success, 1 on failure + * + */ +int DEFAULT_CC +auth_stop_session(long in_val); + /** * * @brief FIXME diff --git a/sesman/session.c b/sesman/session.c index c21ecb6a..a5932736 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -62,11 +62,11 @@ static int g_sync_cmd; char *APP_CC dumpItemsToString(struct list *self, char *outstr, int len) { - g_memset(outstr, 0, len); int index; tbus item; int totalLen = 0; + g_memset(outstr, 0, len); if (self->count == 0) { g_writeln("List is empty"); @@ -385,6 +385,7 @@ session_start_fork(int width, int height, int bpp, char *username, int display = 0; int pid = 0; int wmpid = 0; + int pampid = 0; int xpid = 0; int i = 0; char geometry[32]; @@ -453,99 +454,105 @@ session_start_fork(int width, int height, int bpp, char *username, { g_tcp_close(g_sck); g_tcp_close(g_thread_sck); - auth_start_session(data, display); g_sprintf(geometry, "%dx%d", width, height); g_sprintf(depth, "%d", bpp); g_sprintf(screen, ":%d", display); wmpid = g_fork(); - if (wmpid == -1) { } else if (wmpid == 0) /* child (child sesman) xserver */ { wait_for_xserver(display); - env_set_user(username, 0, display); - - if (x_server_running(display)) + auth_start_session(data, display); + pampid = g_fork(); + if (pampid == -1) { - auth_set_env(data); - - if (directory != 0) + } + else if (pampid == 0) /* child: X11/client */ + { + env_set_user(username, 0, display); + if (x_server_running(display)) { - if (directory[0] != 0) + auth_set_env(data); + if (directory != 0) { - g_set_current_dir(directory); + if (directory[0] != 0) + { + g_set_current_dir(directory); + } } + if (program != 0) + { + if (program[0] != 0) + { + g_execlp3(program, program, 0); + log_message(LOG_LEVEL_ALWAYS, + "error starting program %s for user %s - pid %d", + program, username, g_getpid()); + } + } + /* 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); + log_message(LOG_LEVEL_ALWAYS, "error starting user " + "wm for user %s - pid %d", username, g_getpid()); + /* logging parameters */ + log_message(LOG_LEVEL_DEBUG, "errno: %d, " + "description: %s", errno, g_get_strerror()); + log_message(LOG_LEVEL_DEBUG, "execlp3 parameter " + "list:"); + log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", + text); + log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", + g_cfg->user_wm); + } + } + /* if we're here something happened to g_execlp3 + so we try running the default window manager */ + g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm); + g_execlp3(text, g_cfg->default_wm, 0); + + log_message(LOG_LEVEL_ALWAYS, "error starting default " + "wm for user %s - pid %d", username, g_getpid()); + /* logging parameters */ + log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " + "%s", errno, g_get_strerror()); + log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:"); + log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", + text); + log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", + g_cfg->default_wm); + + /* still a problem starting window manager just start xterm */ + g_execlp3("xterm", "xterm", 0); + + /* should not get here */ + log_message(LOG_LEVEL_ALWAYS, "error starting xterm " + "for user %s - pid %d", username, g_getpid()); + /* logging parameters */ + log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " + "%s", errno, g_get_strerror()); + } + else + { + log_message(LOG_LEVEL_ERROR, "another Xserver might " + "already be active on display %d - see log", display); } - if (program != 0) - { - if (program[0] != 0) - { - g_execlp3(program, program, 0); - log_message(LOG_LEVEL_ALWAYS, - "error starting program %s for user %s - pid %d", - program, username, g_getpid()); - } - } - - /* 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); - log_message(LOG_LEVEL_ALWAYS, "error starting user " - "wm for user %s - pid %d", username, g_getpid()); - /* logging parameters */ - log_message(LOG_LEVEL_DEBUG, "errno: %d, " - "description: %s", errno, g_get_strerror()); - log_message(LOG_LEVEL_DEBUG, "execlp3 parameter " - "list:"); - log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", - text); - log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", - g_cfg->user_wm); - } - } - - /* if we're here something happened to g_execlp3 - so we try running the default window manager */ - g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm); - g_execlp3(text, g_cfg->default_wm, 0); - - log_message( LOG_LEVEL_ALWAYS, "error starting default " - "wm for user %s - pid %d", username, g_getpid()); - /* logging parameters */ - log_message( LOG_LEVEL_DEBUG, "errno: %d, description: " - "%s", errno, g_get_strerror()); - log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:"); - log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", - text); - log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", - g_cfg->default_wm); - - /* still a problem starting window manager just start xterm */ - g_execlp3("xterm", "xterm", 0); - - /* should not get here */ - log_message(LOG_LEVEL_ALWAYS, "error starting xterm " - "for user %s - pid %d", username, g_getpid()); - /* logging parameters */ - log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " - "%s", errno, g_get_strerror()); + log_message(LOG_LEVEL_DEBUG, "aborting connection..."); + g_exit(0); } else { - log_message(LOG_LEVEL_ERROR, "another Xserver might " - "already be active on display %d - see log", display); + g_waitpid(pampid); + auth_stop_session(data); + g_exit(0); } - - log_message(LOG_LEVEL_DEBUG, "aborting connection..."); - g_exit(0); } else /* parent (child sesman) */ { diff --git a/sesman/verify_user_kerberos.c b/sesman/verify_user_kerberos.c index a6480f56..bb7ba3d2 100644 --- a/sesman/verify_user_kerberos.c +++ b/sesman/verify_user_kerberos.c @@ -430,6 +430,14 @@ auth_start_session(void) return 0; } +/******************************************************************************/ +/* returns error */ +int DEFAULT_CC +auth_stop_session(long in_val) +{ + return 0; +} + /******************************************************************************/ int DEFAULT_CC auth_end(void) diff --git a/sesman/verify_user_pam.c b/sesman/verify_user_pam.c index e53f72d5..4d73f85d 100644 --- a/sesman/verify_user_pam.c +++ b/sesman/verify_user_pam.c @@ -201,6 +201,26 @@ auth_start_session(long in_val, int in_display) return 0; } +/******************************************************************************/ +/* returns error */ +int DEFAULT_CC +auth_stop_session(long in_val) +{ + struct t_auth_info *auth_info; + int error; + + auth_info = (struct t_auth_info *)in_val; + error = pam_close_session(auth_info->ph, 0); + if (error != PAM_SUCCESS) + { + g_printf("pam_close_session failed: %s\r\n", + pam_strerror(auth_info->ph, error)); + return 1; + } + auth_info->session_opened = 0; + return 0; +} + /******************************************************************************/ /* returns error */ /* cleanup */ diff --git a/sesman/verify_user_pam_userpass.c b/sesman/verify_user_pam_userpass.c index 7f31176e..b3d4de73 100644 --- a/sesman/verify_user_pam_userpass.c +++ b/sesman/verify_user_pam_userpass.c @@ -90,6 +90,14 @@ auth_start_session(void) return 0; } +/******************************************************************************/ +/* returns error */ +int DEFAULT_CC +auth_stop_session(long in_val) +{ + return 0; +} + /******************************************************************************/ int DEFAULT_CC auth_end(void)