Address review comments

This commit is contained in:
matt335672 2021-07-19 10:21:20 +01:00
parent d4c81229ba
commit 5c9839a7f4
6 changed files with 74 additions and 49 deletions

View File

@ -29,7 +29,27 @@
#include "libscp_commands_mng.h"
#define SCP_CMD_LOGIN 0x0001
#define SCP_CMD_CONN_ERROR 0xFFFF
/* Message numbers
* SCP_CMD_* are client to server, SCP_REPLY_* are server to client */
/* Login sequence */
#define SCP_CMD_LOGIN 1
#define SCP_REPLY_LOGIN_DENIED 2
#define SCP_REPLY_REREQUEST_CREDS 3
#define SCP_CMD_RESEND_CREDS 4
#define SCP_REPLY_CHANGE_PASSWD 20
#define SCP_REPLY_NEW_SESSION 30
#define SCP_REPLY_USER_SESSIONS_EXIST 40
/* List sessions */
#define SCP_CMD_GET_SESSION_LIST 41
#define SCP_REPLY_SESSIONS_INFO 42
#define SCP_CMD_SELECT_SESSION 43
#define SCP_CMD_SELECT_SESSION_CANCEL 44
/* Other */
#define SCP_CMD_FORCE_NEW_CONN 45
#define SCP_REPLY_SESSION_RECONNECTED 46
#define SCP_REPLY_CMD_CONN_ERROR 0xFFFF
#endif

View File

