work on chansrv

This commit is contained in:
jsorg71 2009-04-20 04:31:24 +00:00
parent da99343957
commit c6b9952fa2
5 changed files with 109 additions and 75 deletions

View File

@ -1697,6 +1697,13 @@ g_get_strerror(void)
#endif #endif
} }
/*****************************************************************************/
int APP_CC
g_get_errno(void)
{
return errno;
}
/*****************************************************************************/ /*****************************************************************************/
/* does not work in win32 */ /* does not work in win32 */
int APP_CC int APP_CC

View File

@ -191,6 +191,8 @@ g_system(char* aexec);
char* APP_CC char* APP_CC
g_get_strerror(void); g_get_strerror(void);
int APP_CC int APP_CC
g_get_errno(void);
int APP_CC
g_execvp(const char* p1, char* args[]); g_execvp(const char* p1, char* args[]);
int APP_CC int APP_CC
g_execlp3(const char* a1, const char* a2, const char* a3); g_execlp3(const char* a1, const char* a2, const char* a3);

View File

@ -173,6 +173,7 @@ process_message_channel_setup(struct stream* s)
g_writeln("xrdp-chansrv: in process_message_channel_setup"); g_writeln("xrdp-chansrv: in process_message_channel_setup");
in_uint16_le(s, num_chans); in_uint16_le(s, num_chans);
g_writeln("xrdp-chansrv: num_chans %d", num_chans);
for (index = 0; index < num_chans; index++) for (index = 0; index < num_chans; index++)
{ {
ci = &(g_chan_items[g_num_chan_items]); ci = &(g_chan_items[g_num_chan_items]);
@ -180,8 +181,8 @@ process_message_channel_setup(struct stream* s)
in_uint8a(s, ci->name, 8); in_uint8a(s, ci->name, 8);
in_uint16_le(s, ci->id); in_uint16_le(s, ci->id);
in_uint16_le(s, ci->flags); in_uint16_le(s, ci->flags);
g_writeln("xrdp-chansrv: chan name %s id %d flags %d", ci->name, ci->id, g_writeln("xrdp-chansrv: chan name %s id %d flags %8.8x",
ci->flags); ci->name, ci->id, ci->flags);
if (g_strcasecmp(ci->name, "cliprdr") == 0) if (g_strcasecmp(ci->name, "cliprdr") == 0)
{ {
g_clip_index = g_num_chan_items; g_clip_index = g_num_chan_items;
@ -470,7 +471,7 @@ main(int argc, char** argv)
char* display_text; char* display_text;
pid = g_getpid(); pid = g_getpid();
g_writeln("xrdp-chansrv: started pid %d(0x%8.8x)", pid, pid); g_writeln("xrdp-chansrv: app started pid %d(0x%8.8x)", pid, pid);
g_signal_kill(term_signal_handler); /* SIGKILL */ g_signal_kill(term_signal_handler); /* SIGKILL */
g_signal_terminate(term_signal_handler); /* SIGTERM */ g_signal_terminate(term_signal_handler); /* SIGTERM */
g_signal_user_interrupt(term_signal_handler); /* SIGINT */ g_signal_user_interrupt(term_signal_handler); /* SIGINT */
@ -490,9 +491,10 @@ main(int argc, char** argv)
g_writeln("xrdp-chansrv: error, display is zero"); g_writeln("xrdp-chansrv: error, display is zero");
return 1; return 1;
} }
g_snprintf(text, 255, "xrdp_chansrv_term_%8.8x", pid); g_writeln("xrdp-chansrv: using DISPLAY %d", g_display);
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
g_term_event = g_create_wait_obj(text); g_term_event = g_create_wait_obj(text);
g_snprintf(text, 255, "xrdp_chansrv_thread_done_%8.8x", pid); g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
g_thread_done_event = g_create_wait_obj(text); g_thread_done_event = g_create_wait_obj(text);
tc_thread_create(channel_thread_loop, 0); tc_thread_create(channel_thread_loop, 0);
if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0) if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0)
@ -507,5 +509,6 @@ main(int argc, char** argv)
/* cleanup */ /* cleanup */
g_delete_wait_obj(g_term_event); g_delete_wait_obj(g_term_event);
g_delete_wait_obj(g_thread_done_event); g_delete_wait_obj(g_thread_done_event);
g_writeln("xrdp-chansrv: app exiting pid %d(0x%8.8x)", pid, pid);
return 0; return 0;
} }

View File

