2012-09-20 07:51:34 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2015-12-12 07:41:17 +03:00
|
|
|
* Copyright (C) Jay Sorg 2004-2015
|
2012-09-20 07:51:34 +04:00
|
|
|
*
|
2015-06-16 09:10:30 +03:00
|
|
|
* BSD process grouping by:
|
|
|
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland.
|
|
|
|
* Copyright (c) 2000-2001 Markus Friedl.
|
|
|
|
* Copyright (c) 2011-2015 Koichiro Iwao, Kyushu Institute of Technology.
|
|
|
|
*
|
2012-09-20 07:51:34 +04:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2005-10-06 23:27:38 +04:00
|
|
|
|
2006-05-26 00:34:32 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @file session.c
|
|
|
|
* @brief Session management code
|
|
|
|
* @author Jay Sorg, Simone Fedele
|
2007-04-07 20:20:08 +04:00
|
|
|
*
|
2006-05-26 00:34:32 +04:00
|
|
|
*/
|
|
|
|
|
2016-11-29 11:42:48 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include "config_ac.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PRCTL_H
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-06 23:27:38 +04:00
|
|
|
#include "sesman.h"
|
2006-11-05 16:11:20 +03:00
|
|
|
#include "libscp_types.h"
|
2016-12-15 20:06:35 +03:00
|
|
|
#include "xauth.h"
|
2017-03-18 20:15:50 +03:00
|
|
|
#include "xrdp_sockets.h"
|
2005-10-06 23:27:38 +04:00
|
|
|
|
2016-11-29 11:42:48 +03:00
|
|
|
#ifndef PR_SET_NO_NEW_PRIVS
|
|
|
|
#define PR_SET_NO_NEW_PRIVS 38
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-10-06 23:27:38 +04:00
|
|
|
extern unsigned char g_fixedkey[8];
|
2012-09-20 07:51:34 +04:00
|
|
|
extern struct config_sesman *g_cfg; /* in sesman.c */
|
2013-05-28 22:54:44 +04:00
|
|
|
extern int g_sck; /* in sesman.c */
|
2012-09-20 07:51:34 +04:00
|
|
|
struct session_chain *g_sessions;
|
2006-01-13 18:51:23 +03:00
|
|
|
int g_session_count;
|
2005-10-06 23:27:38 +04:00
|
|
|
|
2015-09-27 11:26:22 +03:00
|
|
|
extern tbus g_term_event; /* in sesman.c */
|
2009-01-12 09:43:58 +03:00
|
|
|
|
2012-05-27 19:17:39 +04:00
|
|
|
/**
|
|
|
|
* Creates a string consisting of all parameters that is hosted in the param list
|
|
|
|
* @param self
|
|
|
|
* @param outstr, allocate this buffer before you use this function
|
|
|
|
* @param len the allocated len for outstr
|
2012-06-11 10:47:08 +04:00
|
|
|
* @return
|
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
char *
|
2012-09-20 07:51:34 +04:00
|
|
|
dumpItemsToString(struct list *self, char *outstr, int len)
|
2012-05-27 19:17:39 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int index;
|
|
|
|
int totalLen = 0;
|
|
|
|
|
2013-10-01 21:42:00 +04:00
|
|
|
g_memset(outstr, 0, len);
|
2012-09-20 07:51:34 +04:00
|
|
|
if (self->count == 0)
|
|
|
|
{
|
|
|
|
g_writeln("List is empty");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < self->count; index++)
|
|
|
|
{
|
|
|
|
/* +1 = one space*/
|
|
|
|
totalLen = totalLen + g_strlen((char *)list_get_item(self, index)) + 1;
|
|
|
|
|
|
|
|
if (len > totalLen)
|
|
|
|
{
|
|
|
|
g_strcat(outstr, (char *)list_get_item(self, index));
|
|
|
|
g_strcat(outstr, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return outstr ;
|
2012-05-27 19:17:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-06 23:27:38 +04:00
|
|
|
/******************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
struct session_item *
|
2016-10-17 09:14:06 +03:00
|
|
|
session_get_bydata(const char *name, int width, int height, int bpp, int type,
|
|
|
|
const char *client_ip)
|
2005-10-06 23:27:38 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct session_chain *tmp;
|
2014-04-20 11:42:19 +04:00
|
|
|
enum SESMAN_CFG_SESS_POLICY policy = g_cfg->sess.policy;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
tmp = g_sessions;
|
|
|
|
|
|
|
|
/* convert from SCP_SESSION_TYPE namespace to SESMAN_SESSION_TYPE namespace */
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SCP_SESSION_TYPE_XVNC: /* 0 */
|
|
|
|
type = SESMAN_SESSION_TYPE_XVNC; /* 2 */
|
2016-07-08 03:40:33 +03:00
|
|
|
/* Xvnc cannot resize */
|
|
|
|
policy = (enum SESMAN_CFG_SESS_POLICY)
|
|
|
|
(policy | SESMAN_CFG_SESS_POLICY_D);
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
case SCP_SESSION_TYPE_XRDP: /* 1 */
|
|
|
|
type = SESMAN_SESSION_TYPE_XRDP; /* 1 */
|
|
|
|
break;
|
2014-03-22 15:36:33 +04:00
|
|
|
case SCP_SESSION_TYPE_XORG:
|
2014-03-22 18:07:06 +04:00
|
|
|
type = SESMAN_SESSION_TYPE_XORG;
|
|
|
|
break;
|
2012-09-20 07:51:34 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
2011-08-24 06:27:12 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-04-20 11:42:19 +04:00
|
|
|
#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
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
while (tmp != 0)
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
2014-04-20 11:42:19 +04:00
|
|
|
#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
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_strncmp(name, tmp->item->name, 255) == 0 &&
|
2015-10-26 01:25:19 +03:00
|
|
|
(!(policy & SESMAN_CFG_SESS_POLICY_D) ||
|
|
|
|
(tmp->item->width == width && tmp->item->height == height)) &&
|
2014-04-20 11:42:19 +04:00
|
|
|
(!(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)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return tmp->item;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp->next;
|
2006-01-13 18:51:23 +03:00
|
|
|
}
|
2007-02-01 09:43:06 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-10-06 23:27:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2006-05-26 00:34:32 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-08-06 23:01:09 +04:00
|
|
|
x_server_running_check_ports(int display)
|
2005-10-06 23:27:38 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
char text[256];
|
|
|
|
int x_running;
|
|
|
|
int sck;
|
|
|
|
|
|
|
|
g_sprintf(text, "/tmp/.X11-unix/X%d", display);
|
2006-02-05 22:09:44 +03:00
|
|
|
x_running = g_file_exist(text);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (!x_running)
|
|
|
|
{
|
|
|
|
g_sprintf(text, "/tmp/.X%d-lock", display);
|
|
|
|
x_running = g_file_exist(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x_running) /* check 59xx */
|
|
|
|
{
|
2014-07-27 00:33:23 +04:00
|
|
|
if ((sck = g_tcp_socket()) != -1)
|
|
|
|
{
|
|
|
|
g_sprintf(text, "59%2.2d", display);
|
|
|
|
x_running = g_tcp_bind(sck, text);
|
|
|
|
g_tcp_close(sck);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!x_running) /* check 60xx */
|
|
|
|
{
|
2014-07-27 00:33:23 +04:00
|
|
|
if ((sck = g_tcp_socket()) != -1)
|
|
|
|
{
|
|
|
|
g_sprintf(text, "60%2.2d", display);
|
|
|
|
x_running = g_tcp_bind(sck, text);
|
|
|
|
g_tcp_close(sck);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!x_running) /* check 62xx */
|
|
|
|
{
|
2014-07-27 00:33:23 +04:00
|
|
|
if ((sck = g_tcp_socket()) != -1)
|
|
|
|
{
|
|
|
|
g_sprintf(text, "62%2.2d", display);
|
|
|
|
x_running = g_tcp_bind(sck, text);
|
|
|
|
g_tcp_close(sck);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2014-08-07 00:33:12 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return x_running;
|
2005-10-06 23:27:38 +04:00
|
|
|
}
|
|
|
|
|
2009-08-06 23:01:09 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-08-06 23:01:09 +04:00
|
|
|
x_server_running(int display)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
char text[256];
|
|
|
|
int x_running;
|
|
|
|
|
|
|
|
g_sprintf(text, "/tmp/.X11-unix/X%d", display);
|
2009-08-06 23:01:09 +04:00
|
|
|
x_running = g_file_exist(text);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (!x_running)
|
|
|
|
{
|
|
|
|
g_sprintf(text, "/tmp/.X%d-lock", display);
|
|
|
|
x_running = g_file_exist(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
return x_running;
|
2009-08-06 23:01:09 +04:00
|
|
|
}
|
|
|
|
|
2009-08-06 10:13:52 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
/* called with the main thread
|
|
|
|
returns boolean */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-08-06 10:13:52 +04:00
|
|
|
session_is_display_in_chain(int display)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct session_chain *chain;
|
|
|
|
struct session_item *item;
|
2009-08-06 10:13:52 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
chain = g_sessions;
|
|
|
|
|
|
|
|
while (chain != 0)
|
2009-08-06 10:13:52 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
item = chain->item;
|
|
|
|
|
|
|
|
if (item->display == display)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
chain = chain->next;
|
2009-08-06 10:13:52 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return 0;
|
2009-08-06 10:13:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* called with the main thread */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2016-02-14 07:41:07 +03:00
|
|
|
session_get_avail_display_from_chain(void)
|
2009-08-06 10:13:52 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int display;
|
2009-08-06 10:13:52 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
display = g_cfg->sess.x11_display_offset;
|
|
|
|
|
|
|
|
while ((display - g_cfg->sess.x11_display_offset) <= g_cfg->sess.max_sessions)
|
2009-08-06 10:13:52 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (!session_is_display_in_chain(display))
|
|
|
|
{
|
|
|
|
if (!x_server_running_check_ports(display))
|
|
|
|
{
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
display++;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_ERROR, "X server -- no display in range is available");
|
|
|
|
return 0;
|
2009-08-06 10:13:52 +04:00
|
|
|
}
|
|
|
|
|
2009-08-27 06:16:34 +04:00
|
|
|
/******************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-08-27 06:16:34 +04:00
|
|
|
wait_for_xserver(int display)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* give X a bit to start */
|
|
|
|
/* wait up to 10 secs for x server to start */
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
while (!x_server_running(display))
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i > 40)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,
|
|
|
|
"X server for display %d startup timeout",
|
|
|
|
display);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_sleep(250);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-08-27 06:16:34 +04:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:45:58 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
static int
|
|
|
|
session_start_chansrv(char *username, int display)
|
|
|
|
{
|
|
|
|
struct list *chansrv_params;
|
|
|
|
char exe_path[262];
|
|
|
|
int chansrv_pid;
|
|
|
|
|
|
|
|
chansrv_pid = g_fork();
|
|
|
|
if (chansrv_pid == 0)
|
|
|
|
{
|
2017-12-15 11:52:39 +03:00
|
|
|
chansrv_params = list_create();
|
2017-03-19 00:45:58 +03:00
|
|
|
chansrv_params->auto_free = 1;
|
|
|
|
|
|
|
|
/* building parameters */
|
|
|
|
g_snprintf(exe_path, sizeof(exe_path), "%s/xrdp-chansrv",
|
|
|
|
XRDP_SBIN_PATH);
|
|
|
|
|
|
|
|
list_add_item(chansrv_params, (intptr_t) g_strdup(exe_path));
|
|
|
|
list_add_item(chansrv_params, 0); /* mandatory */
|
|
|
|
|
|
|
|
env_set_user(username, 0, display,
|
2017-12-15 11:56:45 +03:00
|
|
|
g_cfg->env_names,
|
|
|
|
g_cfg->env_values);
|
2017-03-19 00:45:58 +03:00
|
|
|
|
2019-03-08 10:42:18 +03:00
|
|
|
if (g_cfg->sec.restrict_outbound_clipboard == 1)
|
|
|
|
{
|
2019-03-02 17:36:56 +03:00
|
|
|
g_setenv("CHANSRV_RESTRICT_OUTBOUND_CLIPBOARD", "1", 1);
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:45:58 +03:00
|
|
|
/* executing chansrv */
|
|
|
|
g_execvp(exe_path, (char **) (chansrv_params->items));
|
|
|
|
/* should not get here */
|
|
|
|
log_message(LOG_LEVEL_ALWAYS, "error starting chansrv "
|
|
|
|
"- user %s - pid %d", username, g_getpid());
|
|
|
|
list_delete(chansrv_params);
|
|
|
|
g_exit(1);
|
|
|
|
}
|
|
|
|
return chansrv_pid;
|
|
|
|
}
|
|
|
|
|
2005-10-06 23:27:38 +04:00
|
|
|
/******************************************************************************/
|
2009-01-12 09:43:58 +03:00
|
|
|
/* called with the main thread */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2017-03-19 00:45:58 +03:00
|
|
|
session_start_fork(tbus data, tui8 type, struct SCP_CONNECTION *c,
|
|
|
|
struct SCP_SESSION *s)
|
2005-10-06 23:27:38 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int display = 0;
|
|
|
|
int pid = 0;
|
|
|
|
int i = 0;
|
|
|
|
char geometry[32];
|
|
|
|
char depth[32];
|
2016-04-07 11:34:04 +03:00
|
|
|
char screen[32]; /* display number */
|
2012-09-20 07:51:34 +04:00
|
|
|
char text[256];
|
2016-07-22 11:48:37 +03:00
|
|
|
char execvpparams[2048];
|
|
|
|
char *xserver; /* absolute/relative path to Xorg/X11rdp/Xvnc */
|
|
|
|
char *passwd_file;
|
2012-09-20 07:51:34 +04:00
|
|
|
char **pp1 = (char **)NULL;
|
|
|
|
struct session_chain *temp = (struct session_chain *)NULL;
|
|
|
|
struct list *xserver_params = (struct list *)NULL;
|
|
|
|
struct tm stime;
|
2016-07-22 11:48:37 +03:00
|
|
|
time_t ltime;
|
2016-12-14 09:16:06 +03:00
|
|
|
char authfile[256]; /* The filename for storing xauth informations */
|
2017-03-19 00:45:58 +03:00
|
|
|
int chansrv_pid;
|
|
|
|
int display_pid;
|
|
|
|
int window_manager_pid;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* initialize (zero out) local variables: */
|
|
|
|
g_memset(<ime, 0, sizeof(time_t));
|
|
|
|
g_memset(&stime, 0, sizeof(struct tm));
|
|
|
|
g_memset(geometry, 0, sizeof(char) * 32);
|
|
|
|
g_memset(depth, 0, sizeof(char) * 32);
|
|
|
|
g_memset(screen, 0, sizeof(char) * 32);
|
|
|
|
g_memset(text, 0, sizeof(char) * 256);
|
2016-07-22 11:48:37 +03:00
|
|
|
|
|
|
|
passwd_file = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* check to limit concurrent sessions */
|
|
|
|
if (g_session_count >= g_cfg->sess.max_sessions)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_INFO, "max concurrent session limit "
|
2016-12-04 10:12:48 +03:00
|
|
|
"exceeded. login for user %s denied", s->username);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2006-02-05 08:46:48 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
temp = (struct session_chain *)g_malloc(sizeof(struct session_chain), 0);
|
|
|
|
|
|
|
|
if (temp == 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR, "cannot create new chain "
|
2016-12-04 10:12:48 +03:00
|
|
|
"element - user %s", s->username);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp->item = (struct session_item *)g_malloc(sizeof(struct session_item), 0);
|
|
|
|
|
|
|
|
if (temp->item == 0)
|
|
|
|
{
|
|
|
|
g_free(temp);
|
|
|
|
log_message(LOG_LEVEL_ERROR, "cannot create new session "
|
2016-12-04 10:12:48 +03:00
|
|
|
"item - user %s", s->username);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-14 07:41:07 +03:00
|
|
|
display = session_get_avail_display_from_chain();
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (display == 0)
|
|
|
|
{
|
|
|
|
g_free(temp->item);
|
|
|
|
g_free(temp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-14 07:41:07 +03:00
|
|
|
pid = g_fork(); /* parent is fork from tcp accept,
|
2015-12-12 07:41:17 +03:00
|
|
|
child forks X and wm, then becomes scp */
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (pid == -1)
|
|
|
|
{
|
|
|
|
}
|
2015-12-12 07:41:17 +03:00
|
|
|
else if (pid == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2017-07-10 01:23:13 +03:00
|
|
|
log_message(LOG_LEVEL_INFO, "calling auth_start_session from pid %d",
|
|
|
|
g_getpid());
|
|
|
|
auth_start_session(data, display);
|
2016-08-31 21:15:24 +03:00
|
|
|
g_delete_wait_obj(g_term_event);
|
2013-05-28 22:54:44 +04:00
|
|
|
g_tcp_close(g_sck);
|
2017-03-19 00:45:58 +03:00
|
|
|
g_tcp_close(c->in_sck);
|
2016-12-04 10:12:48 +03:00
|
|
|
g_sprintf(geometry, "%dx%d", s->width, s->height);
|
|
|
|
g_sprintf(depth, "%d", s->bpp);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_sprintf(screen, ":%d", display);
|
2017-01-27 04:02:41 +03:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2014-03-12 12:13:51 +04:00
|
|
|
/*
|
|
|
|
* FreeBSD bug
|
|
|
|
* ports/157282: effective login name is not set by xrdp-sesman
|
|
|
|
* http://www.freebsd.org/cgi/query-pr.cgi?pr=157282
|
|
|
|
*
|
|
|
|
* from:
|
|
|
|
* $OpenBSD: session.c,v 1.252 2010/03/07 11:57:13 dtucker Exp $
|
|
|
|
* with some ideas about BSD process grouping to xrdp
|
|
|
|
*/
|
2018-02-05 11:38:20 +03:00
|
|
|
pid_t bsdsespid = g_fork();
|
2014-03-12 12:13:51 +04:00
|
|
|
|
2018-02-05 11:38:20 +03:00
|
|
|
if (bsdsespid == -1)
|
2014-03-12 12:13:51 +04:00
|
|
|
{
|
|
|
|
}
|
2018-02-05 11:38:20 +03:00
|
|
|
else if (bsdsespid == 0) /* BSD session leader */
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new session and process group since the 4.4BSD
|
|
|
|
* setlogin() affects the entire process group
|
|
|
|
*/
|
|
|
|
if (g_setsid() < 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,
|
|
|
|
"setsid failed - pid %d", g_getpid());
|
|
|
|
}
|
2014-03-12 12:13:51 +04:00
|
|
|
|
2018-02-05 11:38:20 +03:00
|
|
|
if (g_setlogin(s->username) < 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,
|
|
|
|
"setlogin failed for user %s - pid %d", s->username,
|
|
|
|
g_getpid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_waitpid(bsdsespid);
|
|
|
|
|
|
|
|
if (bsdsespid > 0)
|
2017-01-28 15:14:55 +03:00
|
|
|
{
|
2018-02-05 11:38:20 +03:00
|
|
|
g_exit(0);
|
|
|
|
/*
|
|
|
|
* intermediate sesman should exit here after WM exits.
|
|
|
|
* do not execure the following codes.
|
|
|
|
*/
|
2014-03-12 12:13:51 +04:00
|
|
|
}
|
|
|
|
#endif
|
2017-03-19 00:45:58 +03:00
|
|
|
window_manager_pid = g_fork(); /* parent becomes X,
|
2015-12-12 07:41:17 +03:00
|
|
|
child forks wm, and waits, todo */
|
2017-03-19 00:45:58 +03:00
|
|
|
if (window_manager_pid == -1)
|
2006-02-05 08:46:48 +03:00
|
|
|
{
|
|
|
|
}
|
2017-03-19 00:45:58 +03:00
|
|
|
else if (window_manager_pid == 0)
|
2006-02-05 08:46:48 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
wait_for_xserver(display);
|
2017-03-19 00:45:58 +03:00
|
|
|
env_set_user(s->username,
|
|
|
|
0,
|
|
|
|
display,
|
2017-12-15 11:56:45 +03:00
|
|
|
g_cfg->env_names,
|
|
|
|
g_cfg->env_values);
|
2017-03-19 00:45:58 +03:00
|
|
|
if (x_server_running(display))
|
2013-10-01 21:42:00 +04:00
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
auth_set_env(data);
|
|
|
|
if (s->directory != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
if (s->directory[0] != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
g_set_current_dir(s->directory);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2017-03-19 00:45:58 +03:00
|
|
|
}
|
|
|
|
if (s->program != 0)
|
|
|
|
{
|
|
|
|
if (s->program[0] != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
g_execlp3(s->program, s->program, 0);
|
|
|
|
log_message(LOG_LEVEL_ALWAYS,
|
|
|
|
"error starting program %s for user %s - pid %d",
|
|
|
|
s->program, s->username, g_getpid());
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2013-10-01 21:42:00 +04:00
|
|
|
}
|
2017-03-19 00:45:58 +03:00
|
|
|
/* try to execute user window manager if enabled */
|
|
|
|
if (g_cfg->enable_user_wm)
|
2013-10-01 21:42:00 +04:00
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
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", s->username, g_getpid());
|
|
|
|
/* logging parameters */
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "errno: %d, "
|
|
|
|
"description: %s", g_get_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);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2017-03-19 00:45:58 +03:00
|
|
|
/* if we're here something happened to g_execlp3
|
|
|
|
so we try running the default window manager */
|
2018-06-14 05:59:27 +03:00
|
|
|
g_execlp3(g_cfg->default_wm, g_cfg->default_wm, 0);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2017-03-19 00:45:58 +03:00
|
|
|
log_message(LOG_LEVEL_ALWAYS, "error starting default "
|
|
|
|
"wm for user %s - pid %d", s->username, g_getpid());
|
|
|
|
/* logging parameters */
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
|
|
|
|
"%s", g_get_errno(), g_get_strerror());
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:");
|
|
|
|
log_message(LOG_LEVEL_DEBUG, " argv[0] = %s",
|
2018-06-15 07:46:23 +03:00
|
|
|
g_cfg->default_wm);
|
2017-03-19 00:45:58 +03:00
|
|
|
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", s->username, g_getpid());
|
|
|
|
/* logging parameters */
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
|
|
|
|
"%s", g_get_errno(), g_get_strerror());
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
log_message(LOG_LEVEL_ERROR, "another Xserver might "
|
|
|
|
"already be active on display %d - see log", display);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2017-03-19 00:45:58 +03:00
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "aborting connection...");
|
|
|
|
g_exit(0);
|
2006-02-05 08:46:48 +03:00
|
|
|
}
|
2015-12-12 07:41:17 +03:00
|
|
|
else
|
2006-02-09 21:01:41 +03:00
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
display_pid = g_fork(); /* parent becomes scp,
|
2015-12-12 07:41:17 +03:00
|
|
|
child becomes X */
|
2017-03-19 00:45:58 +03:00
|
|
|
if (display_pid == -1)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
}
|
2017-03-19 00:45:58 +03:00
|
|
|
else if (display_pid == 0) /* child */
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2014-11-12 07:06:04 +03:00
|
|
|
if (type == SESMAN_SESSION_TYPE_XVNC)
|
|
|
|
{
|
2016-12-04 10:12:48 +03:00
|
|
|
env_set_user(s->username,
|
2016-07-22 11:48:37 +03:00
|
|
|
&passwd_file,
|
|
|
|
display,
|
2017-12-15 11:56:45 +03:00
|
|
|
g_cfg->env_names,
|
|
|
|
g_cfg->env_values);
|
2014-11-12 07:06:04 +03:00
|
|
|
}
|
2016-07-22 11:48:37 +03:00
|
|
|
else
|
|
|
|
{
|
2016-12-04 10:12:48 +03:00
|
|
|
env_set_user(s->username,
|
2016-07-22 11:48:37 +03:00
|
|
|
0,
|
|
|
|
display,
|
2017-12-15 11:56:45 +03:00
|
|
|
g_cfg->env_names,
|
|
|
|
g_cfg->env_values);
|
2016-07-22 11:48:37 +03:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2013-08-25 04:57:00 +04:00
|
|
|
g_snprintf(text, 255, "%d", g_cfg->sess.max_idle_time);
|
|
|
|
g_setenv("XRDP_SESMAN_MAX_IDLE_TIME", text, 1);
|
|
|
|
g_snprintf(text, 255, "%d", g_cfg->sess.max_disc_time);
|
|
|
|
g_setenv("XRDP_SESMAN_MAX_DISC_TIME", text, 1);
|
|
|
|
g_snprintf(text, 255, "%d", g_cfg->sess.kill_disconnected);
|
|
|
|
g_setenv("XRDP_SESMAN_KILL_DISCONNECTED", text, 1);
|
2017-03-15 07:45:50 +03:00
|
|
|
g_setenv("XRDP_SOCKET_PATH", XRDP_SOCKET_PATH, 1);
|
2013-08-25 04:57:00 +04:00
|
|
|
|
2016-12-14 02:29:22 +03:00
|
|
|
/* prepare the Xauthority stuff */
|
2016-12-14 10:28:25 +03:00
|
|
|
if (g_getenv("XAUTHORITY") != NULL)
|
2016-12-14 02:29:22 +03:00
|
|
|
{
|
|
|
|
g_snprintf(authfile, 255, "%s", g_getenv("XAUTHORITY"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-15 20:06:35 +03:00
|
|
|
g_snprintf(authfile, 255, "%s", ".Xauthority");
|
2016-12-14 02:29:22 +03:00
|
|
|
}
|
|
|
|
|
2016-12-16 00:45:12 +03:00
|
|
|
/* Add the entry in XAUTHORITY file or exit if error */
|
|
|
|
if (add_xauth_cookie(display, authfile) != 0)
|
|
|
|
{
|
|
|
|
g_exit(1);
|
|
|
|
}
|
2016-12-13 15:24:15 +03:00
|
|
|
|
2014-04-20 11:42:19 +04:00
|
|
|
if (type == SESMAN_SESSION_TYPE_XORG)
|
|
|
|
{
|
2016-11-29 11:42:48 +03:00
|
|
|
#ifdef HAVE_SYS_PRCTL_H
|
|
|
|
/*
|
|
|
|
* Make sure Xorg doesn't run setuid root. Root access is not
|
|
|
|
* needed. Xorg can fail when run as root and the user has no
|
|
|
|
* console permissions.
|
|
|
|
* PR_SET_NO_NEW_PRIVS requires Linux kernel 3.5 and newer.
|
|
|
|
*/
|
|
|
|
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_WARNING,
|
|
|
|
"Failed to disable setuid on X server: %s",
|
|
|
|
g_get_strerror());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-09 04:41:37 +04:00
|
|
|
xserver_params = list_create();
|
|
|
|
xserver_params->auto_free = 1;
|
2014-04-20 11:42:19 +04:00
|
|
|
|
2016-04-22 09:03:40 +03:00
|
|
|
/* get path of Xorg from config */
|
|
|
|
xserver = g_strdup((const char *)list_get_item(g_cfg->xorg_params, 0));
|
2016-04-07 11:34:04 +03:00
|
|
|
|
2014-03-09 04:41:37 +04:00
|
|
|
/* these are the must have parameters */
|
2016-04-07 11:34:04 +03:00
|
|
|
list_add_item(xserver_params, (tintptr) g_strdup(xserver));
|
2015-12-12 07:41:17 +03:00
|
|
|
list_add_item(xserver_params, (tintptr) g_strdup(screen));
|
2016-12-13 15:24:15 +03:00
|
|
|
list_add_item(xserver_params, (tintptr) g_strdup("-auth"));
|
|
|
|
list_add_item(xserver_params, (tintptr) g_strdup(authfile));
|
2014-03-09 04:41:37 +04:00
|
|
|
|
|
|
|
/* additional parameters from sesman.ini file */
|
2016-10-17 09:41:05 +03:00
|
|
|
list_append_list_strdup(g_cfg->xorg_params, xserver_params, 1);
|
2014-03-09 04:41:37 +04:00
|
|
|
|
|
|
|
/* 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 */
|
2016-12-04 10:12:48 +03:00
|
|
|
g_sprintf(geometry, "%d", s->width);
|
2014-03-09 04:41:37 +04:00
|
|
|
g_setenv("XRDP_START_WIDTH", geometry, 1);
|
2014-04-20 11:42:19 +04:00
|
|
|
|
2016-12-04 10:12:48 +03:00
|
|
|
g_sprintf(geometry, "%d", s->height);
|
2014-03-09 04:41:37 +04:00
|
|
|
g_setenv("XRDP_START_HEIGHT", geometry, 1);
|
2014-04-20 11:42:19 +04:00
|
|
|
|
|
|
|
/* fire up Xorg */
|
2016-04-07 11:34:04 +03:00
|
|
|
g_execvp(xserver, pp1);
|
2014-04-20 11:42:19 +04:00
|
|
|
}
|
2014-03-09 04:41:37 +04:00
|
|
|
else if (type == SESMAN_SESSION_TYPE_XVNC)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2016-12-05 02:39:10 +03:00
|
|
|
char guid_str[64];
|
|
|
|
g_bytes_to_hexstr(s->guid, 16, guid_str, 64);
|
|
|
|
env_check_password_file(passwd_file, guid_str);
|
2012-09-20 07:51:34 +04:00
|
|
|
xserver_params = list_create();
|
|
|
|
xserver_params->auto_free = 1;
|
2014-04-20 11:42:19 +04:00
|
|
|
|
2016-04-22 09:03:40 +03:00
|
|
|
/* get path of Xvnc from config */
|
|
|
|
xserver = g_strdup((const char *)list_get_item(g_cfg->vnc_params, 0));
|
2016-04-07 11:34:04 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* these are the must have parameters */
|
2016-04-07 11:34:04 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(xserver));
|
2015-12-12 07:41:17 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(screen));
|
2016-12-13 15:24:15 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup("-auth"));
|
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(authfile));
|
2015-12-12 07:41:17 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup("-geometry"));
|
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(geometry));
|
|
|
|
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("-rfbauth"));
|
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(passwd_file));
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2016-07-22 11:48:37 +03:00
|
|
|
g_free(passwd_file);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* additional parameters from sesman.ini file */
|
|
|
|
//config_read_xserver_params(SESMAN_SESSION_TYPE_XVNC,
|
|
|
|
// xserver_params);
|
2016-10-17 09:41:05 +03:00
|
|
|
list_append_list_strdup(g_cfg->vnc_params, xserver_params, 1);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* make sure it ends with a zero */
|
|
|
|
list_add_item(xserver_params, 0);
|
|
|
|
pp1 = (char **)xserver_params->items;
|
2014-03-09 04:41:37 +04:00
|
|
|
log_message(LOG_LEVEL_INFO, "%s", dumpItemsToString(xserver_params, execvpparams, 2048));
|
2016-04-07 11:34:04 +03:00
|
|
|
g_execvp(xserver, pp1);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (type == SESMAN_SESSION_TYPE_XRDP)
|
|
|
|
{
|
|
|
|
xserver_params = list_create();
|
|
|
|
xserver_params->auto_free = 1;
|
2014-04-20 11:42:19 +04:00
|
|
|
|
2016-04-22 09:03:40 +03:00
|
|
|
/* get path of X11rdp from config */
|
|
|
|
xserver = g_strdup((const char *)list_get_item(g_cfg->rdp_params, 0));
|
2016-04-07 11:34:04 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* these are the must have parameters */
|
2016-04-07 11:34:04 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(xserver));
|
2015-12-12 07:41:17 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(screen));
|
2016-12-13 15:24:15 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup("-auth"));
|
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(authfile));
|
2015-12-12 07:41:17 +03:00
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup("-geometry"));
|
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(geometry));
|
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup("-depth"));
|
|
|
|
list_add_item(xserver_params, (tintptr)g_strdup(depth));
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* additional parameters from sesman.ini file */
|
|
|
|
//config_read_xserver_params(SESMAN_SESSION_TYPE_XRDP,
|
|
|
|
// xserver_params);
|
2016-10-17 09:41:05 +03:00
|
|
|
list_append_list_strdup(g_cfg->rdp_params, xserver_params, 1);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* make sure it ends with a zero */
|
|
|
|
list_add_item(xserver_params, 0);
|
|
|
|
pp1 = (char **)xserver_params->items;
|
2014-03-09 04:41:37 +04:00
|
|
|
log_message(LOG_LEVEL_INFO, "%s", dumpItemsToString(xserver_params, execvpparams, 2048));
|
2016-04-07 11:34:04 +03:00
|
|
|
g_execvp(xserver, pp1);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ALWAYS, "bad session type - "
|
2016-12-04 10:12:48 +03:00
|
|
|
"user %s - pid %d", s->username, g_getpid());
|
2012-09-20 07:51:34 +04:00
|
|
|
g_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* should not get here */
|
|
|
|
log_message(LOG_LEVEL_ALWAYS, "error starting X server "
|
2016-12-04 10:12:48 +03:00
|
|
|
"- user %s - pid %d", s->username, g_getpid());
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* logging parameters */
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
|
2015-12-12 07:41:17 +03:00
|
|
|
"%s", g_get_errno(), g_get_strerror());
|
2012-09-20 07:51:34 +04:00
|
|
|
log_message(LOG_LEVEL_DEBUG, "execve parameter list size: "
|
|
|
|
"%d", (xserver_params)->count);
|
|
|
|
|
|
|
|
for (i = 0; i < (xserver_params->count); i++)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s",
|
|
|
|
i, (char *)list_get_item(xserver_params, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
list_delete(xserver_params);
|
|
|
|
g_exit(1);
|
|
|
|
}
|
2015-12-12 07:41:17 +03:00
|
|
|
else
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
wait_for_xserver(display);
|
2017-03-19 00:45:58 +03:00
|
|
|
chansrv_pid = session_start_chansrv(s->username, display);
|
|
|
|
log_message(LOG_LEVEL_ALWAYS, "waiting for window manager "
|
|
|
|
"(pid %d) to exit", window_manager_pid);
|
|
|
|
g_waitpid(window_manager_pid);
|
|
|
|
log_message(LOG_LEVEL_ALWAYS, "window manager (pid %d) did "
|
|
|
|
"exit, cleaning up session", window_manager_pid);
|
2017-07-10 01:23:13 +03:00
|
|
|
log_message(LOG_LEVEL_INFO, "calling auth_stop_session and "
|
|
|
|
"auth_end from pid %d", g_getpid());
|
|
|
|
auth_stop_session(data);
|
|
|
|
auth_end(data);
|
2017-03-19 00:45:58 +03:00
|
|
|
g_sigterm(display_pid);
|
|
|
|
g_sigterm(chansrv_pid);
|
2017-07-12 11:48:00 +03:00
|
|
|
cleanup_sockets(display);
|
2017-03-19 00:45:58 +03:00
|
|
|
g_deinit();
|
|
|
|
g_exit(0);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2006-02-09 21:01:41 +03:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2015-12-12 07:41:17 +03:00
|
|
|
else
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
temp->item->pid = pid;
|
|
|
|
temp->item->display = display;
|
2016-12-04 10:12:48 +03:00
|
|
|
temp->item->width = s->width;
|
|
|
|
temp->item->height = s->height;
|
|
|
|
temp->item->bpp = s->bpp;
|
2012-09-20 07:51:34 +04:00
|
|
|
temp->item->data = data;
|
2016-12-04 10:12:48 +03:00
|
|
|
g_strncpy(temp->item->client_ip, s->client_ip, 255); /* store client ip data */
|
|
|
|
g_strncpy(temp->item->name, s->username, 255);
|
2016-12-05 04:20:01 +03:00
|
|
|
g_memcpy(temp->item->guid, s->guid, 16);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
ltime = g_time1();
|
|
|
|
localtime_r(<ime, &stime);
|
|
|
|
temp->item->connect_time.year = (tui16)(stime.tm_year + 1900);
|
2016-02-14 05:19:38 +03:00
|
|
|
temp->item->connect_time.month = (tui8)(stime.tm_mon + 1);
|
2012-09-20 07:51:34 +04:00
|
|
|
temp->item->connect_time.day = (tui8)stime.tm_mday;
|
|
|
|
temp->item->connect_time.hour = (tui8)stime.tm_hour;
|
|
|
|
temp->item->connect_time.minute = (tui8)stime.tm_min;
|
|
|
|
zero_time(&(temp->item->disconnect_time));
|
|
|
|
zero_time(&(temp->item->idle_time));
|
|
|
|
|
|
|
|
temp->item->type = type;
|
|
|
|
temp->item->status = SESMAN_SESSION_STATUS_ACTIVE;
|
|
|
|
|
|
|
|
temp->next = g_sessions;
|
|
|
|
g_sessions = temp;
|
|
|
|
g_session_count++;
|
2013-12-16 16:52:50 +04:00
|
|
|
|
2014-07-19 22:56:00 +04:00
|
|
|
return display;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2007-04-16 00:40:12 +04:00
|
|
|
|
2014-07-19 22:56:00 +04:00
|
|
|
g_free(temp->item);
|
|
|
|
g_free(temp);
|
2012-09-20 07:51:34 +04:00
|
|
|
return display;
|
2009-01-12 09:43:58 +03:00
|
|
|
}
|
|
|
|
|
2012-07-17 00:20:26 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
/* called with the main thread */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2018-05-31 12:30:11 +03:00
|
|
|
session_reconnect_fork(int display, char *username, long data)
|
2012-07-17 00:20:26 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int pid;
|
|
|
|
|
|
|
|
pid = g_fork();
|
|
|
|
|
|
|
|
if (pid == -1)
|
2012-07-17 00:20:26 +04:00
|
|
|
{
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (pid == 0)
|
|
|
|
{
|
2016-07-22 11:48:37 +03:00
|
|
|
env_set_user(username,
|
|
|
|
0,
|
|
|
|
display,
|
2017-12-15 11:56:45 +03:00
|
|
|
g_cfg->env_names,
|
|
|
|
g_cfg->env_values);
|
2018-05-31 12:30:11 +03:00
|
|
|
auth_set_env(data);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2018-06-14 09:31:12 +03:00
|
|
|
if (g_file_exist(g_cfg->reconnect_sh))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-06-14 09:31:12 +03:00
|
|
|
g_execlp3(g_cfg->reconnect_sh, g_cfg->reconnect_sh, 0);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return display;
|
2012-07-17 00:20:26 +04:00
|
|
|
}
|
|
|
|
|
2009-01-12 09:43:58 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
/* called by a worker thread, ask the main thread to call session_sync_start
|
|
|
|
and wait till done */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2017-03-19 00:45:58 +03:00
|
|
|
session_start(long data, tui8 type, struct SCP_CONNECTION *c,
|
|
|
|
struct SCP_SESSION *s)
|
2009-01-12 09:43:58 +03:00
|
|
|
{
|
2017-03-19 00:45:58 +03:00
|
|
|
return session_start_fork(data, type, c, s);
|
2005-10-06 23:27:38 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 00:20:26 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
/* called by a worker thread, ask the main thread to call session_sync_start
|
|
|
|
and wait till done */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2018-05-31 12:30:11 +03:00
|
|
|
session_reconnect(int display, char *username, long data)
|
2012-07-17 00:20:26 +04:00
|
|
|
{
|
2018-05-31 12:30:11 +03:00
|
|
|
return session_reconnect_fork(display, username, data);
|
2009-01-12 09:43:58 +03:00
|
|
|
}
|
|
|
|
|
2006-01-13 18:51:23 +03:00
|
|
|
/******************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2006-01-13 18:51:23 +03:00
|
|
|
session_kill(int pid)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct session_chain *tmp;
|
|
|
|
struct session_chain *prev;
|
|
|
|
|
|
|
|
tmp = g_sessions;
|
|
|
|
prev = 0;
|
|
|
|
|
|
|
|
while (tmp != 0)
|
|
|
|
{
|
|
|
|
if (tmp->item == 0)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
g_sessions = tmp->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev->next = tmp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SESMAN_SESSION_KILL_NULLITEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp->item->pid == pid)
|
|
|
|
{
|
|
|
|
/* deleting the session */
|
|
|
|
log_message(LOG_LEVEL_INFO, "++ terminated session: username %s, display :%d.0, session_pid %d, ip %s", tmp->item->name, tmp->item->display, tmp->item->pid, tmp->item->client_ip);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev->next = tmp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(tmp);
|
|
|
|
g_session_count--;
|
|
|
|
return SESMAN_SESSION_KILL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go on */
|
|
|
|
prev = tmp;
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SESMAN_SESSION_KILL_NOTFOUND;
|
2006-01-13 18:51:23 +03:00
|
|
|
}
|
|
|
|
|
2007-04-07 20:20:08 +04:00
|
|
|
/******************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2016-12-23 20:52:22 +03:00
|
|
|
session_sigkill_all(void)
|
2007-04-07 20:20:08 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct session_chain *tmp;
|
2007-04-07 20:20:08 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
tmp = g_sessions;
|
2007-04-07 20:20:08 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
while (tmp != 0)
|
2007-04-07 20:20:08 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (tmp->item == 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR, "found null session "
|
|
|
|
"descriptor!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_sigterm(tmp->item->pid);
|
|
|
|
}
|
2007-04-07 20:20:08 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* go on */
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
2007-04-07 20:20:08 +04:00
|
|
|
}
|
|
|
|
|
2006-01-13 18:51:23 +03:00
|
|
|
/******************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
struct session_item *
|
2006-01-13 18:51:23 +03:00
|
|
|
session_get_bypid(int pid)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct session_chain *tmp;
|
|
|
|
struct session_item *dummy;
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2016-06-22 02:30:18 +03:00
|
|
|
dummy = g_new0(struct session_item, 1);
|
2006-07-14 00:15:21 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == dummy)
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
2016-06-22 02:30:16 +03:00
|
|
|
log_message(LOG_LEVEL_ERROR, "session_get_bypid: out of memory");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2006-01-13 18:51:23 +03:00
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
tmp = g_sessions;
|
|
|
|
|
|
|
|
while (tmp != 0)
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (tmp->item == 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR, "session descriptor for "
|
|
|
|
"pid %d is null!", pid);
|
2014-07-19 22:56:00 +04:00
|
|
|
g_free(dummy);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp->item->pid == pid)
|
|
|
|
{
|
|
|
|
g_memcpy(dummy, tmp->item, sizeof(struct session_item));
|
|
|
|
return dummy;
|
|
|
|
}
|
2006-01-13 18:51:23 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* go on */
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2014-07-19 22:56:00 +04:00
|
|
|
g_free(dummy);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2006-01-13 18:51:23 +03:00
|
|
|
}
|
|
|
|
|
2006-11-05 16:11:20 +03:00
|
|
|
/******************************************************************************/
|
2012-09-20 07:51:34 +04:00
|
|
|
struct SCP_DISCONNECTED_SESSION *
|
2016-10-17 09:14:06 +03:00
|
|
|
session_get_byuser(const char *user, int *cnt, unsigned char flags)
|
2006-11-05 16:11:20 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct session_chain *tmp;
|
|
|
|
struct SCP_DISCONNECTED_SESSION *sess;
|
|
|
|
int count;
|
|
|
|
int index;
|
2006-11-05 16:11:20 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
tmp = g_sessions;
|
2006-11-05 16:11:20 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
while (tmp != 0)
|
|
|
|
{
|
|
|
|
LOG_DBG("user: %s", user);
|
|
|
|
|
|
|
|
if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256)))
|
|
|
|
{
|
|
|
|
LOG_DBG("session_get_byuser: status=%d, flags=%d, "
|
|
|
|
"result=%d", (tmp->item->status), flags,
|
|
|
|
((tmp->item->status) & flags));
|
|
|
|
|
|
|
|
if ((tmp->item->status) & flags)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go on */
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
(*cnt) = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* malloc() an array of disconnected sessions */
|
2016-06-22 02:30:18 +03:00
|
|
|
sess = g_new0(struct SCP_DISCONNECTED_SESSION, count);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (sess == 0)
|
|
|
|
{
|
|
|
|
(*cnt) = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = g_sessions;
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
while (tmp != 0)
|
|
|
|
{
|
2015-12-12 07:41:17 +03:00
|
|
|
/* #warning FIXME: we should get only disconnected sessions! */
|
2012-09-20 07:51:34 +04:00
|
|
|
if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256)))
|
|
|
|
{
|
|
|
|
if ((tmp->item->status) & flags)
|
|
|
|
{
|
|
|
|
(sess[index]).SID = tmp->item->pid;
|
|
|
|
(sess[index]).type = tmp->item->type;
|
|
|
|
(sess[index]).height = tmp->item->height;
|
|
|
|
(sess[index]).width = tmp->item->width;
|
|
|
|
(sess[index]).bpp = tmp->item->bpp;
|
2015-12-12 07:41:17 +03:00
|
|
|
/* #warning FIXME: setting idle times and such */
|
2012-09-20 07:51:34 +04:00
|
|
|
/*(sess[index]).connect_time.year = tmp->item->connect_time.year;
|
|
|
|
(sess[index]).connect_time.month = tmp->item->connect_time.month;
|
|
|
|
(sess[index]).connect_time.day = tmp->item->connect_time.day;
|
|
|
|
(sess[index]).connect_time.hour = tmp->item->connect_time.hour;
|
|
|
|
(sess[index]).connect_time.minute = tmp->item->connect_time.minute;
|
|
|
|
(sess[index]).disconnect_time.year = tmp->item->disconnect_time.year;
|
|
|
|
(sess[index]).disconnect_time.month = tmp->item->disconnect_time.month;
|
|
|
|
(sess[index]).disconnect_time.day = tmp->item->disconnect_time.day;
|
|
|
|
(sess[index]).disconnect_time.hour = tmp->item->disconnect_time.hour;
|
|
|
|
(sess[index]).disconnect_time.minute = tmp->item->disconnect_time.minute;
|
|
|
|
(sess[index]).idle_time.year = tmp->item->idle_time.year;
|
|
|
|
(sess[index]).idle_time.month = tmp->item->idle_time.month;
|
|
|
|
(sess[index]).idle_time.day = tmp->item->idle_time.day;
|
|
|
|
(sess[index]).idle_time.hour = tmp->item->idle_time.hour;
|
|
|
|
(sess[index]).idle_time.minute = tmp->item->idle_time.minute;*/
|
|
|
|
(sess[index]).conn_year = tmp->item->connect_time.year;
|
|
|
|
(sess[index]).conn_month = tmp->item->connect_time.month;
|
|
|
|
(sess[index]).conn_day = tmp->item->connect_time.day;
|
|
|
|
(sess[index]).conn_hour = tmp->item->connect_time.hour;
|
|
|
|
(sess[index]).conn_minute = tmp->item->connect_time.minute;
|
|
|
|
(sess[index]).idle_days = tmp->item->idle_time.day;
|
|
|
|
(sess[index]).idle_hours = tmp->item->idle_time.hour;
|
|
|
|
(sess[index]).idle_minutes = tmp->item->idle_time.minute;
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go on */
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*cnt) = count;
|
|
|
|
return sess;
|
2006-11-05 16:11:20 +03:00
|
|
|
}
|
2017-07-12 11:48:00 +03:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
int
|
|
|
|
cleanup_sockets(int display)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "cleanup_sockets:");
|
|
|
|
char file[256];
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
g_snprintf(file, 255, CHANSRV_PORT_OUT_STR, display);
|
|
|
|
if (g_file_exist(file))
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "cleanup_sockets: deleting %s", file);
|
|
|
|
if (g_file_delete(file) == 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,
|
|
|
|
"cleanup_sockets: failed to delete %s", file);
|
|
|
|
error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_snprintf(file, 255, CHANSRV_PORT_IN_STR, display);
|
|
|
|
if (g_file_exist(file))
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "cleanup_sockets: deleting %s", file);
|
|
|
|
if (g_file_delete(file) == 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,
|
|
|
|
"cleanup_sockets: failed to delete %s", file);
|
|
|
|
error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_snprintf(file, 255, XRDP_CHANSRV_STR, display);
|
|
|
|
if (g_file_exist(file))
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "cleanup_sockets: deleting %s", file);
|
|
|
|
if (g_file_delete(file) == 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,
|
|
|
|
"cleanup_sockets: failed to delete %s", file);
|
|
|
|
error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_snprintf(file, 255, CHANSRV_API_STR, display);
|
|
|
|
if (g_file_exist(file))
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG, "cleanup_sockets: deleting %s", file);
|
|
|
|
if (g_file_delete(file) == 0)
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,
|
|
|
|
"cleanup_sockets: failed to delete %s", file);
|
|
|
|
error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
}
|