Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move scp to standard transport #1925

Merged
merged 7 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ trans_connect(struct trans *self, const char *server, const char *port,
* @return 0 on success, 1 on failure
*/
int
trans_listen_address(struct trans *self, char *port, const char *address)
trans_listen_address(struct trans *self, const char *port, const char *address)
{
if (self->sck != 0)
{
Expand Down Expand Up @@ -929,7 +929,7 @@ trans_listen_address(struct trans *self, char *port, const char *address)

/*****************************************************************************/
int
trans_listen(struct trans *self, char *port)
trans_listen(struct trans *self, const char *port)
{
return trans_listen_address(self, port, "0.0.0.0");
}
Expand Down
4 changes: 2 additions & 2 deletions common/trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ int
trans_connect(struct trans *self, const char *server, const char *port,
int timeout);
int
trans_listen_address(struct trans *self, char *port, const char *address);
trans_listen_address(struct trans *self, const char *port, const char *address);
int
trans_listen(struct trans *self, char *port);
trans_listen(struct trans *self, const char *port);
struct stream *
trans_get_in_s(struct trans *self);
struct stream *
Expand Down
3 changes: 2 additions & 1 deletion sesman/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ env_set_user(const char *username, char **passwd_file, int display,
g_sprintf(text, ":%d.0", display);
g_setenv("DISPLAY", text, 1);
g_setenv("XRDP_SESSION", "1", 1);
/* XRDP_SOCKET_PATH should be set even here, chansrv uses this */
/* XRDP_SOCKET_PATH should be set even here. It's used by
* xorgxrdp and the pulseaudio plugin */
g_setenv("XRDP_SOCKET_PATH", XRDP_SOCKET_PATH, 1);
/* pulse sink socket */
g_snprintf(text, sizeof(text) - 1, CHANSRV_PORT_OUT_BASE_STR, display);
Expand Down
24 changes: 22 additions & 2 deletions sesman/libscp/libscp_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 6 additions & 24 deletions sesman/libscp/libscp_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,14 @@

//extern struct log_config* s_log;

struct SCP_CONNECTION *
scp_connection_create(int sck)
struct trans *
scp_trans_create(int sck)
{
struct SCP_CONNECTION *conn;

conn = g_new(struct SCP_CONNECTION, 1);

if (0 == conn)
struct trans *result = trans_create(TRANS_MODE_TCP, 8192, 8192);
if (result != NULL)
{
LOG(LOG_LEVEL_ERROR, "[connection:%d] connection create: malloc error", __LINE__);
return 0;
result->sck = sck;
}

conn->in_sck = sck;
make_stream(conn->in_s);
init_stream(conn->in_s, 8196);
make_stream(conn->out_s);
init_stream(conn->out_s, 8196);

return conn;
}

void
scp_connection_destroy(struct SCP_CONNECTION *c)
{
free_stream(c->in_s);
free_stream(c->out_s);
g_free(c);
return result;
}
18 changes: 7 additions & 11 deletions sesman/libscp/libscp_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,18 @@

/**
*
* @brief creates a new connection
* @brief creates a new SCP transport object
* @param sck the connection socket
*
* @return a struct SCP_CONNECTION* object on success, NULL otherwise
* This is a convenience function which calls trans_create() with the
* correct parameters.
*
*/
struct SCP_CONNECTION *
scp_connection_create(int sck);

/**
* Returned object can be freed with trans_delete()
*
* @brief destroys a struct SCP_CONNECTION* object
* @param c the object to be destroyed
* @return a struct trans* object on success, NULL otherwise
*
*/
void
scp_connection_destroy(struct SCP_CONNECTION *c);
struct trans *
scp_trans_create(int sck);

#endif
69 changes: 51 additions & 18 deletions sesman/libscp/libscp_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ scp_session_set_type(struct SCP_SESSION *s, tui8 type)

case SCP_SESSION_TYPE_MANAGE:
s->type = SCP_SESSION_TYPE_MANAGE;
s->mng = (struct SCP_MNG_DATA *)g_malloc(sizeof(struct SCP_MNG_DATA), 1);

if (NULL == s->mng)
{
LOG(LOG_LEVEL_ERROR, "[session:%d] set_type: internal error", __LINE__);
return 1;
}

break;

default:
Expand Down Expand Up @@ -439,14 +431,55 @@ scp_session_set_guid(struct SCP_SESSION *s, const tui8 *guid)
void
scp_session_destroy(struct SCP_SESSION *s)
{
g_free(s->username);
g_free(s->password);
g_free(s->hostname);
g_free(s->domain);
g_free(s->program);
g_free(s->directory);
g_free(s->client_ip);
g_free(s->errstr);
g_free(s->mng);
g_free(s);
if (s != NULL)
{
g_free(s->username);
g_free(s->password);
g_free(s->hostname);
g_free(s->domain);
g_free(s->program);
g_free(s->directory);
g_free(s->client_ip);
g_free(s->errstr);
g_free(s);
}
}

/*******************************************************************/
struct SCP_SESSION *
scp_session_clone(const struct SCP_SESSION *s)
{
struct SCP_SESSION *result = NULL;

if (s != NULL && (result = g_new(struct SCP_SESSION, 1)) != NULL)
{
/* Duplicate all the scalar variables */
g_memcpy(result, s, sizeof(*s));

/* Now duplicate all the strings */
result->username = g_strdup(s->username);
result->password = g_strdup(s->password);
result->hostname = g_strdup(s->hostname);
result->errstr = g_strdup(s->errstr);
result->domain = g_strdup(s->domain);
result->program = g_strdup(s->program);
result->directory = g_strdup(s->directory);
result->client_ip = g_strdup(s->client_ip);

/* Did all the string copies succeed? */
if ((s->username != NULL && result->username == NULL) ||
(s->password != NULL && result->password == NULL) ||
(s->hostname != NULL && result->hostname == NULL) ||
(s->errstr != NULL && result->errstr == NULL) ||
(s->domain != NULL && result->domain == NULL) ||
(s->program != NULL && result->program == NULL) ||
(s->directory != NULL && result->directory == NULL) ||
(s->client_ip != NULL && result->client_ip == NULL))
{
scp_session_destroy(result);
result = NULL;
}
}

return result;
}
8 changes: 8 additions & 0 deletions sesman/libscp/libscp_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
struct SCP_SESSION *
scp_session_create(void);

/*
* Makes a copy of a struct SCP_SESSION object
* @param s Object to clone
* @return a copy of s, or NULL if no memory
*/
struct SCP_SESSION *
scp_session_clone(const struct SCP_SESSION *s);

int
scp_session_set_type(struct SCP_SESSION *s, tui8 type);

Expand Down
14 changes: 6 additions & 8 deletions sesman/libscp/libscp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "parse.h"
#include "arch.h"
#include "log.h"
#include "trans.h"

#define SCP_SID tui32
#define SCP_DISPLAY tui16
Expand Down Expand Up @@ -63,13 +64,6 @@
exhaustion attempts (CVE-2020-4044) */
#define SCP_MAX_MESSAGE_SIZE 8192

struct SCP_CONNECTION
{
int in_sck;
struct stream *in_s;
struct stream *out_s;
};

struct SCP_SESSION
{
tui8 type;
Expand All @@ -87,12 +81,16 @@ struct SCP_SESSION
tui8 ipv6addr[16];
SCP_DISPLAY display;
char *errstr;
struct SCP_MNG_DATA *mng;
char *domain;
char *program;
char *directory;
char *client_ip;
tui8 guid[16];
/* added for state */
int current_cmd;
int return_sid;
int retries;
int current_try;
};

struct SCP_DISCONNECTED_SESSION
Expand Down
Loading