@ -205,24 +205,24 @@ session_start_fork(int width, int height, int bpp, char* username,
/* check to limit concurrent sessions */ /* check to limit concurrent sessions */
if (g_session_count >= g_cfg->sess.max_sessions) if (g_session_count >= g_cfg->sess.max_sessions)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "max concurrent session limit exceeded. login \ log_message(&(g_cfg->log), LOG_LEVEL_INFO, "max concurrent session limit "
for user %s denied", username); "exceeded. login for user %s denied", username);
return 0; return 0;
} }
temp = (struct session_chain*)g_malloc(sizeof(struct session_chain), 0); temp = (struct session_chain*)g_malloc(sizeof(struct session_chain), 0);
if (temp == 0) if (temp == 0)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new chain element - user %s", log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new chain "
username); "element - user %s", username);
return 0; return 0;
} }
temp->item = (struct session_item*)g_malloc(sizeof(struct session_item), 0); temp->item = (struct session_item*)g_malloc(sizeof(struct session_item), 0);
if (temp->item == 0) if (temp->item == 0)
{ {
g_free(temp); g_free(temp);
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new session item - user %s", log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new session "
username); "item - user %s", username);
return 0; return 0;
} }
@ -283,15 +283,17 @@ for user %s denied", username);
if (g_file_exist(text)) if (g_file_exist(text))
{ {
g_execlp3(text, g_cfg->user_wm, 0); g_execlp3(text, g_cfg->user_wm, 0);
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting user wm for user %s - pid %d", log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting user "
username, g_getpid()); "wm for user %s - pid %d", username, g_getpid());
/* logging parameters */ /* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */ log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, "
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, "description: %s", errno, g_get_strerror());
g_get_strerror()); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter "
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter list:"); "list:");
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s", text); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s",
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->user_wm); text);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s",
g_cfg->user_wm);
} }
} }
/* if we're here something happened to g_execlp3 /* if we're here something happened to g_execlp3
@ -299,29 +301,31 @@ for user %s denied", username);
g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm); g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm);
g_execlp3(text, g_cfg->default_wm, 0); g_execlp3(text, g_cfg->default_wm, 0);
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting default wm for user %s - pid %d", log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting default "
username, g_getpid()); "wm for user %s - pid %d", username, g_getpid());
/* logging parameters */ /* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */ log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: "
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, "%s", errno, g_get_strerror());
g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter list:"); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter list:");
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s", text); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s",
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->default_wm); text);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s",
g_cfg->default_wm);
/* still a problem starting window manager just start xterm */ /* still a problem starting window manager just start xterm */
g_execlp3("xterm", "xterm", 0); g_execlp3("xterm", "xterm", 0);
/* should not get here */ /* should not get here */
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting xterm for user %s - pid %d", log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting xterm "
username, g_getpid()); "for user %s - pid %d", username, g_getpid());
/* logging parameters */ /* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */ log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: "
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror()); "%s", errno, g_get_strerror());
} }
else else
{ {
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "another Xserver is already active on display %d", display); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "another Xserver is "
"already active on display %d", display);
} }
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"aborting connection..."); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"aborting connection...");
g_exit(0); g_exit(0);
@ -384,29 +388,35 @@ for user %s denied", username);
} }
else else
{ {
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "bad session type - user %s - pid %d", log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "bad session type - "
username, g_getpid()); "user %s - pid %d", username, g_getpid());
g_exit(1); g_exit(1);
} }
/* should not get here */ /* should not get here */
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "error starting X server - user %s - pid %d", log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "error starting X server "
username, g_getpid()); "- user %s - pid %d", username, g_getpid());
/* logging parameters */ /* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */ log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: "
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror()); "%s", errno, g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "execve parameter list: %d", (xserver_params)->count); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "execve parameter list: "
"%d", (xserver_params)->count);
for (i=0; i<(xserver_params->count); i++) for (i=0; i<(xserver_params->count); i++)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(xserver_params, i)); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[%d] = %s",
i, (char*)list_get_item(xserver_params, i));
} }
list_delete(xserver_params); list_delete(xserver_params);
g_exit(1); g_exit(1);
} }
else /* parent (child sesman)*/ else /* parent (child sesman)*/
{ {
g_snprintf(text, 255, "%d", display);
g_setenv("XRDP_SESSVC_DISPLAY", text, 1);
g_snprintf(text, 255, ":%d.0", display);
g_setenv("DISPLAY", text, 1);
/* new style waiting for clients */ /* new style waiting for clients */
session_start_sessvc(xpid, wmpid, data); session_start_sessvc(xpid, wmpid, data);
} }
@ -505,8 +515,8 @@ session_kill(int pid)
{ {
if (tmp->item == 0) if (tmp->item == 0)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for pid %d is null!", log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for "
pid); "pid %d is null!", pid);
if (prev == 0) if (prev == 0)
{ {
/* prev does no exist, so it's the first element - so we set /* prev does no exist, so it's the first element - so we set
@ -525,8 +535,8 @@ session_kill(int pid)
if (tmp->item->pid == pid) if (tmp->item->pid == pid)
{ {
/* deleting the session */ /* deleting the session */
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session %d - user %s - terminated", log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session %d - user %s - "
tmp->item->pid, tmp->item->name); "terminated", tmp->item->pid, tmp->item->name);
g_free(tmp->item); g_free(tmp->item);
if (prev == 0) if (prev == 0)
{ {
@ -570,7 +580,8 @@ session_sigkill_all()
{ {
if (tmp->item == 0) if (tmp->item == 0)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "found null session descriptor!"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "found null session "
"descriptor!");
} }
else else
{ {
@ -607,8 +618,8 @@ session_get_bypid(int pid)
{ {
if (tmp->item == 0) if (tmp->item == 0)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for pid %d is null!", log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for "
pid); "pid %d is null!", pid);
/*THREAD-FIX release chain lock */ /*THREAD-FIX release chain lock */
lock_chain_release(); lock_chain_release();
return 0; return 0;
@ -652,7 +663,9 @@ session_get_byuser(char* user, int* cnt, unsigned char flags)
LOG_DBG(&(g_cfg->log), "user: %s", user); LOG_DBG(&(g_cfg->log), "user: %s", user);
if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256))) if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256)))
{ {
LOG_DBG(&(g_cfg->log), "session_get_byuser: status=%d, flags=%d, result=%d", (tmp->item->status), flags, ((tmp->item->status) & flags)); LOG_DBG(&(g_cfg->log), "session_get_byuser: status=%d, flags=%d, "
"result=%d", (tmp->item->status), flags,
((tmp->item->status) & flags));
if ((tmp->item->status) & flags) if ((tmp->item->status) & flags)
{ {
count++; count++;
@ -733,4 +746,3 @@ session_get_byuser(char* user, int* cnt, unsigned char flags)
(*cnt)=count; (*cnt)=count;
return sess; return sess;
} }

View File

@ -14,7 +14,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server. xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005-2008 Copyright (C) Jay Sorg 2005-2009
*/ */
/** /**
@ -25,43 +25,53 @@
* *
*/ */
#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif
#include "file_loc.h"
#include "os_calls.h" #include "os_calls.h"
#include "arch.h" #include "arch.h"
#include "log.h"
#include <sys/types.h>
#include <errno.h>
pid_t wm_pid;
pid_t x_pid;
void DEFAULT_CC
signal_handler(int sig)
{
g_sigterm(x_pid);
g_sigterm(wm_pid);
g_exit(0);
}
/******************************************************************************/ /******************************************************************************/
int DEFAULT_CC int DEFAULT_CC
main(int argc, char** argv) main(int argc, char** argv)
{ {
int ret=0; int ret;
int chansrv_pid;
int wm_pid;
int x_pid;
char exe_path[262];
if (argc < 3)
{
g_writeln("xrdp-sessvc: exiting, not enough params");
return 1;
}
x_pid = g_atoi(argv[1]); x_pid = g_atoi(argv[1]);
wm_pid = g_atoi(argv[2]); wm_pid = g_atoi(argv[2]);
g_writeln("xrdp-sessvc: waiting for X (pid %d) and WM (pid %d)",
g_printf("\n[sessvc] Setting signal handler\n"); x_pid, wm_pid);
g_signal(9, signal_handler); /* SIGKILL */ /* run xrdp-chansrv as a seperate process */
g_signal(15, signal_handler); /* SIGTERM */ chansrv_pid = g_fork();
g_signal(17, signal_handler); /* SIGCHLD */ if (chansrv_pid == -1)
{
g_printf("\n[sessvc] Waiting for X (pid %d) and WM (pid %d)\n", x_pid, wm_pid); g_writeln("xrdp-sessvc: fork error");
return 1;
}
else if (chansrv_pid == 0) /* child */
{
g_snprintf(exe_path, 261, "%s/xrdp-chansrv", XRDP_SBIN_PATH);
g_execvp(exe_path, 0);
/* should not get here */
return 1;
}
/* wait for window manager to get done */
ret = g_waitpid(wm_pid); ret = g_waitpid(wm_pid);
/* kill X server */
g_sigterm(x_pid); g_sigterm(x_pid);
/* kill channel server */
g_printf("\n[sessvc] WM is dead (waitpid said %d, errno is %d). exiting...\n", ret, errno); g_sigterm(chansrv_pid);
g_writeln("xrdp-sessvc: WM is dead (waitpid said %d, errno is %d) "
"exiting...", ret, g_get_errno());
return 0; return 0;
} }