2012-09-20 07:51:34 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
|
|
|
* Copyright (C) Jay Sorg 2004-2012
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-05-07 01:02:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @file libscp_v0.c
|
|
|
|
* @brief libscp version 0 code
|
|
|
|
* @author Simone Fedele
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2007-05-07 01:02:25 +04:00
|
|
|
#include "libscp_v0.h"
|
|
|
|
|
|
|
|
#include "os_calls.h"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2008-07-30 14:58:30 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
extern struct log_config *s_log;
|
2008-07-30 14:58:30 +04:00
|
|
|
|
2020-06-12 11:56:47 +03:00
|
|
|
/** Maximum length of a string (two bytes + len), excluding the terminator
|
|
|
|
*
|
|
|
|
* Practially this is limited by [MS-RDPBCGR] TS_INFO_PACKET
|
|
|
|
* */
|
|
|
|
#define STRING16_MAX_LEN 512
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a big-endian uint16 followed by a string into a buffer
|
|
|
|
*
|
|
|
|
* Buffer is null-terminated on success
|
|
|
|
*
|
|
|
|
* @param s Input stream
|
|
|
|
* @param [out] Output buffer (must be >= (STRING16_MAX_LEN+1) chars)
|
|
|
|
* @param param Parameter we're reading
|
|
|
|
* @return != 0 if string read OK
|
|
|
|
*/
|
|
|
|
static
|
2020-10-08 04:55:08 +03:00
|
|
|
int in_string16(struct stream *s, char str[], const char *param)
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (!s_check_rem(s, 2))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: %s len missing", param);
|
2020-06-12 11:56:47 +03:00
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned int sz;
|
|
|
|
|
|
|
|
in_uint16_be(s, sz);
|
|
|
|
if (sz > STRING16_MAX_LEN)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING,
|
2020-11-30 03:36:20 +03:00
|
|
|
"connection aborted: %s too long (%u chars)", param, sz);
|
2020-06-12 11:56:47 +03:00
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = s_check_rem(s, sz);
|
|
|
|
if (!result)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: %s data missing", param);
|
2020-06-12 11:56:47 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
in_uint8a(s, str, sz);
|
|
|
|
str[sz] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2007-05-07 01:02:25 +04:00
|
|
|
/* client API */
|
2020-06-10 11:20:27 +03:00
|
|
|
#if 0
|
2007-05-07 01:02:25 +04:00
|
|
|
/******************************************************************************/
|
2020-06-10 11:20:27 +03:00
|
|
|
static enum SCP_CLIENT_STATES_E
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_v0c_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
tui32 version;
|
2020-06-29 13:22:13 +03:00
|
|
|
int size;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui16 sz;
|
|
|
|
|
|
|
|
init_stream(c->in_s, c->in_s->size);
|
|
|
|
init_stream(c->out_s, c->in_s->size);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "starting connection");
|
2012-09-20 07:51:34 +04:00
|
|
|
g_tcp_set_non_blocking(c->in_sck);
|
|
|
|
g_tcp_set_no_delay(c->in_sck);
|
|
|
|
s_push_layer(c->out_s, channel_hdr, 8);
|
|
|
|
|
|
|
|
/* code */
|
|
|
|
if (s->type == SCP_SESSION_TYPE_XVNC)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint16_be(c->out_s, 0);
|
|
|
|
}
|
|
|
|
else if (s->type == SCP_SESSION_TYPE_XRDP)
|
|
|
|
{
|
|
|
|
out_uint16_be(c->out_s, 10);
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2014-03-09 04:41:37 +04:00
|
|
|
else if (s->type == SCP_SESSION_TYPE_XORG)
|
|
|
|
{
|
|
|
|
out_uint16_be(c->out_s, 20);
|
2014-05-10 03:02:19 +04:00
|
|
|
}
|
2007-05-07 01:02:25 +04:00
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: network error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
sz = g_strlen(s->username);
|
2020-06-12 11:56:47 +03:00
|
|
|
if (sz > STRING16_MAX_LEN)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: username too long");
|
2020-06-12 11:56:47 +03:00
|
|
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint16_be(c->out_s, sz);
|
|
|
|
out_uint8a(c->out_s, s->username, sz);
|
|
|
|
|
|
|
|
sz = g_strlen(s->password);
|
2020-06-12 11:56:47 +03:00
|
|
|
if (sz > STRING16_MAX_LEN)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: password too long");
|
2020-06-12 11:56:47 +03:00
|
|
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint16_be(c->out_s, sz);
|
|
|
|
out_uint8a(c->out_s, s->password, sz);
|
|
|
|
out_uint16_be(c->out_s, s->width);
|
|
|
|
out_uint16_be(c->out_s, s->height);
|
|
|
|
out_uint16_be(c->out_s, s->bpp);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
s_mark_end(c->out_s);
|
|
|
|
s_pop_layer(c->out_s, channel_hdr);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* version */
|
|
|
|
out_uint32_be(c->out_s, 0);
|
|
|
|
/* size */
|
|
|
|
out_uint32_be(c->out_s, c->out_s->end - c->out_s->data);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: network error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: network error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
in_uint32_be(c->in_s, version);
|
|
|
|
|
|
|
|
if (0 != version)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: version error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint32_be(c->in_s, size);
|
|
|
|
|
2020-06-12 11:56:47 +03:00
|
|
|
if (size < (8 + 2 + 2 + 2) || size > SCP_MAX_MESSAGE_SIZE)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: msg size = %d", size);
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* getting payload */
|
2020-06-12 11:56:47 +03:00
|
|
|
init_stream(c->in_s, size - 8);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: network error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2020-06-12 11:56:47 +03:00
|
|
|
c->in_s->end = c->in_s->data + (size - 8);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* check code */
|
2008-07-30 14:58:30 +04:00
|
|
|
in_uint16_be(c->in_s, sz);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (3 != sz)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: sequence error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* message payload */
|
2007-05-07 01:02:25 +04:00
|
|
|
in_uint16_be(c->in_s, sz);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (1 != sz)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: connection denied");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
|
|
|
}
|
|
|
|
|
2008-07-30 14:58:30 +04:00
|
|
|
in_uint16_be(c->in_s, sz);
|
2012-09-20 07:51:34 +04:00
|
|
|
s->display = sz;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "connection terminated");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_END;
|
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* server API */
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-12 11:56:47 +03:00
|
|
|
/**
|
|
|
|
* Initialises a V0 session object
|
|
|
|
*
|
|
|
|
* At the time of the call, the version has been read from the connection
|
|
|
|
*
|
|
|
|
* @param c Connection
|
|
|
|
* @param [out] session pre-allocated session object
|
|
|
|
* @return SCP_SERVER_STATE_OK for success
|
|
|
|
*/
|
2021-06-22 15:38:46 +03:00
|
|
|
enum SCP_SERVER_STATES_E
|
|
|
|
scp_v0s_accept(struct trans *atrans, struct SCP_SESSION *session)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-06-12 11:56:47 +03:00
|
|
|
tui16 height;
|
|
|
|
tui16 width;
|
|
|
|
tui16 bpp;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui32 code = 0;
|
2020-06-12 11:56:47 +03:00
|
|
|
char buf[STRING16_MAX_LEN + 1];
|
2020-06-10 11:20:27 +03:00
|
|
|
struct stream *in_s = atrans->in_s;
|
2021-06-22 15:38:46 +03:00
|
|
|
int session_type = -1;
|
2020-06-12 11:56:47 +03:00
|
|
|
scp_session_set_version(session, 0);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!s_check_rem(in_s, 6))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
2020-08-07 23:56:54 +03:00
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
2020-06-12 11:56:47 +03:00
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
in_uint8s(in_s, 4); /* size */
|
|
|
|
in_uint16_be(in_s, code);
|
|
|
|
if ((code == 0) || (code == 10) || (code == 20))
|
2009-08-19 11:27:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (code == 0)
|
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
session_type = SCP_SESSION_TYPE_XVNC;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2014-03-09 04:41:37 +04:00
|
|
|
else if (code == 10)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
session_type = SCP_SESSION_TYPE_XRDP;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2021-06-22 15:38:46 +03:00
|
|
|
else
|
2014-03-09 04:41:37 +04:00
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
session_type = SCP_SESSION_TYPE_XORG;
|
2014-05-10 03:02:19 +04:00
|
|
|
}
|
2021-06-22 15:38:46 +03:00
|
|
|
scp_session_set_type(session, session_type);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* reading username */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "username"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 != scp_session_set_username(session, buf))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: error setting username");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reading password */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "passwd"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 != scp_session_set_password(session, buf))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: error setting password");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
|
|
}
|
2020-06-12 11:56:47 +03:00
|
|
|
|
|
|
|
/* width + height + bpp */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!s_check_rem(in_s, 2 + 2 + 2))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: width+height+bpp missing");
|
2020-06-12 11:56:47 +03:00
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
in_uint16_be(in_s, width);
|
2020-06-12 11:56:47 +03:00
|
|
|
scp_session_set_width(session, width);
|
2020-06-10 11:20:27 +03:00
|
|
|
in_uint16_be(in_s, height);
|
2020-06-12 11:56:47 +03:00
|
|
|
scp_session_set_height(session, height);
|
2020-06-10 11:20:27 +03:00
|
|
|
in_uint16_be(in_s, bpp);
|
2021-06-22 15:38:46 +03:00
|
|
|
if (session_type == SCP_SESSION_TYPE_XORG && bpp != 24)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_WARNING,
|
|
|
|
"Setting bpp to 24 from %d for Xorg session", bpp);
|
|
|
|
bpp = 24;
|
|
|
|
}
|
2020-06-12 11:56:47 +03:00
|
|
|
if (0 != scp_session_set_bpp(session, (tui8)bpp))
|
2016-02-10 12:14:40 +03:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING,
|
2020-11-30 03:36:20 +03:00
|
|
|
"connection aborted: unsupported bpp: %d", (tui8)bpp);
|
2016-02-10 12:14:40 +03:00
|
|
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
if (s_check_rem(in_s, 2))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
/* reading domain */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "domain"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2020-08-07 23:56:54 +03:00
|
|
|
|
2020-06-12 11:56:47 +03:00
|
|
|
if (buf[0] != '\0')
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
scp_session_set_domain(session, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
if (s_check_rem(in_s, 2))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
/* reading program */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "program"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-12 11:56:47 +03:00
|
|
|
if (buf[0] != '\0')
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
scp_session_set_program(session, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
if (s_check_rem(in_s, 2))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
/* reading directory */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "directory"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-12 11:56:47 +03:00
|
|
|
if (buf[0] != '\0')
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
scp_session_set_directory(session, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
if (s_check_rem(in_s, 2))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
/* reading client IP address */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "client IP"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
|
|
|
if (buf[0] != '\0')
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
scp_session_set_client_ip(session, buf);
|
|
|
|
}
|
|
|
|
}
|
2009-08-19 11:27:35 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (code == SCP_GW_AUTHENTICATION)
|
2010-11-04 14:14:03 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_type(session, SCP_GW_AUTHENTICATION);
|
|
|
|
/* reading username */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "username"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (0 != scp_session_set_username(session, buf))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: error setting username");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reading password */
|
2020-06-10 11:20:27 +03:00
|
|
|
if (!in_string16(in_s, buf, "passwd"))
|
2020-06-12 11:56:47 +03:00
|
|
|
{
|
|
|
|
return SCP_SERVER_STATE_SIZE_ERR;
|
|
|
|
}
|
2012-05-31 18:57:17 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 != scp_session_set_password(session, buf))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: error setting password");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
|
|
}
|
2012-05-31 18:57:17 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
2012-05-31 18:57:17 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: sequence error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
2012-06-24 02:35:27 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return SCP_SERVER_STATE_OK;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2009-08-19 11:27:35 +04:00
|
|
|
enum SCP_SERVER_STATES_E
|
2020-06-10 11:20:27 +03:00
|
|
|
scp_v0s_allow_connection(struct trans *atrans, SCP_DISPLAY d, const tui8 *guid)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2016-12-04 10:12:48 +03:00
|
|
|
int msg_size;
|
2020-06-10 11:20:27 +03:00
|
|
|
struct stream *out_s;
|
2016-12-04 10:12:48 +03:00
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
out_s = trans_get_out_s(atrans, 0);
|
2016-12-04 10:12:48 +03:00
|
|
|
msg_size = guid == 0 ? 14 : 14 + 16;
|
2020-06-10 11:20:27 +03:00
|
|
|
out_uint32_be(out_s, 0); /* version */
|
|
|
|
out_uint32_be(out_s, msg_size); /* size */
|
|
|
|
out_uint16_be(out_s, 3); /* cmd */
|
|
|
|
out_uint16_be(out_s, 1); /* data */
|
|
|
|
out_uint16_be(out_s, d); /* data */
|
2016-12-04 10:12:48 +03:00
|
|
|
if (msg_size > 14)
|
|
|
|
{
|
2020-06-10 11:20:27 +03:00
|
|
|
out_uint8a(out_s, guid, 16);
|
2016-12-04 10:12:48 +03:00
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
s_mark_end(out_s);
|
|
|
|
if (0 != trans_write_copy(atrans))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: network error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "connection terminated (allowed)");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_OK;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2009-08-19 11:27:35 +04:00
|
|
|
enum SCP_SERVER_STATES_E
|
2020-06-10 11:20:27 +03:00
|
|
|
scp_v0s_deny_connection(struct trans *atrans)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2020-06-10 11:20:27 +03:00
|
|
|
struct stream *out_s;
|
|
|
|
|
|
|
|
out_s = trans_get_out_s(atrans, 0);
|
|
|
|
out_uint32_be(out_s, 0); /* version */
|
|
|
|
out_uint32_be(out_s, 14); /* size */
|
|
|
|
out_uint16_be(out_s, 3); /* cmd */
|
|
|
|
out_uint16_be(out_s, 0); /* data = 0 - means NOT ok*/
|
|
|
|
out_uint16_be(out_s, 0); /* reserved for display number*/
|
|
|
|
s_mark_end(out_s);
|
|
|
|
if (0 != trans_write_copy(atrans))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: network error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "connection terminated (denied)");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_OK;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2012-05-31 18:57:17 +04:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
enum SCP_SERVER_STATES_E
|
2020-06-10 11:20:27 +03:00
|
|
|
scp_v0s_replyauthentication(struct trans *atrans, unsigned short int value)
|
2012-05-31 18:57:17 +04:00
|
|
|
{
|
2020-06-10 11:20:27 +03:00
|
|
|
struct stream *out_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
out_s = trans_get_out_s(atrans, 0);
|
|
|
|
out_uint32_be(out_s, 0); /* version */
|
|
|
|
out_uint32_be(out_s, 14); /* size */
|
|
|
|
/* cmd SCP_GW_AUTHENTICATION means authentication reply */
|
|
|
|
out_uint16_be(out_s, SCP_GW_AUTHENTICATION);
|
|
|
|
out_uint16_be(out_s, value); /* reply code */
|
|
|
|
out_uint16_be(out_s, 0); /* dummy data */
|
|
|
|
s_mark_end(out_s);
|
|
|
|
if (0 != trans_write_copy(atrans))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "connection aborted: network error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "connection terminated (scp_v0s_deny_authentication)");
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_SERVER_STATE_OK;
|
2012-05-31 18:57:17 +04:00
|
|
|
}
|