summaryrefslogtreecommitdiffstats
path: root/sesman
diff options
context:
space:
mode:
Diffstat (limited to 'sesman')
-rw-r--r--sesman/chansrv/chansrv.c5
-rw-r--r--sesman/scp_v0.c13
-rw-r--r--sesman/scp_v1.c9
-rw-r--r--sesman/session.c168
4 files changed, 184 insertions, 11 deletions
diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c
index 918bb832..7b4bf0b5 100644
--- a/sesman/chansrv/chansrv.c
+++ b/sesman/chansrv/chansrv.c
@@ -442,6 +442,7 @@ send_init_response_message(void)
out_uint32_le(s, 2); /* msg id */
out_uint32_le(s, 8); /* size */
s_mark_end(s);
+ LOG(1, ("send_init_response_message: calling trans_force_write"));
return trans_write_copy(g_con_trans);
}
@@ -775,6 +776,7 @@ process_message(void)
if (rv != 0)
{
+ LOG(0, ("process_message: error in process_message: rv %d", rv));
break;
}
@@ -1173,7 +1175,6 @@ channel_thread_loop(void *in_val)
g_con_trans = 0;
// Use the display number to mark session disconnected in the Raptor session management database
raptor_sm_set_session_state(g_display_num, SM_STATUS_RUNNING);
- exit(0); // RAPTOR session management
/* create new listener */
error = setup_listen();
@@ -1409,6 +1410,7 @@ read_ini(void)
name = (char *)list_get_item(names, index);
value = (char *)list_get_item(values, index);
+#ifndef DISABLE_UNIX_DOMAIN_SOCKETS
if (g_strcasecmp(name, "ListenAddress") == 0)
{
if (g_strcasecmp(value, "127.0.0.1") == 0)
@@ -1416,6 +1418,7 @@ read_ini(void)
g_use_unix_socket = 1;
}
}
+#endif
}
}
diff --git a/sesman/scp_v0.c b/sesman/scp_v0.c
index efa9080c..5eb13e05 100644
--- a/sesman/scp_v0.c
+++ b/sesman/scp_v0.c
@@ -26,6 +26,8 @@
#include "sesman.h"
+#include "libraptorsmiface.h"
+
extern struct config_sesman *g_cfg; /* in sesman.c */
/******************************************************************************/
@@ -76,6 +78,17 @@ scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
s_item = session_get_bydata(s->username, s->width, s->height,
s->bpp, s->type, s->client_ip);
+ // RAPTOR session management
+ pid_t serverpid = raptor_sm_get_pid_for_username(s->username);
+ if (serverpid < 0) {
+ // Session NOT already running
+ if (s_item != 0) {
+ log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ [FIXME] scp claimed there was an active session, but the authoritative RAPTOR database disagrees: username %s", s->username);
+ }
+ s_item = 0;
+ }
+
+
if (s_item != 0)
{
display = s_item->display;
diff --git a/sesman/scp_v1.c b/sesman/scp_v1.c
index 92e1dad5..008c7c9d 100644
--- a/sesman/scp_v1.c
+++ b/sesman/scp_v1.c
@@ -29,6 +29,8 @@
//#include "libscp_types.h"
#include "libscp.h"
+#include "libraptorsmiface.h"
+
extern struct config_sesman *g_cfg; /* in sesman.c */
static void parseCommonStates(enum SCP_SERVER_STATES_E e, char *f);
@@ -107,6 +109,13 @@ scp_v1_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
/* list disconnected sessions */
slist = session_get_byuser(s->username, &scount, SESMAN_SESSION_STATUS_DISCONNECTED);
+ // RAPTOR session management
+ pid_t serverpid = raptor_sm_get_pid_for_username(s->username);
+ if (serverpid < 0) {
+ // Session NOT already running
+ scount = 0;
+ }
+
if (scount == 0)
{
/* no disconnected sessions - start a new one */
diff --git a/sesman/session.c b/sesman/session.c
index 250c8baf..1e6a22ce 100644
--- a/sesman/session.c
+++ b/sesman/session.c
@@ -35,6 +35,15 @@
#include <errno.h>
//#include <time.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <netdb.h>
+
#include "libraptorsmiface.h"
extern unsigned char g_fixedkey[8];
@@ -146,6 +155,82 @@ session_get_bydata(char *name, int width, int height, int bpp, int type, char *c
/******************************************************************************/
/**
*
+ * @brief checks if there's a server running on a host and port
+ * @param display the display to check
+ * @return 0 if the port is closed, 1 if it is open
+ *
+ */
+static int DEFAULT_CC
+check_port_status(const char* host, const char* port)
+{
+ char text[256];
+ int x_running;
+ int sck;
+
+ struct sockaddr_in servaddr;
+ int soc = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ g_memset( &servaddr, 0, sizeof(servaddr));
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_port = htons(atoi(port));
+
+ struct hostent* hostaddr;
+ hostaddr = gethostbyname(host);
+ g_memcpy(&servaddr.sin_addr, hostaddr->h_addr, hostaddr->h_length);
+
+ int res = connect(soc, (struct sockaddr*)&servaddr, sizeof(servaddr));
+
+ close(soc);
+
+ if (res == -1)
+ {
+ // Port is closed, no server there!
+ return 0;
+ }
+ else {
+ // Port is open
+ return 1;
+ }
+}
+
+/******************************************************************************/
+/**
+ *
+ * @brief checks if there's a server running on a remote display
+ * @param display the display to check
+ * @return 0 if there isn't a display running, nonzero otherwise
+ *
+ */
+static int DEFAULT_CC
+x_server_running_check_remote_ports(const char* host, int display)
+{
+ char text[256];
+ int x_running;
+ int sck;
+
+ x_running = 0;
+ /* check 59xx */
+ {
+ g_sprintf(text, "59%2.2d", display);
+ x_running += check_port_status(host, text);
+ }
+ /* check 60xx */
+ {
+ g_sprintf(text, "60%2.2d", display);
+ x_running += check_port_status(host, text);
+ }
+ /* check 62xx */
+ {
+ g_sprintf(text, "62%2.2d", display);
+ x_running += check_port_status(host, text);
+ }
+
+ return x_running;
+}
+
+/******************************************************************************/
+/**
+ *
* @brief checks if there's a server running on a display
* @param display the display to check
* @return 0 if there isn't a display running, nonzero otherwise
@@ -383,14 +468,14 @@ wait_for_xserver(int display)
int i;
/* give X a bit to start */
- /* wait up to 10 secs for x server to start */
+ /* wait up to 15 secs for x server to start */
i = 0;
- while (!x_server_running(display))
+ while (!x_server_running_check_ports(display))
{
i++;
- if (i > 40)
+ if (i > 60)
{
log_message(LOG_LEVEL_ERROR,
"X server for display %d startup timeout",
@@ -405,6 +490,57 @@ wait_for_xserver(int display)
}
/******************************************************************************/
+static int APP_CC
+wait_for_remote_xserver(const char* host, int display)
+{
+ int i;
+
+ /* give X a bit to start */
+ /* wait up to 15 secs for x server to start */
+ i = 0;
+ //while (!x_server_running(display))
+ while (!x_server_running_check_remote_ports(host, display))
+ {
+ i++;
+ if (i > 60)
+ {
+ log_message(&(g_cfg->log), LOG_LEVEL_ERROR,
+ "X server for host %s and display %d startup timeout",
+ host, display);
+ break;
+ }
+ g_sleep(250);
+ }
+ return 0;
+}
+
+/******************************************************************************/
+static const char * APP_CC
+wait_for_remote_hostname(char* username)
+{
+ int i;
+
+ /* wait up to 5 secs for hostname to appear */
+ i = 0;
+ const char * hostname = raptor_sm_get_hostname_for_username(username, false);
+ while (strcmp(hostname, "") == 0)
+ {
+ g_free(hostname);
+ hostname = raptor_sm_get_hostname_for_username(username, false);
+ i++;
+ if (i > 20)
+ {
+ log_message(&(g_cfg->log), LOG_LEVEL_ERROR,
+ "Hostname allocation timeout");
+ break;
+ }
+ g_sleep(250);
+ }
+
+ return hostname;
+}
+
+/******************************************************************************/
/* called with the main thread */
static int APP_CC
session_start_fork(int width, int height, int bpp, char *username,
@@ -485,6 +621,7 @@ session_start_fork(int width, int height, int bpp, char *username,
if (display == 0)
{
+ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "Unable to allocate display for user %s", username);
g_free(temp->item);
g_free(temp);
return 0;
@@ -547,7 +684,6 @@ session_start_fork(int width, int height, int bpp, char *username,
}
else if (wmpid == 0)
{
- wait_for_xserver(display);
auth_start_session(data, display);
pampid = g_fork(); /* parent waits, todo
child becomes wm */
@@ -556,17 +692,24 @@ session_start_fork(int width, int height, int bpp, char *username,
}
else if (pampid == 0)
{
- env_set_user(username, 0, display,
- g_cfg->session_variables1,
- g_cfg->session_variables2);
if (session_was_already_running) {
g_exit(0);
}
+ char* remote_server = wait_for_remote_hostname(username);
+ wait_for_remote_xserver(remote_server, display);
env_set_user(username, 0, display,
g_cfg->session_variables1,
g_cfg->session_variables2);
- if (x_server_running(display))
+
+ //if (x_server_running(display))
+ if (x_server_running_check_remote_ports(remote_server, display))
{
+ g_free(remote_server);
+
+ // RAPTOR session management
+ raptor_sm_run_remote_desktop(username, display, "/opt/trinity/bin/starttde");
+ g_exit(0);
+
auth_set_env(data);
if (directory != 0)
{
@@ -633,6 +776,7 @@ session_start_fork(int width, int height, int bpp, char *username,
}
else
{
+ g_free(remote_server);
log_message(LOG_LEVEL_ERROR, "another Xserver might "
"already be active on display %d - see log", display);
}
@@ -754,7 +898,7 @@ session_start_fork(int width, int height, int bpp, char *username,
list_add_item(xserver_params, (tintptr)g_strdup("-depth"));
list_add_item(xserver_params, (tintptr)g_strdup(depth));
list_add_item(xserver_params, (tintptr)g_strdup("-reset"));
- list_add_item(xserver_params, (tintptr)g_strdup("-terminate"));
+// list_add_item(xserver_params, (tintptr)g_strdup("-terminate"));
/* additional parameters from sesman.ini file */
//config_read_xserver_params(SESMAN_SESSION_TYPE_XRDP,
@@ -768,6 +912,7 @@ session_start_fork(int width, int height, int bpp, char *username,
pid_t serverpid;
serverpid = raptor_sm_run_remote_server(username, pp1);
+ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "new server pid code was %d during login for user %s", serverpid, username);
if (serverpid >= 0) {
if (!session_was_already_running) {
@@ -818,7 +963,10 @@ session_start_fork(int width, int height, int bpp, char *username,
}
else
{
- wait_for_xserver(display);
+ //wait_for_xserver(display);
+ char* remote_server = wait_for_remote_hostname(username);
+ wait_for_remote_xserver(remote_server, display);
+ free(remote_server);
g_snprintf(text, 255, "%d", display);
g_setenv("XRDP_SESSVC_DISPLAY", text, 1);
g_snprintf(text, 255, ":%d.0", display);