@ -38,7 +38,6 @@ static enum SCP_CLIENT_STATES_E
_scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s);
/* client API */
/* 001 */
enum SCP_CLIENT_STATES_E
scp_v1c_connect(struct trans *t, struct SCP_SESSION *s)
{
@ -66,7 +65,7 @@ scp_v1c_connect(struct trans *t, struct SCP_SESSION *s)
out_uint32_be(out_s, 1); /* version */
out_uint32_be(out_s, size);
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, 1);
out_uint16_be(out_s, SCP_CMD_LOGIN);
/* body */
out_uint8(out_s, s->type);
@ -106,7 +105,6 @@ scp_v1c_connect(struct trans *t, struct SCP_SESSION *s)
return _scp_v1c_check_response(t, s);
}
/* 004 */
enum SCP_CLIENT_STATES_E
scp_v1c_resend_credentials(struct trans *t, struct SCP_SESSION *s)
{
@ -123,7 +121,7 @@ scp_v1c_resend_credentials(struct trans *t, struct SCP_SESSION *s)
out_uint32_be(out_s, 1); /* version */
out_uint32_be(out_s, size);
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, 4);
out_uint16_be(out_s, SCP_CMD_RESEND_CREDS);
/* body */
sz = g_strlen(s->username);
@ -143,7 +141,6 @@ scp_v1c_resend_credentials(struct trans *t, struct SCP_SESSION *s)
return _scp_v1c_check_response(t, s);
}
/* 041 */
enum SCP_CLIENT_STATES_E
scp_v1c_get_session_list(struct trans *t, int *scount,
struct SCP_DISCONNECTED_SESSION **s)
@ -152,7 +149,7 @@ scp_v1c_get_session_list(struct trans *t, int *scount,
struct stream *out_s = t->out_s;
tui32 version = 1;
int size = 12;
tui16 cmd = 41;
tui16 cmd = SCP_CMD_GET_SESSION_LIST;
tui32 sescnt = 0; /* total session number */
tui32 sestmp = 0; /* additional total session number */
tui8 pktcnt = 0; /* packet session count */
@ -221,7 +218,7 @@ scp_v1c_get_session_list(struct trans *t, int *scount,
in_uint16_be(in_s, cmd);
if (cmd != 42)
if (cmd != SCP_REPLY_SESSIONS_INFO)
{
g_free(ds);
return SCP_CLIENT_STATE_SEQUENCE_ERR;
@ -288,7 +285,6 @@ scp_v1c_get_session_list(struct trans *t, int *scount,
return SCP_CLIENT_STATE_LIST_OK;
}
/* 043 */
enum SCP_CLIENT_STATES_E
scp_v1c_select_session(struct trans *t, struct SCP_SESSION *s,
SCP_SID sid)
@ -297,7 +293,7 @@ scp_v1c_select_session(struct trans *t, struct SCP_SESSION *s,
struct stream *out_s = t->out_s;
tui32 version = 1;
int size = 16;
tui16 cmd = 43;
tui16 cmd = SCP_CMD_SELECT_SESSION;
init_stream(out_s, 64);
@ -354,7 +350,7 @@ scp_v1c_select_session(struct trans *t, struct SCP_SESSION *s,
in_uint16_be(in_s, cmd);
if (cmd != 46)
if (cmd != SCP_REPLY_SESSION_RECONNECTED)
{
return SCP_CLIENT_STATE_SEQUENCE_ERR;
}
@ -367,14 +363,13 @@ scp_v1c_select_session(struct trans *t, struct SCP_SESSION *s,
return SCP_CLIENT_STATE_OK;
}
/* 044 */
enum SCP_CLIENT_STATES_E
scp_v1c_select_session_cancel(struct trans *t)
{
struct stream *out_s = t->out_s;
tui32 version = 1;
tui32 size = 12;
tui16 cmd = 44;
tui16 cmd = SCP_CMD_SELECT_SESSION_CANCEL;
init_stream(out_s, 64);
@ -435,7 +430,7 @@ _scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s)
in_uint16_be(in_s, cmd);
if (cmd == 2) /* connection denied */
if (cmd == SCP_REPLY_LOGIN_DENIED)
{
in_uint16_be(in_s, dim);
@ -456,7 +451,7 @@ _scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s)
return SCP_CLIENT_STATE_CONNECTION_DENIED;
}
else if (cmd == 3) /* resend usr/pwd */
else if (cmd == SCP_REPLY_REREQUEST_CREDS)
{
in_uint16_be(in_s, dim);
@ -477,7 +472,7 @@ _scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s)
return SCP_CLIENT_STATE_RESEND_CREDENTIALS;
}
else if (cmd == 20) /* password change */
else if (cmd == SCP_REPLY_CHANGE_PASSWD)
{
in_uint16_be(in_s, dim);
@ -498,7 +493,7 @@ _scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s)
return SCP_CLIENT_STATE_PWD_CHANGE_REQ;
}
else if (cmd == 30) /* display */
else if (cmd == SCP_REPLY_NEW_SESSION)
{
in_uint16_be(in_s, s->display);
@ -512,7 +507,7 @@ _scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s)
//{
// return SCP_CLIENT_STATE_RECONNECT;
//}
else if (cmd == 40) /* session list */
else if (cmd == SCP_REPLY_USER_SESSIONS_EXIST) /* session list */
{
return SCP_CLIENT_STATE_SESSION_LIST;
}

View File

@ -256,14 +256,14 @@ scp_v1s_accept(struct trans *t, struct SCP_SESSION *s)
switch (cmd)
{
case 1:
case SCP_CMD_LOGIN:
s->current_cmd = cmd;
result = scp_v1s_init_session(t, s);
break;
case 4:
case SCP_CMD_RESEND_CREDS:
result = scp_v1s_accept_password_reply(t, s);
s->current_cmd = 1; /* Caller re-parses credentials */
s->current_cmd = SCP_CMD_LOGIN; /* Caller re-parses credentials */
break;
default:
@ -293,7 +293,7 @@ scp_v1s_deny_connection(struct trans *t, const char *reason)
/* version + size + cmdset + cmd + msglen + msg */
out_uint32_be(out_s, rlen + 14);
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, 2);
out_uint16_be(out_s, SCP_REPLY_LOGIN_DENIED);
out_uint16_be(out_s, rlen);
out_uint8p(out_s, reason, rlen);
s_mark_end(out_s);
@ -324,7 +324,7 @@ scp_v1s_request_password(struct trans *t, struct SCP_SESSION *s,
/* version + size + cmdset + cmd + msglen + msg */
out_uint32_be(out_s, rlen + 14);
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, 3);
out_uint16_be(out_s, SCP_REPLY_REREQUEST_CREDS);
out_uint16_be(out_s, rlen);
out_uint8p(out_s, reason, rlen);
s_mark_end(out_s);
@ -374,21 +374,18 @@ scp_v1s_accept_password_reply(struct trans *t, struct SCP_SESSION *s)
return SCP_SERVER_STATE_OK;
}
/* 020 */
enum SCP_SERVER_STATES_E
scp_v1s_request_pwd_change(struct trans *t, char *reason, char *npw)
{
return SCP_SERVER_STATE_INTERNAL_ERR;
}
/* 023 */
enum SCP_SERVER_STATES_E
scp_v1s_pwd_change_error(struct trans *t, char *error, int retry, char *npw)
{
return SCP_SERVER_STATE_INTERNAL_ERR;
}
/* 030 */
enum SCP_SERVER_STATES_E
scp_v1s_connect_new_session(struct trans *t, SCP_DISPLAY d)
{
@ -400,7 +397,7 @@ scp_v1s_connect_new_session(struct trans *t, SCP_DISPLAY d)
/* version + size + cmdset + cmd + msglen + msg */
out_uint32_be(out_s, 14);
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, 30);
out_uint16_be(out_s, SCP_REPLY_NEW_SESSION);
out_uint16_be(out_s, d);
s_mark_end(out_s);
if (0 != trans_force_write(t))
@ -411,7 +408,6 @@ scp_v1s_connect_new_session(struct trans *t, SCP_DISPLAY d)
return SCP_SERVER_STATE_OK;
}
/* 032 */
enum SCP_SERVER_STATES_E
scp_v1s_connection_error(struct trans *t, const char *error)
{
@ -429,7 +425,7 @@ scp_v1s_connection_error(struct trans *t, const char *error)
/* version + size + cmdset + cmd */
out_uint32_be(out_s, 12 + len);
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, SCP_CMD_CONN_ERROR);
out_uint16_be(out_s, SCP_REPLY_CMD_CONN_ERROR);
out_uint8a(out_s, error, len);
s_mark_end(out_s);
if (0 != trans_force_write(t))
@ -439,7 +435,6 @@ scp_v1s_connection_error(struct trans *t, const char *error)
return SCP_SERVER_STATE_END;
}
/* 040 */
#if 0
enum SCP_SERVER_STATES_E
scp_v1s_list_sessions(struct SCP_CONNECTION *c, int sescnt, struct SCP_DISCONNECTED_SESSION *ds, SCP_SID *sid)
@ -719,7 +714,7 @@ scp_v1s_list_sessions40(struct trans *t)
out_uint32_be(out_s, 1); /* version */
out_uint32_be(out_s, 12); /* size */
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
out_uint16_be(out_s, 40); /* cmd */
out_uint16_be(out_s, SCP_REPLY_USER_SESSIONS_EXIST);/* cmd */
s_mark_end(out_s);
if (0 != trans_force_write(t))
{
@ -757,7 +752,7 @@ scp_v1s_list_sessions42(struct trans *t, int sescnt, struct SCP_DISCONNECTED_SES
/* header */
s_push_layer(out_s, channel_hdr, 8);
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, 42);
out_uint16_be(out_s, SCP_REPLY_SESSIONS_INFO);
/* session count */
out_uint32_be(out_s, sescnt);
@ -845,14 +840,14 @@ scp_v1s_accept_list_sessions_reply(int cmd, struct trans *t)
in_s = t->in_s;
switch (cmd)
{
case 41:
case SCP_CMD_GET_SESSION_LIST:
break;
case 43:
case SCP_CMD_SELECT_SESSION:
in_uint32_be(in_s, s->return_sid);
break;
case 44:
case SCP_CMD_SELECT_SESSION_CANCEL:
break;
case 45:
case SCP_CMD_FORCE_NEW_CONN:
break;
default:
break;
@ -860,7 +855,6 @@ scp_v1s_accept_list_sessions_reply(int cmd, struct trans *t)
return SCP_SERVER_STATE_OK;
}
/* 046 was: 031 struct SCP_DISCONNECTED_SESSION* ds, */
enum SCP_SERVER_STATES_E
scp_v1s_reconnect_session(struct trans *t, SCP_DISPLAY d)
{
@ -872,7 +866,7 @@ scp_v1s_reconnect_session(struct trans *t, SCP_DISPLAY d)
out_uint32_be(out_s, 1); /* version */
out_uint32_be(out_s, 14); /* size */
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(out_s, 46); /* cmd */
out_uint16_be(out_s, SCP_REPLY_SESSION_RECONNECTED); /* cmd */
/* session data */
out_uint16_be(out_s, d); /* session display */
s_mark_end(out_s);

View File

@ -1,3 +1,11 @@
************************************************************
** Notes on the current version of the SCP protocol used **
** to communicate with sesman **
** **
** This information is for internal documentational use **
** only. It may be incomplete. The SCP protocol is **
** internal, and may change for even minor releases. **
************************************************************
message header

View File

@ -191,7 +191,7 @@ scp_v1_process41(struct trans *t, struct SCP_SESSION *s)
e = scp_v1s_list_sessions42(t, scount, slist);
if (SCP_SERVER_STATE_OK != e)
{
LOG(LOG_LEVEL_ERROR, "scp_v1s_list_sessions42 failed");
LOG(LOG_LEVEL_WARNING, "scp_v1s_list_sessions42 failed");
}
return SCP_SERVER_STATE_OK;
@ -209,7 +209,7 @@ scp_v1_process43(struct trans *t, struct SCP_SESSION *s)
if (0 == sitem)
{
e = scp_v1s_connection_error(t, "Internal error");
LOG(LOG_LEVEL_INFO, "Cannot find session item on the chain");
LOG(LOG_LEVEL_INFO, "No session exists with PID %d", s->return_sid);
}
else
{
@ -253,17 +253,17 @@ scp_v1_process(struct trans *t, struct SCP_SESSION *s)
; /* astyle 3.1 needs this, or the switch is badly formatted */
switch (s->current_cmd)
{
case 1:
case SCP_CMD_LOGIN:
return scp_v1_process1(t, s);
case 4:
case SCP_CMD_RESEND_CREDS:
return scp_v1_process4(t, s);
case 41:
case SCP_CMD_GET_SESSION_LIST:
return scp_v1_process41(t, s);
case 43:
case SCP_CMD_SELECT_SESSION:
return scp_v1_process43(t, s);
case 44:
case SCP_CMD_SELECT_SESSION_CANCEL:
return scp_v1_process44(t, s);
case 45:
case SCP_CMD_FORCE_NEW_CONN:
return scp_v1_process45(t, s);
}
return SCP_SERVER_STATE_END;

View File

@ -34,6 +34,14 @@
#include "xrdp_configure_options.h"
#include "string_calls.h"
/**
* Maximum number of short-lived connections to sesman
*
* At the moment, all connections to sesman are short-lived. This may change
* in the future
*/
#define MAX_SHORT_LIVED_CONNECTIONS 16
struct sesman_startup_params
{
const char *sesman_ini;
@ -296,7 +304,7 @@ sesman_data_in(struct trans *self)
/* reset for next message */
self->header_size = 8;
self->extra_flags = 0;
init_stream(self->in_s, 0);
init_stream(self->in_s, 0); /* Reset input stream pointers */
}
return 0;
}
@ -306,7 +314,7 @@ static int
sesman_listen_conn_in(struct trans *self, struct trans *new_self)
{
struct sesman_con *sc;
if (g_con_list->count >= 16)
if (g_con_list->count >= MAX_SHORT_LIVED_CONNECTIONS)
{
LOG(LOG_LEVEL_ERROR, "sesman_data_in: error, too many "
"connections, rejecting");