Rename the pre-session list to the SCP list
The name pre-session list makes no sense now, as we need items to remain on the list after starting the session and before connecting.
This commit is contained in:
+2
-2
@@ -21,8 +21,8 @@ xrdp_sesman_SOURCES = \
|
||||
ercp_process.h \
|
||||
lock_uds.c \
|
||||
lock_uds.h \
|
||||
pre_session_list.c \
|
||||
pre_session_list.h \
|
||||
scp_list.c \
|
||||
scp_list.h \
|
||||
scp_process.c \
|
||||
scp_process.h \
|
||||
sesman.c \
|
||||
|
||||
+18
-18
@@ -33,7 +33,7 @@
|
||||
#include "eicp.h"
|
||||
#include "eicp_process.h"
|
||||
#include "os_calls.h"
|
||||
#include "pre_session_list.h"
|
||||
#include "scp_list.h"
|
||||
#include "scp.h"
|
||||
#include "sesman.h"
|
||||
#include "sesman_access.h"
|
||||
@@ -42,49 +42,49 @@
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_sys_login_response(struct pre_session_item *psi)
|
||||
process_sys_login_response(struct scp_list_item *sli)
|
||||
{
|
||||
int rv;
|
||||
int is_logged_in;
|
||||
uid_t uid;
|
||||
int scp_fd;
|
||||
|
||||
rv = eicp_get_sys_login_response(psi->sesexec_trans, &is_logged_in,
|
||||
rv = eicp_get_sys_login_response(sli->sesexec_trans, &is_logged_in,
|
||||
&uid, &scp_fd);
|
||||
if (rv == 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO, "Received sys login status for %s : %s",
|
||||
psi->username,
|
||||
sli->username,
|
||||
(is_logged_in) ? "logged in" : "not logged in");
|
||||
|
||||
if (!is_logged_in)
|
||||
{
|
||||
// This shouldn't happen. Close the connection to the
|
||||
// client immediately.
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We've been handed back the client connection */
|
||||
psi->client_trans = scp_init_trans_from_fd(scp_fd,
|
||||
sli->client_trans = scp_init_trans_from_fd(scp_fd,
|
||||
TRANS_TYPE_SERVER,
|
||||
sesman_is_term);
|
||||
if (psi->client_trans == NULL)
|
||||
if (sli->client_trans == NULL)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "Can't re-create client connection");
|
||||
g_file_close(scp_fd);
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
psi->client_trans->trans_data_in = sesman_scp_data_in;
|
||||
psi->client_trans->callback_data = (void *)psi;
|
||||
psi->login_state = E_PS_LOGIN_SYS;
|
||||
psi->uid = uid;
|
||||
sli->client_trans->trans_data_in = sesman_scp_data_in;
|
||||
sli->client_trans->callback_data = (void *)sli;
|
||||
sli->login_state = E_SLI_LOGIN_SYS;
|
||||
sli->uid = uid;
|
||||
// For system logins, don't allow admin access
|
||||
//psi->is_admin = access_login_mng_allowed(&g_cfg->sec,
|
||||
// psi->username);
|
||||
psi->is_admin = 0;
|
||||
//sli->is_admin = access_login_mng_allowed(&g_cfg->sec,
|
||||
// sli->username);
|
||||
sli->is_admin = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,15 +94,15 @@ process_sys_login_response(struct pre_session_item *psi)
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
eicp_process(struct pre_session_item *psi)
|
||||
eicp_process(struct scp_list_item *sli)
|
||||
{
|
||||
enum eicp_msg_code msgno;
|
||||
int rv = 0;
|
||||
|
||||
switch ((msgno = eicp_msg_in_get_msgno(psi->sesexec_trans)))
|
||||
switch ((msgno = eicp_msg_in_get_msgno(sli->sesexec_trans)))
|
||||
{
|
||||
case E_EICP_SYS_LOGIN_RESPONSE:
|
||||
rv = process_sys_login_response(psi);
|
||||
rv = process_sys_login_response(sli);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -27,15 +27,15 @@
|
||||
#ifndef EICP_PROCESS_H
|
||||
#define EICP_PROCESS_H
|
||||
|
||||
struct pre_session_item;
|
||||
struct scp_list_item;
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Processes an EICP message
|
||||
* @param sc the sesman connection
|
||||
* @param sli the sesman connection
|
||||
*
|
||||
*/
|
||||
int
|
||||
eicp_process(struct pre_session_item *psi);
|
||||
eicp_process(struct scp_list_item *sli);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
/**
|
||||
* xrdp: A Remote Desktop Protocol server.
|
||||
*
|
||||
* Copyright (C) Jay Sorg 2004-2015
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @file pre_session_list.h
|
||||
* @brief List of pre-session connections to sesman (definitions)
|
||||
*
|
||||
* @author Matt Burt
|
||||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config_ac.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "arch.h"
|
||||
#include "list.h"
|
||||
#include "os_calls.h"
|
||||
#include "pre_session_list.h"
|
||||
#include "trans.h"
|
||||
|
||||
#define PRE_SESSION_IN_USE(si) \
|
||||
( \
|
||||
(si) != NULL && \
|
||||
( \
|
||||
((si)->client_trans != NULL && (si)->client_trans->status == TRANS_STATUS_UP) || \
|
||||
((si)->sesexec_trans != NULL && (si)->sesexec_trans->status == TRANS_STATUS_UP) \
|
||||
) \
|
||||
)
|
||||
|
||||
static struct list *g_pre_session_list = NULL;
|
||||
|
||||
/**
|
||||
* Deletes a pre_session_item, freeing resources
|
||||
*
|
||||
* After this call, the passed-in pointer is invalid and must not be
|
||||
* referenced.
|
||||
*
|
||||
* Any auth_info struct found in the sesman_con is also deallocated.
|
||||
*
|
||||
* @param sc struct to de-allocate
|
||||
*/
|
||||
static void
|
||||
free_pre_session_item(struct pre_session_item *psi)
|
||||
{
|
||||
if (psi != NULL)
|
||||
{
|
||||
trans_delete(psi->client_trans);
|
||||
trans_delete(psi->sesexec_trans);
|
||||
g_free(psi->username);
|
||||
g_free(psi);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
pre_session_list_init(unsigned int list_size)
|
||||
{
|
||||
int rv = 1;
|
||||
if (g_pre_session_list == NULL)
|
||||
{
|
||||
g_pre_session_list = list_create_sized(list_size);
|
||||
}
|
||||
|
||||
if (g_pre_session_list == NULL)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "Can't allocate pre-session list");
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pre_session_list->auto_free = 0;
|
||||
rv = 0;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void
|
||||
pre_session_list_cleanup(void)
|
||||
{
|
||||
if (g_pre_session_list != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0 ; i < g_pre_session_list->count ; ++i)
|
||||
{
|
||||
struct pre_session_item *p;
|
||||
p = (struct pre_session_item *)list_get_item(g_pre_session_list, i);
|
||||
free_pre_session_item(p);
|
||||
}
|
||||
list_delete(g_pre_session_list);
|
||||
g_pre_session_list = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
unsigned int
|
||||
pre_session_list_get_count(void)
|
||||
{
|
||||
return g_pre_session_list->count;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
struct pre_session_item *
|
||||
pre_session_list_new(void)
|
||||
{
|
||||
struct pre_session_item *result = g_new0(struct pre_session_item, 1);
|
||||
if (result != NULL)
|
||||
{
|
||||
g_snprintf(result->peername, sizeof(result->peername), "unknown");
|
||||
result->uid = (uid_t) -1;
|
||||
|
||||
if (!list_add_item(g_pre_session_list, (tintptr)result))
|
||||
{
|
||||
g_free(result);
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
pre_session_list_set_peername(struct pre_session_item *psi, const char *name)
|
||||
{
|
||||
int rv = 1;
|
||||
|
||||
if (psi != NULL && name != NULL)
|
||||
{
|
||||
g_snprintf(psi->peername, sizeof(psi->peername), "%s", name);
|
||||
rv = 0;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
pre_session_list_get_wait_objs(tbus robjs[], int *robjs_count)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < g_pre_session_list->count)
|
||||
{
|
||||
struct pre_session_item *psi;
|
||||
psi = (struct pre_session_item *)list_get_item(g_pre_session_list, i);
|
||||
int psi_in_use = 0;
|
||||
|
||||
if (psi != NULL)
|
||||
{
|
||||
if (psi->client_trans != NULL &&
|
||||
psi->client_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
robjs[(*robjs_count)++] = psi->client_trans->sck;
|
||||
psi_in_use = 1;
|
||||
}
|
||||
|
||||
if (psi->sesexec_trans != NULL &&
|
||||
psi->sesexec_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
robjs[(*robjs_count)++] = psi->sesexec_trans->sck;
|
||||
psi_in_use = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (psi_in_use)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
free_pre_session_item(psi);
|
||||
list_remove_item(g_pre_session_list, i);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
pre_session_list_check_wait_objs(void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < g_pre_session_list->count)
|
||||
{
|
||||
struct pre_session_item *psi;
|
||||
enum pre_session_dispatcher_action action;
|
||||
|
||||
psi = (struct pre_session_item *)list_get_item(g_pre_session_list, i);
|
||||
action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
|
||||
if (PRE_SESSION_IN_USE(psi))
|
||||
{
|
||||
if (psi->client_trans != NULL &&
|
||||
psi->client_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
if (trans_check_wait_objs(psi->client_trans) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "pre_session_list_check_wait_objs: "
|
||||
"trans_check_wait_objs(1) failed, removing trans");
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
}
|
||||
}
|
||||
|
||||
if (psi->sesexec_trans != NULL &&
|
||||
psi->sesexec_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
if (trans_check_wait_objs(psi->sesexec_trans) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "pre_session_list_check_wait_objs: "
|
||||
"trans_check_wait_objs(2) failed, removing trans");
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get any action, and reset the requested one */
|
||||
action = psi->dispatcher_action;
|
||||
psi->dispatcher_action = E_PSD_NONE;
|
||||
}
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case E_PSD_NONE:
|
||||
/* On to the next item on the list */
|
||||
++i;
|
||||
break;
|
||||
|
||||
case E_PSD_REMOVE_CLIENT_TRANS:
|
||||
trans_delete(psi->client_trans);
|
||||
psi->client_trans = NULL;
|
||||
/* On to the next item on the list */
|
||||
++i;
|
||||
break;
|
||||
case E_PSD_TERMINATE_PRE_SESSION:
|
||||
free_pre_session_item(psi);
|
||||
list_remove_item(g_pre_session_list, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
* xrdp: A Remote Desktop Protocol server.
|
||||
*
|
||||
* Copyright (C) Jay Sorg 2004-2015
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @file scp_list.h
|
||||
* @brief List of SCP connections to sesman (definitions)
|
||||
*
|
||||
* @author Matt Burt
|
||||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config_ac.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "arch.h"
|
||||
#include "list.h"
|
||||
#include "os_calls.h"
|
||||
#include "scp_list.h"
|
||||
#include "trans.h"
|
||||
|
||||
#define SCP_LIST_ITEM_IN_USE(sli) \
|
||||
( \
|
||||
(sli) != NULL && \
|
||||
( \
|
||||
((sli)->client_trans != NULL && (sli)->client_trans->status == TRANS_STATUS_UP) || \
|
||||
((sli)->sesexec_trans != NULL && (sli)->sesexec_trans->status == TRANS_STATUS_UP) \
|
||||
) \
|
||||
)
|
||||
|
||||
static struct list *g_scp_list = NULL;
|
||||
|
||||
/**
|
||||
* Deletes a scp_list_item, freeing resources
|
||||
*
|
||||
* After this call, the passed-in pointer is invalid and must not be
|
||||
* referenced.
|
||||
*
|
||||
* Any auth_info struct found in the sesman_con is also deallocated.
|
||||
*
|
||||
* @param sli struct to de-allocate
|
||||
*/
|
||||
static void
|
||||
free_scp_list_item(struct scp_list_item *sli)
|
||||
{
|
||||
if (sli != NULL)
|
||||
{
|
||||
trans_delete(sli->client_trans);
|
||||
trans_delete(sli->sesexec_trans);
|
||||
g_free(sli->username);
|
||||
g_free(sli);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
scp_list_init(unsigned int list_size)
|
||||
{
|
||||
int rv = 1;
|
||||
if (g_scp_list == NULL)
|
||||
{
|
||||
g_scp_list = list_create_sized(list_size);
|
||||
}
|
||||
|
||||
if (g_scp_list == NULL)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "Can't allocate SCP list");
|
||||
}
|
||||
else
|
||||
{
|
||||
g_scp_list->auto_free = 0;
|
||||
rv = 0;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void
|
||||
scp_list_cleanup(void)
|
||||
{
|
||||
if (g_scp_list != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0 ; i < g_scp_list->count ; ++i)
|
||||
{
|
||||
struct scp_list_item *p;
|
||||
p = (struct scp_list_item *)list_get_item(g_scp_list, i);
|
||||
free_scp_list_item(p);
|
||||
}
|
||||
list_delete(g_scp_list);
|
||||
g_scp_list = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
unsigned int
|
||||
scp_list_get_count(void)
|
||||
{
|
||||
return g_scp_list->count;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
struct scp_list_item *
|
||||
scp_list_item_new(void)
|
||||
{
|
||||
struct scp_list_item *result = g_new0(struct scp_list_item, 1);
|
||||
if (result != NULL)
|
||||
{
|
||||
g_snprintf(result->peername, sizeof(result->peername), "unknown");
|
||||
result->uid = (uid_t) -1;
|
||||
|
||||
if (!list_add_item(g_scp_list, (tintptr)result))
|
||||
{
|
||||
g_free(result);
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
scp_list_set_peername(struct scp_list_item *sli, const char *name)
|
||||
{
|
||||
int rv = 1;
|
||||
|
||||
if (sli != NULL && name != NULL)
|
||||
{
|
||||
g_snprintf(sli->peername, sizeof(sli->peername), "%s", name);
|
||||
rv = 0;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
scp_list_get_wait_objs(tbus robjs[], int *robjs_count)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < g_scp_list->count)
|
||||
{
|
||||
struct scp_list_item *sli;
|
||||
sli = (struct scp_list_item *)list_get_item(g_scp_list, i);
|
||||
int sli_in_use = 0;
|
||||
|
||||
if (sli != NULL)
|
||||
{
|
||||
if (sli->client_trans != NULL &&
|
||||
sli->client_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
robjs[(*robjs_count)++] = sli->client_trans->sck;
|
||||
sli_in_use = 1;
|
||||
}
|
||||
|
||||
if (sli->sesexec_trans != NULL &&
|
||||
sli->sesexec_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
robjs[(*robjs_count)++] = sli->sesexec_trans->sck;
|
||||
sli_in_use = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sli_in_use)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
free_scp_list_item(sli);
|
||||
list_remove_item(g_scp_list, i);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
scp_list_check_wait_objs(void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < g_scp_list->count)
|
||||
{
|
||||
struct scp_list_item *sli;
|
||||
enum scp_list_dispatcher_action action;
|
||||
|
||||
sli = (struct scp_list_item *)list_get_item(g_scp_list, i);
|
||||
action = E_SLD_TERMINATE_SCP_CONN;
|
||||
|
||||
if (SCP_LIST_ITEM_IN_USE(sli))
|
||||
{
|
||||
if (sli->client_trans != NULL &&
|
||||
sli->client_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
if (trans_check_wait_objs(sli->client_trans) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "scp_list_check_wait_objs: "
|
||||
"trans_check_wait_objs(1) failed, removing trans");
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
}
|
||||
}
|
||||
|
||||
if (sli->sesexec_trans != NULL &&
|
||||
sli->sesexec_trans->status == TRANS_STATUS_UP)
|
||||
{
|
||||
if (trans_check_wait_objs(sli->sesexec_trans) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "scp_list_check_wait_objs: "
|
||||
"trans_check_wait_objs(2) failed, removing trans");
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get any action, and reset the requested one */
|
||||
action = sli->dispatcher_action;
|
||||
sli->dispatcher_action = E_SLD_NONE;
|
||||
}
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case E_SLD_NONE:
|
||||
/* On to the next item on the list */
|
||||
++i;
|
||||
break;
|
||||
|
||||
case E_SLD_REMOVE_CLIENT_TRANS:
|
||||
trans_delete(sli->client_trans);
|
||||
sli->client_trans = NULL;
|
||||
/* On to the next item on the list */
|
||||
++i;
|
||||
break;
|
||||
case E_SLD_TERMINATE_SCP_CONN:
|
||||
free_scp_list_item(sli);
|
||||
list_remove_item(g_scp_list, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -18,31 +18,28 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @file pre_session_list.h
|
||||
* @brief List of pre-session connections to sesman (declarations)
|
||||
*
|
||||
* Items on this list are moved to the session list once they have
|
||||
* authenticated and a session is started.
|
||||
* @file scp_list.h
|
||||
* @brief List of SCP connections to sesman (declarations)
|
||||
*
|
||||
* @author Matt Burt
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRE_SESSION_LIST_H
|
||||
#define PRE_SESSION_LIST_H
|
||||
#ifndef SCP_LIST_H
|
||||
#define SCP_LIST_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "xrdp_constants.h"
|
||||
|
||||
/**
|
||||
* Type describing the login state of a pre-session item
|
||||
* Type describing the login state of an SCP list item
|
||||
*/
|
||||
enum ps_login_state
|
||||
enum sli_login_state
|
||||
{
|
||||
E_PS_LOGIN_NOT_LOGGED_IN = 0,
|
||||
E_PS_LOGIN_SYS,
|
||||
E_PS_LOGIN_UDS
|
||||
E_SLI_LOGIN_NOT_LOGGED_IN = 0,
|
||||
E_SLI_LOGIN_SYS,
|
||||
E_SLI_LOGIN_UDS
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -52,28 +49,28 @@ enum ps_login_state
|
||||
* ask the dispatcher to do them. For example, we can't delete the
|
||||
* client_trans as the callback stack won't be expecting this.
|
||||
*/
|
||||
enum pre_session_dispatcher_action
|
||||
enum scp_list_dispatcher_action
|
||||
{
|
||||
E_PSD_NONE = 0,
|
||||
E_PSD_REMOVE_CLIENT_TRANS,
|
||||
E_PSD_TERMINATE_PRE_SESSION
|
||||
E_SLD_NONE = 0,
|
||||
E_SLD_REMOVE_CLIENT_TRANS,
|
||||
E_SLD_TERMINATE_SCP_CONN
|
||||
};
|
||||
|
||||
/**
|
||||
* Type for managing sesman connections from SCP clients (xrdp, etc)
|
||||
* and any sesexec processes we've created for them.
|
||||
*/
|
||||
struct pre_session_item
|
||||
struct scp_list_item
|
||||
{
|
||||
struct trans *client_trans; ///< SCP link to sesman client
|
||||
struct trans *sesexec_trans; ///< ECP link to sesexec
|
||||
pid_t sesexec_pid; ///< PID of sesexec (if sesexec is active)
|
||||
char peername[15 + 1]; ///< Name of peer, if known, for logging
|
||||
enum ps_login_state login_state; ///< Login state
|
||||
enum sli_login_state login_state; ///< Login state
|
||||
/**
|
||||
* Any action which a callback requires the dispatcher to
|
||||
* do out of scope of the callback */
|
||||
enum pre_session_dispatcher_action dispatcher_action;
|
||||
enum scp_list_dispatcher_action dispatcher_action;
|
||||
uid_t uid; ///< User
|
||||
char *username; ///< Username from UID (at time of logon)
|
||||
char start_ip_addr[MAX_PEER_ADDRSTRLEN];
|
||||
@@ -83,67 +80,67 @@ struct pre_session_item
|
||||
|
||||
/**
|
||||
* Initialise the module
|
||||
* @param list_size Number of pre-session items allowed
|
||||
* @param list_size Number of SCP list items allowed
|
||||
* @return 0 for success
|
||||
*
|
||||
* Errors are logged
|
||||
*/
|
||||
int
|
||||
pre_session_list_init(unsigned int list_size);
|
||||
scp_list_init(unsigned int list_size);
|
||||
|
||||
/**
|
||||
* Clean up the module on program exit
|
||||
*/
|
||||
void
|
||||
pre_session_list_cleanup(void);
|
||||
scp_list_cleanup(void);
|
||||
|
||||
/**
|
||||
* Returns the number of items on the pre-session list
|
||||
* Returns the number of items on the SCP list
|
||||
* @return Item count
|
||||
*/
|
||||
unsigned int
|
||||
pre_session_list_get_count(void);
|
||||
scp_list_get_count(void);
|
||||
|
||||
/**
|
||||
* Allocates a new pre-session item on the list
|
||||
* Allocates a new item on the SCP list
|
||||
*
|
||||
* @return pointer to new pre-session object or NULL for no memory
|
||||
* @return pointer to new SCP list item or NULL for no memory
|
||||
*
|
||||
* After allocating the session, you must initialise the sesexec_trans field
|
||||
* After allocating the item, you must initialise the sesexec_trans field
|
||||
* with a valid transport.
|
||||
*
|
||||
* The session is removed by pre_session_list_get_wait_objs() or
|
||||
* pre_session_check_wait_objs() when the client
|
||||
* The session is removed by scp_list_get_wait_objs() or
|
||||
* scp_list_check_wait_objs() when the client
|
||||
* transport goes down (or wasn't allocated in the first place).
|
||||
*/
|
||||
struct pre_session_item *
|
||||
pre_session_list_new(void);
|
||||
struct scp_list_item *
|
||||
scp_list_item_new(void);
|
||||
|
||||
/**
|
||||
* Set the peername of a pre-session
|
||||
* Set the peername of an SCP list item
|
||||
*
|
||||
* @param psi pre-session-item
|
||||
* @param sli SCP list item
|
||||
* @param name Name to set
|
||||
* @result 0 for success
|
||||
*/
|
||||
int
|
||||
pre_session_list_set_peername(struct pre_session_item *psi, const char *name);
|
||||
scp_list_set_peername(struct scp_list_item *sli, const char *name);
|
||||
|
||||
/**
|
||||
* @brief Get the wait objs for the pre-session list module
|
||||
* @brief Get the wait objs for the SCP list module
|
||||
* @param @robjs Objects array to update
|
||||
* @param robjs_count Elements in robjs (by reference)
|
||||
* @return 0 for success
|
||||
*/
|
||||
int
|
||||
pre_session_list_get_wait_objs(tbus robjs[], int *robjs_count);
|
||||
scp_list_get_wait_objs(tbus robjs[], int *robjs_count);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Check the wait objs for the pre-session list module
|
||||
* @brief Check the wait objs for the SCP list module
|
||||
* @return 0 for success
|
||||
*/
|
||||
int
|
||||
pre_session_list_check_wait_objs(void);
|
||||
scp_list_check_wait_objs(void);
|
||||
|
||||
#endif // PRE_SESSION_LIST_H
|
||||
#endif // SCP_LIST_H
|
||||
+101
-101
@@ -40,7 +40,7 @@
|
||||
#include "sesman_auth.h"
|
||||
#include "sesman_config.h"
|
||||
#include "os_calls.h"
|
||||
#include "pre_session_list.h"
|
||||
#include "scp_list.h"
|
||||
#include "session_list.h"
|
||||
#include "sesexec_control.h"
|
||||
#include "string_calls.h"
|
||||
@@ -49,19 +49,19 @@
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_set_peername_request(struct pre_session_item *psi)
|
||||
process_set_peername_request(struct scp_list_item *sli)
|
||||
{
|
||||
int rv;
|
||||
const char *peername;
|
||||
|
||||
rv = scp_get_set_peername_request(psi->client_trans, &peername);
|
||||
rv = scp_get_set_peername_request(sli->client_trans, &peername);
|
||||
if (rv == 0)
|
||||
{
|
||||
if (pre_session_list_set_peername(psi, peername) != 0)
|
||||
if (scp_list_set_peername(sli, peername) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_WARNING,
|
||||
"Failed to set connection peername from %s to %s",
|
||||
psi->peername, peername);
|
||||
sli->peername, peername);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ process_set_peername_request(struct pre_session_item *psi)
|
||||
|
||||
/******************************************************************************/
|
||||
static int
|
||||
process_sys_login_request(struct pre_session_item *psi)
|
||||
process_sys_login_request(struct scp_list_item *sli)
|
||||
{
|
||||
int rv;
|
||||
const char *username;
|
||||
@@ -78,7 +78,7 @@ process_sys_login_request(struct pre_session_item *psi)
|
||||
const char *ip_addr;
|
||||
int send_client_reply = 1;
|
||||
|
||||
rv = scp_get_sys_login_request(psi->client_trans, &username,
|
||||
rv = scp_get_sys_login_request(sli->client_trans, &username,
|
||||
&password, &ip_addr);
|
||||
if (rv == 0)
|
||||
{
|
||||
@@ -86,15 +86,15 @@ process_sys_login_request(struct pre_session_item *psi)
|
||||
|
||||
LOG(LOG_LEVEL_INFO,
|
||||
"Received system login request from %s for user: %s IP: %s",
|
||||
psi->peername, username, ip_addr);
|
||||
sli->peername, username, ip_addr);
|
||||
|
||||
if (psi->login_state != E_PS_LOGIN_NOT_LOGGED_IN)
|
||||
if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)
|
||||
{
|
||||
errorcode = E_SCP_LOGIN_ALREADY_LOGGED_IN;
|
||||
LOG(LOG_LEVEL_ERROR, "Connection is already logged in for %s",
|
||||
psi->username);
|
||||
sli->username);
|
||||
}
|
||||
else if ((psi->username = g_strdup(username)) == NULL)
|
||||
else if ((sli->username = g_strdup(username)) == NULL)
|
||||
{
|
||||
errorcode = E_SCP_LOGIN_NO_MEMORY;
|
||||
LOG(LOG_LEVEL_ERROR, "Memory allocation failure logging in %s",
|
||||
@@ -107,14 +107,14 @@ process_sys_login_request(struct pre_session_item *psi)
|
||||
* successful login. We need this so we can search for a session
|
||||
* with a matching IP address if required.
|
||||
*/
|
||||
g_snprintf(psi->start_ip_addr, sizeof(psi->start_ip_addr),
|
||||
g_snprintf(sli->start_ip_addr, sizeof(sli->start_ip_addr),
|
||||
"%s", ip_addr);
|
||||
|
||||
/* Create a sesexec process to handle the login
|
||||
*
|
||||
* We won't check for the user being valid here, as this might
|
||||
* lead to information leakage */
|
||||
if (sesexec_start(psi) != 0)
|
||||
if (sesexec_start(sli) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR,
|
||||
"Can't start sesexec to authenticate user");
|
||||
@@ -123,11 +123,11 @@ process_sys_login_request(struct pre_session_item *psi)
|
||||
else
|
||||
{
|
||||
int eicp_stat;
|
||||
eicp_stat = eicp_send_sys_login_request(psi->sesexec_trans,
|
||||
eicp_stat = eicp_send_sys_login_request(sli->sesexec_trans,
|
||||
username,
|
||||
password,
|
||||
ip_addr,
|
||||
psi->client_trans->sck);
|
||||
sli->client_trans->sck);
|
||||
if (eicp_stat != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR,
|
||||
@@ -139,7 +139,7 @@ process_sys_login_request(struct pre_session_item *psi)
|
||||
/* We've handed over responsibility for the
|
||||
* SCP communication */
|
||||
send_client_reply = 0;
|
||||
psi->dispatcher_action = E_PSD_REMOVE_CLIENT_TRANS;
|
||||
sli->dispatcher_action = E_SLD_REMOVE_CLIENT_TRANS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,8 +148,8 @@ process_sys_login_request(struct pre_session_item *psi)
|
||||
{
|
||||
/* We only get here if something has gone
|
||||
* wrong with the handover to sesexec */
|
||||
rv = scp_send_login_response(psi->client_trans, errorcode, 1, -1);
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
rv = scp_send_login_response(sli->client_trans, errorcode, 1, -1);
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,15 +161,15 @@ process_sys_login_request(struct pre_session_item *psi)
|
||||
/**
|
||||
* Authenticate and authorize a UDS connection
|
||||
*
|
||||
* @param psi Connection to sesman
|
||||
* @param sli Connection to sesman
|
||||
* @param uid UID for user
|
||||
* @param username Name for user
|
||||
* @return Status for the operation
|
||||
*
|
||||
* @post If E_SCP_LOGIN_OK is returned, psi->username is non-NULL
|
||||
* @post If E_SCP_LOGIN_OK is returned, sli->username is non-NULL
|
||||
*/
|
||||
static enum scp_login_status
|
||||
authenticate_and_authorize_uds_connection(struct pre_session_item *psi,
|
||||
authenticate_and_authorize_uds_connection(struct scp_list_item *sli,
|
||||
int uid,
|
||||
const char *username)
|
||||
{
|
||||
@@ -194,22 +194,22 @@ authenticate_and_authorize_uds_connection(struct pre_session_item *psi,
|
||||
/* If all is well, add info to the sesman connection for later use */
|
||||
if (status == E_SCP_LOGIN_OK)
|
||||
{
|
||||
if ((psi->username = g_strdup(username)) == NULL)
|
||||
if ((sli->username = g_strdup(username)) == NULL)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "%s : Memory allocation failed",
|
||||
__func__);
|
||||
g_free(psi->username);
|
||||
psi->username = NULL;
|
||||
g_free(sli->username);
|
||||
sli->username = NULL;
|
||||
status = E_SCP_LOGIN_NO_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
psi->login_state = E_PS_LOGIN_UDS;
|
||||
psi->uid = uid;
|
||||
psi->start_ip_addr[0] = '\0';
|
||||
psi->is_admin = access_login_is_admin(&g_cfg->sec,
|
||||
psi->username);
|
||||
if (psi->is_admin)
|
||||
sli->login_state = E_SLI_LOGIN_UDS;
|
||||
sli->uid = uid;
|
||||
sli->start_ip_addr[0] = '\0';
|
||||
sli->is_admin = access_login_is_admin(&g_cfg->sec,
|
||||
sli->username);
|
||||
if (sli->is_admin)
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO, "Admin access permitted for user: %s",
|
||||
username);
|
||||
@@ -231,7 +231,7 @@ authenticate_and_authorize_uds_connection(struct pre_session_item *psi,
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_uds_login_request(struct pre_session_item *psi)
|
||||
process_uds_login_request(struct scp_list_item *sli)
|
||||
{
|
||||
enum scp_login_status errorcode;
|
||||
int rv;
|
||||
@@ -240,25 +240,25 @@ process_uds_login_request(struct pre_session_item *psi)
|
||||
char *username = NULL;
|
||||
int server_closed;
|
||||
|
||||
rv = g_sck_get_peer_cred(psi->client_trans->sck, &pid, &uid, NULL);
|
||||
rv = g_sck_get_peer_cred(sli->client_trans->sck, &pid, &uid, NULL);
|
||||
if (rv != 0)
|
||||
{
|
||||
errorcode = E_SCP_LOGIN_GENERAL_ERROR;
|
||||
LOG(LOG_LEVEL_INFO,
|
||||
"Unable to get peer credentials for socket %d",
|
||||
(int)psi->client_trans->sck);
|
||||
(int)sli->client_trans->sck);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO,
|
||||
"Received UDS login request from %s for UID: %d from PID: %d",
|
||||
psi->peername, uid, pid);
|
||||
sli->peername, uid, pid);
|
||||
|
||||
if (psi->login_state != E_PS_LOGIN_NOT_LOGGED_IN)
|
||||
if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)
|
||||
{
|
||||
errorcode = E_SCP_LOGIN_ALREADY_LOGGED_IN;
|
||||
LOG(LOG_LEVEL_ERROR, "Connection is already logged in for %s",
|
||||
psi->username);
|
||||
sli->username);
|
||||
}
|
||||
else if (g_getuser_info_by_uid(uid, &username,
|
||||
NULL, NULL, NULL, NULL) != 0)
|
||||
@@ -269,7 +269,7 @@ process_uds_login_request(struct pre_session_item *psi)
|
||||
else
|
||||
{
|
||||
errorcode = authenticate_and_authorize_uds_connection(
|
||||
psi, uid, username);
|
||||
sli, uid, username);
|
||||
g_free(username);
|
||||
}
|
||||
}
|
||||
@@ -283,44 +283,44 @@ process_uds_login_request(struct pre_session_item *psi)
|
||||
server_closed = 1;
|
||||
|
||||
/* Close the connection after returning from this callback */
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
|
||||
/* Never return the UID if the server is closing */
|
||||
uid = -1;
|
||||
}
|
||||
|
||||
return scp_send_login_response(psi->client_trans, errorcode,
|
||||
return scp_send_login_response(sli->client_trans, errorcode,
|
||||
server_closed, uid);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static void
|
||||
logout_pre_session(struct pre_session_item *psi)
|
||||
logout_scp_list_item(struct scp_list_item *sli)
|
||||
{
|
||||
if (psi->login_state != E_PS_LOGIN_NOT_LOGGED_IN)
|
||||
if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)
|
||||
{
|
||||
(void)eicp_send_logout_request(psi->sesexec_trans);
|
||||
trans_delete(psi->sesexec_trans);
|
||||
psi->sesexec_trans = NULL;
|
||||
psi->uid = (uid_t) -1;
|
||||
g_free(psi->username);
|
||||
psi->username = NULL;
|
||||
psi->start_ip_addr[0] = '\0';
|
||||
(void)eicp_send_logout_request(sli->sesexec_trans);
|
||||
trans_delete(sli->sesexec_trans);
|
||||
sli->sesexec_trans = NULL;
|
||||
sli->uid = (uid_t) -1;
|
||||
g_free(sli->username);
|
||||
sli->username = NULL;
|
||||
sli->start_ip_addr[0] = '\0';
|
||||
|
||||
psi->login_state = E_PS_LOGIN_NOT_LOGGED_IN;
|
||||
sli->login_state = E_SLI_LOGIN_NOT_LOGGED_IN;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_logout_request(struct pre_session_item *psi)
|
||||
process_logout_request(struct scp_list_item *sli)
|
||||
{
|
||||
if (psi->login_state != E_PS_LOGIN_NOT_LOGGED_IN)
|
||||
if (sli->login_state != E_SLI_LOGIN_NOT_LOGGED_IN)
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO, "Logging out %s from sesman", psi->username);
|
||||
logout_pre_session(psi);
|
||||
LOG(LOG_LEVEL_INFO, "Logging out %s from sesman", sli->username);
|
||||
logout_scp_list_item(sli);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -392,7 +392,7 @@ create_xrdp_socket_path(uid_t uid)
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_create_session_request(struct pre_session_item *psi)
|
||||
process_create_session_request(struct scp_list_item *sli)
|
||||
{
|
||||
int rv;
|
||||
/* Client parameters describing new session*/
|
||||
@@ -410,13 +410,13 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
|
||||
enum scp_screate_status status = E_SCP_SCREATE_OK;
|
||||
|
||||
rv = scp_get_create_session_request(psi->client_trans,
|
||||
rv = scp_get_create_session_request(sli->client_trans,
|
||||
&type, &width, &height,
|
||||
&bpp, &shell, &directory);
|
||||
|
||||
if (rv == 0)
|
||||
{
|
||||
if (psi->login_state == E_PS_LOGIN_NOT_LOGGED_IN)
|
||||
if (sli->login_state == E_SLI_LOGIN_NOT_LOGGED_IN)
|
||||
{
|
||||
status = E_SCP_SCREATE_NOT_LOGGED_IN;
|
||||
}
|
||||
@@ -424,10 +424,10 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO,
|
||||
"Received request from %s to create a session for user %s",
|
||||
psi->peername, psi->username);
|
||||
sli->peername, sli->username);
|
||||
|
||||
s_item = session_list_get_bydata(psi->uid, type, width, height,
|
||||
bpp, psi->start_ip_addr);
|
||||
s_item = session_list_get_bydata(sli->uid, type, width, height,
|
||||
bpp, sli->start_ip_addr);
|
||||
if (s_item != NULL)
|
||||
{
|
||||
// Found an existing session
|
||||
@@ -439,23 +439,23 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
// will be picked up in the main loop
|
||||
(void)ercp_send_session_reconnect_event(s_item->sesexec_trans);
|
||||
|
||||
if (psi->start_ip_addr[0] != '\0')
|
||||
if (sli->start_ip_addr[0] != '\0')
|
||||
{
|
||||
LOG( LOG_LEVEL_INFO, "++ reconnected session: username %s, "
|
||||
"display :%d.0, session_pid %d, ip %s",
|
||||
psi->username, display,
|
||||
s_item->sesexec_pid, psi->start_ip_addr);
|
||||
sli->username, display,
|
||||
s_item->sesexec_pid, sli->start_ip_addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO, "++ reconnected session: username %s, "
|
||||
"display :%d.0, session_pid %d",
|
||||
psi->username, display, s_item->sesexec_pid);
|
||||
sli->username, display, s_item->sesexec_pid);
|
||||
}
|
||||
|
||||
// If we created an authentication process for this SCP
|
||||
// connection, close it gracefully
|
||||
logout_pre_session(psi);
|
||||
logout_scp_list_item(sli);
|
||||
}
|
||||
// Need to create a new session
|
||||
else if (g_cfg->sess.max_sessions > 0 &&
|
||||
@@ -473,12 +473,12 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
status = E_SCP_SCREATE_NO_MEMORY;
|
||||
}
|
||||
// Create a socket dir for this user
|
||||
else if (create_xrdp_socket_path(psi->uid) != 0)
|
||||
else if (create_xrdp_socket_path(sli->uid) != 0)
|
||||
{
|
||||
status = E_SCP_SCREATE_GENERAL_ERROR;
|
||||
}
|
||||
// Create a sesexec process if we don't have one (UDS login)
|
||||
else if (psi->sesexec_trans == NULL && sesexec_start(psi) != 0)
|
||||
else if (sli->sesexec_trans == NULL && sesexec_start(sli) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR,
|
||||
"Can't start sesexec to manage session");
|
||||
@@ -489,8 +489,8 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
// Pass the session create request to sesexec
|
||||
int eicp_stat;
|
||||
eicp_stat = eicp_send_create_session_request(
|
||||
psi->sesexec_trans,
|
||||
psi->client_trans->sck,
|
||||
sli->sesexec_trans,
|
||||
sli->client_trans->sck,
|
||||
display,
|
||||
type, width, height,
|
||||
bpp, shell, directory);
|
||||
@@ -509,15 +509,15 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
|
||||
// Further comms from sesexec comes over the ERCP
|
||||
// protocol
|
||||
ercp_trans_from_eicp_trans(psi->sesexec_trans,
|
||||
ercp_trans_from_eicp_trans(sli->sesexec_trans,
|
||||
sesman_ercp_data_in,
|
||||
(void *)s_item);
|
||||
|
||||
// Move the transport over to the session list item
|
||||
s_item->sesexec_trans = psi->sesexec_trans;
|
||||
s_item->sesexec_pid = psi->sesexec_pid;
|
||||
psi->sesexec_trans = NULL;
|
||||
psi->sesexec_pid = 0;
|
||||
s_item->sesexec_trans = sli->sesexec_trans;
|
||||
s_item->sesexec_pid = sli->sesexec_pid;
|
||||
sli->sesexec_trans = NULL;
|
||||
sli->sesexec_pid = 0;
|
||||
|
||||
// Add the display to the session item so we don't try
|
||||
// to allocate it to another session
|
||||
@@ -531,10 +531,10 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
//
|
||||
// We may have passed the client_trans over to sesexec. If so,
|
||||
// we can't send a reply here.
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
if (send_client_reply)
|
||||
{
|
||||
rv = scp_send_create_session_response(psi->client_trans,
|
||||
rv = scp_send_create_session_response(sli->client_trans,
|
||||
status, display, &guid);
|
||||
}
|
||||
}
|
||||
@@ -545,7 +545,7 @@ process_create_session_request(struct pre_session_item *psi)
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_list_sessions_request(struct pre_session_item *psi)
|
||||
process_list_sessions_request(struct scp_list_item *sli)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
@@ -553,9 +553,9 @@ process_list_sessions_request(struct pre_session_item *psi)
|
||||
unsigned int cnt = 0;
|
||||
unsigned int i;
|
||||
|
||||
if (psi->login_state == E_PS_LOGIN_NOT_LOGGED_IN)
|
||||
if (sli->login_state == E_SLI_LOGIN_NOT_LOGGED_IN)
|
||||
{
|
||||
rv = scp_send_list_sessions_response(psi->client_trans,
|
||||
rv = scp_send_list_sessions_response(sli->client_trans,
|
||||
E_SCP_LS_NOT_LOGGED_IN,
|
||||
NULL);
|
||||
}
|
||||
@@ -563,20 +563,20 @@ process_list_sessions_request(struct pre_session_item *psi)
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO,
|
||||
"Received request from %s to list sessions for user %s",
|
||||
psi->peername, psi->username);
|
||||
sli->peername, sli->username);
|
||||
|
||||
if (psi->is_admin)
|
||||
if (sli->is_admin)
|
||||
{
|
||||
info = session_list_get_byuid(NULL, &cnt, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
info = session_list_get_byuid(&psi->uid, &cnt, 0);
|
||||
info = session_list_get_byuid(&sli->uid, &cnt, 0);
|
||||
}
|
||||
|
||||
for (i = 0; rv == 0 && i < cnt; ++i)
|
||||
{
|
||||
rv = scp_send_list_sessions_response(psi->client_trans,
|
||||
rv = scp_send_list_sessions_response(sli->client_trans,
|
||||
E_SCP_LS_SESSION_INFO,
|
||||
&info[i]);
|
||||
}
|
||||
@@ -584,7 +584,7 @@ process_list_sessions_request(struct pre_session_item *psi)
|
||||
|
||||
if (rv == 0)
|
||||
{
|
||||
rv = scp_send_list_sessions_response(psi->client_trans,
|
||||
rv = scp_send_list_sessions_response(sli->client_trans,
|
||||
E_SCP_LS_END_OF_LIST,
|
||||
NULL);
|
||||
}
|
||||
@@ -596,11 +596,11 @@ process_list_sessions_request(struct pre_session_item *psi)
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_create_sockdir_request(struct pre_session_item *psi)
|
||||
process_create_sockdir_request(struct scp_list_item *sli)
|
||||
{
|
||||
enum scp_create_sockdir_status status = E_SCP_CS_OTHER_ERROR;
|
||||
|
||||
if (psi->login_state == E_PS_LOGIN_NOT_LOGGED_IN)
|
||||
if (sli->login_state == E_SLI_LOGIN_NOT_LOGGED_IN)
|
||||
{
|
||||
status = E_SCP_CS_NOT_LOGGED_IN;
|
||||
}
|
||||
@@ -608,72 +608,72 @@ process_create_sockdir_request(struct pre_session_item *psi)
|
||||
{
|
||||
LOG(LOG_LEVEL_INFO,
|
||||
"Received request from %s to create sockdir for user %s",
|
||||
psi->peername, psi->username);
|
||||
sli->peername, sli->username);
|
||||
|
||||
if (create_xrdp_socket_path(psi->uid) == 0)
|
||||
if (create_xrdp_socket_path(sli->uid) == 0)
|
||||
{
|
||||
status = E_SCP_CS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return scp_send_create_sockdir_response(psi->client_trans, status);
|
||||
return scp_send_create_sockdir_response(sli->client_trans, status);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static int
|
||||
process_close_connection_request(struct pre_session_item *psi)
|
||||
process_close_connection_request(struct scp_list_item *sli)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
LOG(LOG_LEVEL_INFO, "Received request to close connection from %s",
|
||||
psi->peername);
|
||||
sli->peername);
|
||||
|
||||
/* Expecting no more client messages. Close the connection
|
||||
* after returning from this callback */
|
||||
psi->dispatcher_action = E_PSD_TERMINATE_PRE_SESSION;
|
||||
sli->dispatcher_action = E_SLD_TERMINATE_SCP_CONN;
|
||||
return rv;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
scp_process(struct pre_session_item *psi)
|
||||
scp_process(struct scp_list_item *sli)
|
||||
{
|
||||
enum scp_msg_code msgno;
|
||||
int rv = 0;
|
||||
|
||||
switch ((msgno = scp_msg_in_get_msgno(psi->client_trans)))
|
||||
switch ((msgno = scp_msg_in_get_msgno(sli->client_trans)))
|
||||
{
|
||||
case E_SCP_SET_PEERNAME_REQUEST:
|
||||
rv = process_set_peername_request(psi);
|
||||
rv = process_set_peername_request(sli);
|
||||
break;
|
||||
|
||||
case E_SCP_SYS_LOGIN_REQUEST:
|
||||
rv = process_sys_login_request(psi);
|
||||
rv = process_sys_login_request(sli);
|
||||
break;
|
||||
|
||||
case E_SCP_UDS_LOGIN_REQUEST:
|
||||
rv = process_uds_login_request(psi);
|
||||
rv = process_uds_login_request(sli);
|
||||
break;
|
||||
|
||||
case E_SCP_LOGOUT_REQUEST:
|
||||
rv = process_logout_request(psi);
|
||||
rv = process_logout_request(sli);
|
||||
break;
|
||||
|
||||
case E_SCP_CREATE_SESSION_REQUEST:
|
||||
rv = process_create_session_request(psi);
|
||||
rv = process_create_session_request(sli);
|
||||
break;
|
||||
|
||||
case E_SCP_LIST_SESSIONS_REQUEST:
|
||||
rv = process_list_sessions_request(psi);
|
||||
rv = process_list_sessions_request(sli);
|
||||
break;
|
||||
|
||||
case E_SCP_CREATE_SOCKDIR_REQUEST:
|
||||
rv = process_create_sockdir_request(psi);
|
||||
rv = process_create_sockdir_request(sli);
|
||||
break;
|
||||
|
||||
case E_SCP_CLOSE_CONNECTION_REQUEST:
|
||||
rv = process_close_connection_request(psi);
|
||||
rv = process_close_connection_request(sli);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -27,15 +27,15 @@
|
||||
#ifndef SCP_PROCESS_H
|
||||
#define SCP_PROCESS_H
|
||||
|
||||
struct pre_session_item;
|
||||
struct scp_list_item;
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Processes an SCP message
|
||||
* @param sc the sesman connection
|
||||
* @param sli the sesman connection
|
||||
*
|
||||
*/
|
||||
int
|
||||
scp_process(struct pre_session_item *sc);
|
||||
scp_process(struct scp_list_item *sli);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "eicp.h"
|
||||
#include "log.h"
|
||||
#include "os_calls.h"
|
||||
#include "pre_session_list.h"
|
||||
#include "scp_list.h"
|
||||
#include "string_calls.h"
|
||||
#include "sesexec_control.h"
|
||||
#include "sesman.h"
|
||||
@@ -104,7 +104,7 @@ create_exec_args(void)
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
sesexec_start(struct pre_session_item *psi)
|
||||
sesexec_start(struct scp_list_item *sli)
|
||||
{
|
||||
// Local socket pair used to set up the EICP channel for sesexec
|
||||
// We also use the socket pair to communicate the PID of sesexec back
|
||||
@@ -214,9 +214,9 @@ sesexec_start(struct pre_session_item *psi)
|
||||
else
|
||||
{
|
||||
t->trans_data_in = sesman_eicp_data_in;
|
||||
t->callback_data = (void *)psi;
|
||||
psi->sesexec_trans = t;
|
||||
psi->sesexec_pid = pid;
|
||||
t->callback_data = (void *)sli;
|
||||
sli->sesexec_trans = t;
|
||||
sli->sesexec_pid = pid;
|
||||
rv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,19 +31,19 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
struct trans;
|
||||
struct pre_session_item;
|
||||
struct scp_list_item;
|
||||
|
||||
/**
|
||||
* Start a session executive
|
||||
* @param psi Pre-session item to allocate EICP transport to
|
||||
* @param sli SCP list item to allocate EICP transport to
|
||||
* @result 0 for success
|
||||
*
|
||||
* If non-zero is returned, all errors have been logged.
|
||||
* If zero is returned, the sesexec_trans and sesexec_pid fields of
|
||||
* the pre-session-item have been initialised.
|
||||
* the SCP_list_item have been initialised.
|
||||
*/
|
||||
|
||||
int
|
||||
sesexec_start(struct pre_session_item *psi);
|
||||
sesexec_start(struct scp_list_item *sli);
|
||||
|
||||
#endif // SESEXEC_H
|
||||
|
||||
+20
-20
@@ -39,7 +39,7 @@
|
||||
#include "eicp_process.h"
|
||||
#include "ercp.h"
|
||||
#include "ercp_process.h"
|
||||
#include "pre_session_list.h"
|
||||
#include "scp_list.h"
|
||||
#include "session_list.h"
|
||||
#include "lock_uds.h"
|
||||
#include "os_calls.h"
|
||||
@@ -54,9 +54,9 @@
|
||||
#include "xrdp_sockets.h"
|
||||
|
||||
/**
|
||||
* Maximum number of pre-session items
|
||||
* Maximum number of SCP list items
|
||||
*/
|
||||
#define MAX_PRE_SESSION_ITEMS 16
|
||||
#define MAX_SCP_LIST_ITEMS 16
|
||||
|
||||
/**
|
||||
* Define the mode of operation of the program
|
||||
@@ -218,7 +218,7 @@ sesman_close_all(void)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_TRACE, "sesman_close_all:");
|
||||
|
||||
pre_session_list_cleanup();
|
||||
scp_list_cleanup();
|
||||
session_list_cleanup();
|
||||
|
||||
g_delete_wait_obj(g_reload_event);
|
||||
@@ -241,10 +241,10 @@ sesman_scp_data_in(struct trans *self)
|
||||
|
||||
if (rv == 0 && available)
|
||||
{
|
||||
struct pre_session_item *psi;
|
||||
psi = (struct pre_session_item *)self->callback_data;
|
||||
struct scp_list_item *sli;
|
||||
sli = (struct scp_list_item *)self->callback_data;
|
||||
|
||||
if ((rv = scp_process(psi)) != 0)
|
||||
if ((rv = scp_process(sli)) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "sesman_data_in: scp_process_msg failed");
|
||||
}
|
||||
@@ -258,14 +258,14 @@ sesman_scp_data_in(struct trans *self)
|
||||
static int
|
||||
sesman_listen_conn_in(struct trans *self, struct trans *new_self)
|
||||
{
|
||||
struct pre_session_item *psi;
|
||||
if (pre_session_list_get_count() >= MAX_PRE_SESSION_ITEMS)
|
||||
struct scp_list_item *sli;
|
||||
if (scp_list_get_count() >= MAX_SCP_LIST_ITEMS)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "sesman_listen_conn_in: error, too many "
|
||||
"connections, rejecting");
|
||||
trans_delete(new_self);
|
||||
}
|
||||
else if ((psi = pre_session_list_new()) == NULL)
|
||||
else if ((sli = scp_list_item_new()) == NULL)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "sesman_data_in: No memory to allocate "
|
||||
"new connection");
|
||||
@@ -278,9 +278,9 @@ sesman_listen_conn_in(struct trans *self, struct trans *new_self)
|
||||
}
|
||||
else
|
||||
{
|
||||
new_self->callback_data = (void *)psi;
|
||||
new_self->callback_data = (void *)sli;
|
||||
new_self->trans_data_in = sesman_scp_data_in;
|
||||
psi->client_trans = new_self;
|
||||
sli->client_trans = new_self;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -297,9 +297,9 @@ sesman_eicp_data_in(struct trans *self)
|
||||
|
||||
if (rv == 0 && available)
|
||||
{
|
||||
struct pre_session_item *psi;
|
||||
psi = (struct pre_session_item *)self->callback_data;
|
||||
if ((rv = eicp_process(psi)) != 0)
|
||||
struct scp_list_item *sli;
|
||||
sli = (struct scp_list_item *)self->callback_data;
|
||||
if ((rv = eicp_process(sli)) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "sesman_eicp_data_in: eicp_process_msg failed");
|
||||
}
|
||||
@@ -499,11 +499,11 @@ sesman_main_loop(void)
|
||||
}
|
||||
}
|
||||
|
||||
error = pre_session_list_get_wait_objs(robjs, &robjs_count);
|
||||
error = scp_list_get_wait_objs(robjs, &robjs_count);
|
||||
if (error != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
|
||||
"pre_session_list_get_wait_objs failed");
|
||||
"scp_list_get_wait_objs failed");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -557,11 +557,11 @@ sesman_main_loop(void)
|
||||
}
|
||||
}
|
||||
|
||||
error = pre_session_list_check_wait_objs();
|
||||
error = scp_list_check_wait_objs();
|
||||
if (error != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
|
||||
"pre_session_list_check_wait_objs failed");
|
||||
"scp_list_check_wait_objs failed");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -945,7 +945,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if ((error = pre_session_list_init(MAX_PRE_SESSION_ITEMS)) == 0 &&
|
||||
if ((error = scp_list_init(MAX_SCP_LIST_ITEMS)) == 0 &&
|
||||
(error = session_list_init()) == 0 &&
|
||||
(error = sesman_restart_discover_sessions()) == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user