Rework the start session method in SCP

The start session method is reworked to pass a response back to the
client.
If the method was successful, a session list entry is created. This
is different to the provious behaviour, where we created the
session list entry unconditionally.

This new arrangement means that we need a different way to avoid
a race condition where two users may try to create a session at the
same time, and end up with the same display. We do this by keeping
track of newly allocated displays as part of the SCP connections. When
we allocate a display, the SCP connection displays are also taken
into account.
This commit is contained in:
matt335672
2025-06-10 11:06:20 +01:00
parent 7baa27a59f
commit 3e38d9be80
17 changed files with 604 additions and 328 deletions
+57 -6
View File
@@ -44,6 +44,7 @@ msgno_to_str(unsigned short n)
(n == E_EICP_LOGOUT_REQUEST) ? "EICP_LOGOUT_REQUEST" :
(n == E_EICP_CREATE_SESSION_REQUEST) ? "EICP_CREATE_SESSION_REQUEST" :
(n == E_EICP_CREATE_SESSION_RESPONSE) ? "EICP_CREATE_SESSION_RESPONSE" :
NULL;
}
@@ -244,6 +245,23 @@ eicp_get_sys_login_response(struct trans *trans,
return rv;
}
/*****************************************************************************/
int
eicp_send_uds_login_request(struct trans *trans,
int scp_fd)
{
return libipm_msg_out_simple_send(
trans, (int)E_EICP_UDS_LOGIN_REQUEST, "h", scp_fd);
}
/*****************************************************************************/
int
eicp_get_uds_login_request(struct trans *trans,
int *scp_fd)
{
return libipm_msg_in_parse( trans, "h", scp_fd);
}
/*****************************************************************************/
int
eicp_send_logout_request(struct trans *trans)
@@ -255,7 +273,6 @@ eicp_send_logout_request(struct trans *trans)
int
eicp_send_create_session_request(struct trans *trans,
int scp_fd,
unsigned int display,
enum scp_session_type type,
unsigned short width,
@@ -267,8 +284,7 @@ eicp_send_create_session_request(struct trans *trans,
return libipm_msg_out_simple_send(
trans,
(int)E_EICP_CREATE_SESSION_REQUEST,
"huyqqyss",
scp_fd,
"uyqqyss",
display,
type,
width,
@@ -282,7 +298,6 @@ eicp_send_create_session_request(struct trans *trans,
int
eicp_get_create_session_request(struct trans *trans,
int *scp_fd,
unsigned int *display,
enum scp_session_type *type,
unsigned short *width,
@@ -300,8 +315,7 @@ eicp_get_create_session_request(struct trans *trans,
int rv = libipm_msg_in_parse(
trans,
"huyqqyss",
scp_fd,
"uyqqyss",
&i_display,
&i_type,
&i_width,
@@ -322,3 +336,40 @@ eicp_get_create_session_request(struct trans *trans,
return rv;
}
/*****************************************************************************/
int
eicp_send_create_session_response(struct trans *trans,
enum scp_screate_status status,
const struct guid *guid)
{
struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };
return libipm_msg_out_simple_send(
trans, (int)E_EICP_CREATE_SESSION_RESPONSE,
"iB", status, &guid_descriptor);
}
/*****************************************************************************/
int
eicp_get_create_session_response(struct trans *trans,
enum scp_screate_status *status,
struct guid *guid)
{
/* Intermediate values */
int32_t i_status;
const struct libipm_fsb guid_descriptor = { (void *)guid, sizeof(*guid) };
int rv = libipm_msg_in_parse(
trans,
"iB",
&i_status,
&guid_descriptor);
if (rv == 0)
{
*status = (enum scp_screate_status)i_status;
}
return rv;
}
+78 -14
View File
@@ -45,11 +45,14 @@ enum eicp_msg_code
E_EICP_SYS_LOGIN_REQUEST,
E_EICP_SYS_LOGIN_RESPONSE,
E_EICP_UDS_LOGIN_REQUEST,
// No E_EIC_UDS_LOGIN response
E_EICP_LOGOUT_REQUEST,
// No E_EICP_LOGOUT_RESPONSE
E_EICP_CREATE_SESSION_REQUEST
// No E_EICP_CREATE_SESSION_RESPONSE
E_EICP_CREATE_SESSION_REQUEST,
E_EICP_CREATE_SESSION_RESPONSE
};
/* Common facilities */
@@ -204,7 +207,7 @@ eicp_send_sys_login_response(struct trans *trans,
int scp_fd);
/**
* Parses an incoming E_EICP_SYS_LOGIN_RESPONSE (sesexec)
* Parses an incoming E_EICP_SYS_LOGIN_RESPONSE (sesman)
*
* @param trans EICP transport
* @param[out] is_logged_in true if the SCP client is logged in
@@ -221,6 +224,37 @@ eicp_get_sys_login_response(struct trans *trans,
uid_t *uid,
int *scp_fd);
/**
* Send an E_EICP_UDS_LOGIN_REQUEST (sesman)
*
* @param trans EICP transport
* @param scp_fd File descriptor attached to the client
* @return != 0 for error
*
* This call is needed if the sesexec process is created after
* the UID is known already. It generates no response. It is expected to
* succeed, as sesman is expected to have already vetted the caller.
*
* The file descriptor is closed immediately after it is used by the
* recipient.
*/
int
eicp_send_uds_login_request(struct trans *trans,
int scp_fd);
/**
* Get a E_EICP_UDS_LOGIN_REQUEST (sesexec)
*
* @param trans EICP transport
* @param[out] scp_fd File descriptor attached to the client
* @return != 0 for error
*/
int
eicp_get_uds_login_request(struct trans *trans,
int *scp_fd);
/**
* Send an E_EICP_LOGOUT_REQUEST (sesexec)
*
@@ -238,7 +272,6 @@ eicp_send_logout_request(struct trans *trans);
* Send an E_EICP_CREATE_SESSION_REQUEST (sesman)
*
* @param trans EICP transport
* @param scp_fd SCP file descriptor from sesman client
* @param display X display number to use
* @param type Session type
* @param width Initial session width
@@ -248,20 +281,17 @@ eicp_send_logout_request(struct trans *trans);
* @param directory Directory to run the program in. May be ""
* @return != 0 for error
*
* The UID for the session comes from one of two places:-
* - The UID for a sys login request is used if one has successfully
* been executed.
* - If no sys login request is used, the UID is taken from the scp_fd
* The UID for the session must have been set by a previous call.
*
* Following a successful request, the session creation can be
* considered to be underway. The result of this operation is
* conveyed back to the caller as an ERCP event. The caller must use
* ercp_trans_from_eicp_trans() on 'trans' to convert the transport to
* an ERCP transport to receive this (and other) session run-time events.
* conveyed back to the caller as one or more ERCP messages. The caller
* must use ercp_trans_from_eicp_trans() on 'trans' to convert the
* transport to an ERCP transport to receive this (and other) session
* run-time events.
*/
int
eicp_send_create_session_request(struct trans *trans,
int scp_fd,
unsigned int display,
enum scp_session_type type,
unsigned short width,
@@ -275,7 +305,6 @@ eicp_send_create_session_request(struct trans *trans,
* Parse an incoming E_EICP_CREATE_SESSION_REQUEST (sesexec)
*
* @param trans EICP transport
* @param[out] scp_fd SCP file descriptor from sesman client
* @param[out] display X display number to use
* @param[out] type Session type
* @param[out] width Initial session width
@@ -290,7 +319,6 @@ eicp_send_create_session_request(struct trans *trans,
*/
int
eicp_get_create_session_request(struct trans *trans,
int *scp_fd,
unsigned int *display,
enum scp_session_type *type,
unsigned short *width,
@@ -299,4 +327,40 @@ eicp_get_create_session_request(struct trans *trans,
const char **shell,
const char **directory);
/**
* Send an E_EICP_CREATE_SESSION_RESPONSE
*
* Direction : sesexec -> sesman
*
* This event is in response to an E_EICP_CREATE_SESSION_REQUEST
*
* @param trans EICP transport
* @param status Status of creation request
* @param guid GUID of session
* @return != 0 for error
*/
int
eicp_send_create_session_response(struct trans *trans,
enum scp_screate_status status,
const struct guid *guid);
/**
* Parse an E_EICP_CREATE_SESSION_RESPONSE
*
* Direction : sesexec -> sesman
*
* This event is in response to an E_EICP_CREATE_SESSION_REQUEST
*
* @param trans EICP transport
* @param[out] status Status of creation request
* @param[out] guid GUID of session
* @return != 0 for error
*/
int
eicp_get_create_session_response(struct trans *trans,
enum scp_screate_status *status,
struct guid *guid);
#endif /* EICP_H */
+2
View File
@@ -40,6 +40,8 @@ msgno_to_str(unsigned short n)
return
(n == E_ERCP_SESSION_ANNOUNCE_EVENT) ? "ERCP_SESSION_ANNOUNCE_EVENT" :
(n == E_ERCP_SESSION_FINISHED_EVENT) ? "ERCP_SESSION_FINISHED_EVENT" :
(n == E_ERCP_SESSION_RECONNECT_EVENT) ? "ERCP_SESSION_RECONNECT_EVENT" :
NULL;
}
+3 -5
View File
@@ -44,10 +44,10 @@ struct guid;
/* Message codes */
enum ercp_msg_code
{
E_ERCP_SESSION_ANNOUNCE_EVENT,
E_ERCP_SESSION_FINISHED_EVENT,
E_ERCP_SESSION_ANNOUNCE_EVENT, // sesexec -> sesman
E_ERCP_SESSION_FINISHED_EVENT, // sesexec -> sesman
E_ERCP_SESSION_RECONNECT_EVENT
E_ERCP_SESSION_RECONNECT_EVENT // sesman -> sesexec
};
/* Common facilities */
@@ -225,8 +225,6 @@ ercp_get_session_announce_event(struct trans *trans,
int
ercp_send_session_finished_event(struct trans *trans);
/**
* Send an E_ERCP_SESSION_RECONNECT_EVENT
*
+1
View File
@@ -69,6 +69,7 @@ scp_screate_status_to_str(enum scp_screate_status n,
(n == E_SCP_SCREATE_NO_DISPLAY) ? "No X displays are available" :
(n == E_SCP_SCREATE_X_SERVER_FAIL) ? "X server could not be started" :
(n == E_SCP_SCREATE_SESSION_FAIL) ? "Session failed immediately" :
(n == E_SCP_SCREATE_IN_PROGRESS) ? "Session creation is already in progress" :
(n == E_SCP_SCREATE_GENERAL_ERROR) ? "General session creation error" :
/* Default */ NULL;
+1
View File
@@ -99,6 +99,7 @@ enum scp_screate_status
E_SCP_SCREATE_NO_DISPLAY, ///< No X server display number is available
E_SCP_SCREATE_X_SERVER_FAIL, ///< X server could not be started
E_SCP_SCREATE_SESSION_FAIL, ///< The session failed quickly
E_SCP_SCREATE_IN_PROGRESS, ///< A create session request is in progress
E_SCP_SCREATE_GENERAL_ERROR ///< An unspecific error has occurred
};