summaryrefslogtreecommitdiffstats
path: root/sesman/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'sesman/session.c')
-rw-r--r--sesman/session.c161
1 files changed, 135 insertions, 26 deletions
diff --git a/sesman/session.c b/sesman/session.c
index 665d1138..856c969e 100644
--- a/sesman/session.c
+++ b/sesman/session.c
@@ -90,9 +90,10 @@ dumpItemsToString(struct list *self, char *outstr, int len)
/******************************************************************************/
struct session_item *DEFAULT_CC
-session_get_bydata(char *name, int width, int height, int bpp, int type)
+session_get_bydata(char *name, int width, int height, int bpp, int type, char *client_ip)
{
struct session_chain *tmp;
+ enum SESMAN_CFG_SESS_POLICY policy = g_cfg->sess.policy;
/*THREAD-FIX require chain lock */
lock_chain_acquire();
@@ -104,23 +105,49 @@ session_get_bydata(char *name, int width, int height, int bpp, int type)
{
case SCP_SESSION_TYPE_XVNC: /* 0 */
type = SESMAN_SESSION_TYPE_XVNC; /* 2 */
+ policy |= SESMAN_CFG_SESS_POLICY_D; /* Xvnc cannot resize */
break;
case SCP_SESSION_TYPE_XRDP: /* 1 */
type = SESMAN_SESSION_TYPE_XRDP; /* 1 */
break;
+ case SCP_SESSION_TYPE_XORG:
+ type = SESMAN_SESSION_TYPE_XORG;
+ break;
default:
lock_chain_release();
return 0;
}
+#if 0
+ log_message(LOG_LEVEL_INFO,
+ "session_get_bydata: search policy %d U %s W %d H %d bpp %d T %d IP %s",
+ policy, name, width, height, bpp, type, client_ip);
+#endif
+
while (tmp != 0)
{
+#if 0
+ log_message(LOG_LEVEL_INFO,
+ "session_get_bydata: try %p U %s W %d H %d bpp %d T %d IP %s",
+ tmp->item,
+ tmp->item->name,
+ tmp->item->width, tmp->item->height,
+ tmp->item->bpp, tmp->item->type,
+ tmp->item->client_ip);
+#endif
+
if (type == SESMAN_SESSION_TYPE_XRDP)
{
/* only name and bpp need to match for X11rdp, it can resize */
if (g_strncmp(name, tmp->item->name, 255) == 0 &&
- tmp->item->bpp == bpp &&
- tmp->item->type == type)
+ (!(policy & SESMAN_CFG_SESS_POLICY_D) ||
+ (tmp->item->width == width && tmp->item->height == height)) &&
+ (!(policy & SESMAN_CFG_SESS_POLICY_I) ||
+ (g_strncmp_d(client_ip, tmp->item->client_ip, ':', 255) == 0)) &&
+ (!(policy & SESMAN_CFG_SESS_POLICY_C) ||
+ (g_strncmp(client_ip, tmp->item->client_ip, 255) == 0)) &&
+ tmp->item->bpp == bpp &&
+ tmp->item->type == type)
{
/*THREAD-FIX release chain lock */
lock_chain_release();
@@ -129,10 +156,13 @@ session_get_bydata(char *name, int width, int height, int bpp, int type)
}
if (g_strncmp(name, tmp->item->name, 255) == 0 &&
- tmp->item->width == width &&
- tmp->item->height == height &&
- tmp->item->bpp == bpp &&
- tmp->item->type == type)
+ (tmp->item->width == width && tmp->item->height == height) &&
+ (!(policy & SESMAN_CFG_SESS_POLICY_I) ||
+ (g_strncmp_d(client_ip, tmp->item->client_ip, ':', 255) == 0)) &&
+ (!(policy & SESMAN_CFG_SESS_POLICY_C) ||
+ (g_strncmp(client_ip, tmp->item->client_ip, 255) == 0)) &&
+ tmp->item->bpp == bpp &&
+ tmp->item->type == type)
{
/*THREAD-FIX release chain lock */
lock_chain_release();
@@ -173,26 +203,62 @@ x_server_running_check_ports(int display)
if (!x_running) /* check 59xx */
{
- sck = g_tcp_socket();
- g_sprintf(text, "59%2.2d", display);
- x_running = g_tcp_bind(sck, text);
- g_tcp_close(sck);
+ if ((sck = g_tcp_socket()) != -1)
+ {
+ g_sprintf(text, "59%2.2d", display);
+ x_running = g_tcp_bind(sck, text);
+ g_tcp_close(sck);
+ }
}
if (!x_running) /* check 60xx */
{
- sck = g_tcp_socket();
- g_sprintf(text, "60%2.2d", display);
- x_running = g_tcp_bind(sck, text);
- g_tcp_close(sck);
+ if ((sck = g_tcp_socket()) != -1)
+ {
+ g_sprintf(text, "60%2.2d", display);
+ x_running = g_tcp_bind(sck, text);
+ g_tcp_close(sck);
+ }
}
if (!x_running) /* check 62xx */
{
- sck = g_tcp_socket();
- g_sprintf(text, "62%2.2d", display);
- x_running = g_tcp_bind(sck, text);
- g_tcp_close(sck);
+ if ((sck = g_tcp_socket()) != -1)
+ {
+ g_sprintf(text, "62%2.2d", display);
+ x_running = g_tcp_bind(sck, text);
+ g_tcp_close(sck);
+ }
+ }
+
+ if (!x_running)
+ {
+ g_sprintf(text, XRDP_CHANSRV_STR, display);
+ x_running = g_file_exist(text);
+ }
+
+ if (!x_running)
+ {
+ g_sprintf(text, CHANSRV_PORT_OUT_STR, display);
+ x_running = g_file_exist(text);
+ }
+
+ if (!x_running)
+ {
+ g_sprintf(text, CHANSRV_PORT_IN_STR, display);
+ x_running = g_file_exist(text);
+ }
+
+ if (!x_running)
+ {
+ g_sprintf(text, CHANSRV_API_STR, display);
+ x_running = g_file_exist(text);
+ }
+
+ if (!x_running)
+ {
+ g_sprintf(text, XRDP_X11RDP_STR, display);
+ x_running = g_file_exist(text);
}
return x_running;
@@ -258,7 +324,8 @@ session_start_sessvc(int xpid, int wmpid, long data, char *username, int display
list_add_item(sessvc_params, (long)g_strdup(wmpid_str));
list_add_item(sessvc_params, 0); /* mandatory */
- env_set_user(username, 0, display);
+ env_set_user(username, 0, display,
+ g_cfg->session_variables1, g_cfg->session_variables2);
/* executing sessvc */
g_execvp(exe_path, ((char **)sessvc_params->items));
@@ -471,7 +538,9 @@ session_start_fork(int width, int height, int bpp, char *username,
}
else if (pampid == 0) /* child: X11/client */
{
- env_set_user(username, 0, display);
+ env_set_user(username, 0, display,
+ g_cfg->session_variables1,
+ g_cfg->session_variables2);
if (x_server_running(display))
{
auth_set_env(data);
@@ -564,7 +633,9 @@ session_start_fork(int width, int height, int bpp, char *username,
}
else if (xpid == 0) /* child */
{
- env_set_user(username, passwd_file, display);
+ env_set_user(username, passwd_file, display,
+ g_cfg->session_variables1,
+ g_cfg->session_variables2);
env_check_password_file(passwd_file, password);
g_snprintf(text, 255, "%d", g_cfg->sess.max_idle_time);
@@ -574,10 +645,40 @@ session_start_fork(int width, int height, int bpp, char *username,
g_snprintf(text, 255, "%d", g_cfg->sess.kill_disconnected);
g_setenv("XRDP_SESMAN_KILL_DISCONNECTED", text, 1);
- if (type == SESMAN_SESSION_TYPE_XVNC)
+ if (type == SESMAN_SESSION_TYPE_XORG)
{
xserver_params = list_create();
xserver_params->auto_free = 1;
+
+ /* these are the must have parameters */
+ list_add_item(xserver_params, (long) g_strdup("/usr/bin/Xorg"));
+ list_add_item(xserver_params, (long) g_strdup(screen));
+
+ /* additional parameters from sesman.ini file */
+ list_append_list_strdup(g_cfg->xorg_params, xserver_params, 0);
+
+ /* make sure it ends with a zero */
+ list_add_item(xserver_params, 0);
+
+ pp1 = (char **) xserver_params->items;
+
+ log_message(LOG_LEVEL_INFO, "%s", dumpItemsToString(xserver_params, execvpparams, 2048));
+
+ /* some args are passed via env vars */
+ g_sprintf(geometry, "%d", width);
+ g_setenv("XRDP_START_WIDTH", geometry, 1);
+
+ g_sprintf(geometry, "%d", height);
+ g_setenv("XRDP_START_HEIGHT", geometry, 1);
+
+ /* fire up Xorg */
+ g_execvp("/usr/bin/Xorg", pp1);
+ }
+ else if (type == SESMAN_SESSION_TYPE_XVNC)
+ {
+ xserver_params = list_create();
+ xserver_params->auto_free = 1;
+
/* these are the must have parameters */
list_add_item(xserver_params, (long)g_strdup("Xvnc"));
list_add_item(xserver_params, (long)g_strdup(screen));
@@ -596,13 +697,14 @@ session_start_fork(int width, int height, int bpp, char *username,
/* make sure it ends with a zero */
list_add_item(xserver_params, 0);
pp1 = (char **)xserver_params->items;
- log_message(LOG_LEVEL_INFO, "Xvnc start:%s", dumpItemsToString(xserver_params, execvpparams, 2048));
+ log_message(LOG_LEVEL_INFO, "%s", dumpItemsToString(xserver_params, execvpparams, 2048));
g_execvp("Xvnc", pp1);
}
else if (type == SESMAN_SESSION_TYPE_XRDP)
{
xserver_params = list_create();
xserver_params->auto_free = 1;
+
/* these are the must have parameters */
list_add_item(xserver_params, (long)g_strdup("X11rdp"));
list_add_item(xserver_params, (long)g_strdup(screen));
@@ -619,7 +721,7 @@ session_start_fork(int width, int height, int bpp, char *username,
/* make sure it ends with a zero */
list_add_item(xserver_params, 0);
pp1 = (char **)xserver_params->items;
- log_message(LOG_LEVEL_INFO, "X11rdp start:%s", dumpItemsToString(xserver_params, execvpparams, 2048));
+ log_message(LOG_LEVEL_INFO, "%s", dumpItemsToString(xserver_params, execvpparams, 2048));
g_execvp("X11rdp", pp1);
}
else
@@ -693,8 +795,12 @@ session_start_fork(int width, int height, int bpp, char *username,
/*THREAD-FIX release chain lock */
lock_chain_release();
+
+ return display;
}
+ g_free(temp->item);
+ g_free(temp);
return display;
}
@@ -713,7 +819,8 @@ session_reconnect_fork(int display, char *username)
}
else if (pid == 0)
{
- env_set_user(username, 0, display);
+ env_set_user(username, 0, display,
+ g_cfg->session_variables1, g_cfg->session_variables2);
g_snprintf(text, 255, "%s/%s", XRDP_CFG_PATH, "reconnectwm.sh");
if (g_file_exist(text))
@@ -936,6 +1043,7 @@ session_get_bypid(int pid)
"pid %d is null!", pid);
/*THREAD-FIX release chain lock */
lock_chain_release();
+ g_free(dummy);
return 0;
}
@@ -954,6 +1062,7 @@ session_get_bypid(int pid)
/*THREAD-FIX release chain lock */
lock_chain_release();
+ g_free(dummy);
return 0;
}