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_v1c.c
|
|
|
|
* @brief libscp version 1 client api 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_v1c.h"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2007-05-07 01:02:25 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-07-18 10:31:11 +04:00
|
|
|
static enum SCP_CLIENT_STATES_E
|
2021-06-18 13:48:05 +03:00
|
|
|
_scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
|
|
|
/* client API */
|
|
|
|
/* 001 */
|
2007-07-18 10:31:11 +04:00
|
|
|
enum SCP_CLIENT_STATES_E
|
2021-06-18 13:48:05 +03:00
|
|
|
scp_v1c_connect(struct trans *t, struct SCP_SESSION *s)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
tui8 sz;
|
2021-06-18 13:48:05 +03:00
|
|
|
int size;
|
|
|
|
struct stream *out_s = t->out_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
size = (19 + 17 + 4 + g_strlen(s->hostname) + g_strlen(s->username) +
|
|
|
|
g_strlen(s->password));
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
|
|
|
{
|
|
|
|
size = size + 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size = size + 16;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(out_s, size);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* sending request */
|
|
|
|
|
|
|
|
/* header */
|
2021-06-18 13:48:05 +03:00
|
|
|
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);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* body */
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint8(out_s, s->type);
|
|
|
|
out_uint16_be(out_s, s->height);
|
|
|
|
out_uint16_be(out_s, s->width);
|
|
|
|
out_uint8(out_s, s->bpp);
|
|
|
|
out_uint8(out_s, s->rsr);
|
|
|
|
out_uint8p(out_s, s->locale, 17);
|
|
|
|
out_uint8(out_s, s->addr_type);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint32_be(out_s, s->ipv4addr);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (s->addr_type == SCP_ADDRESS_TYPE_IPV6)
|
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint8p(out_s, s->ipv6addr, 16);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sz = g_strlen(s->hostname);
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint8(out_s, sz);
|
|
|
|
out_uint8p(out_s, s->hostname, sz);
|
2012-09-20 07:51:34 +04:00
|
|
|
sz = g_strlen(s->username);
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint8(out_s, sz);
|
|
|
|
out_uint8p(out_s, s->username, sz);
|
2012-09-20 07:51:34 +04:00
|
|
|
sz = g_strlen(s->password);
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint8(out_s, sz);
|
|
|
|
out_uint8p(out_s, s->password, sz);
|
|
|
|
s_mark_end(out_s);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_write(t))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for response */
|
2021-06-18 13:48:05 +03:00
|
|
|
return _scp_v1c_check_response(t, s);
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 004 */
|
2007-07-18 10:31:11 +04:00
|
|
|
enum SCP_CLIENT_STATES_E
|
2021-06-18 13:48:05 +03:00
|
|
|
scp_v1c_resend_credentials(struct trans *t, struct SCP_SESSION *s)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
struct stream *out_s = t->out_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui8 sz;
|
2021-06-18 13:48:05 +03:00
|
|
|
int size;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
size = 12 + 2 + g_strlen(s->username) + g_strlen(s->password);
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(out_s, size);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* sending request */
|
|
|
|
/* header */
|
2021-06-18 13:48:05 +03:00
|
|
|
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);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* body */
|
|
|
|
sz = g_strlen(s->username);
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint8(out_s, sz);
|
|
|
|
out_uint8p(out_s, s->username, sz);
|
2012-09-20 07:51:34 +04:00
|
|
|
sz = g_strlen(s->password);
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint8(out_s, sz);
|
|
|
|
out_uint8p(out_s, s->password, sz);
|
|
|
|
s_mark_end(out_s);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_write(t))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for response */
|
2021-06-18 13:48:05 +03:00
|
|
|
return _scp_v1c_check_response(t, s);
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 041 */
|
|
|
|
enum SCP_CLIENT_STATES_E
|
2021-06-18 13:48:05 +03:00
|
|
|
scp_v1c_get_session_list(struct trans *t, int *scount,
|
2012-09-20 07:51:34 +04:00
|
|
|
struct SCP_DISCONNECTED_SESSION **s)
|
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
struct stream *in_s = t->in_s;
|
|
|
|
struct stream *out_s = t->out_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui32 version = 1;
|
2021-06-18 13:48:05 +03:00
|
|
|
int size = 12;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui16 cmd = 41;
|
|
|
|
tui32 sescnt = 0; /* total session number */
|
|
|
|
tui32 sestmp = 0; /* additional total session number */
|
|
|
|
tui8 pktcnt = 0; /* packet session count */
|
|
|
|
tui32 totalcnt = 0; /* session counter */
|
|
|
|
tui8 continued = 0; /* continue flag */
|
|
|
|
int firstpkt = 1; /* "first packet" flag */
|
|
|
|
int idx;
|
|
|
|
struct SCP_DISCONNECTED_SESSION *ds = 0;
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(out_s, 64);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* we request session list */
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint32_be(out_s, version); /* version */
|
|
|
|
out_uint32_be(out_s, size); /* size */
|
|
|
|
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
|
|
|
out_uint16_be(out_s, cmd); /* cmd */
|
|
|
|
s_mark_end(out_s);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_write(t))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* then we wait for server response */
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(in_s, 8);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_read(t, 8))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-01-17 10:13:22 +03:00
|
|
|
g_free(ds);
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(t->in_s, version);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (version != 1)
|
|
|
|
{
|
2018-01-17 10:13:22 +03:00
|
|
|
g_free(ds);
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(t->in_s, size);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (size < 12)
|
|
|
|
{
|
2018-01-17 10:13:22 +03:00
|
|
|
g_free(ds);
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(t->in_s, size - 8);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_read(t, size - 8))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-01-17 10:13:22 +03:00
|
|
|
g_free(ds);
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, cmd);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
|
|
|
{
|
2018-01-17 10:13:22 +03:00
|
|
|
g_free(ds);
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, cmd);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (cmd != 42)
|
|
|
|
{
|
2018-01-17 10:13:22 +03:00
|
|
|
g_free(ds);
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firstpkt)
|
|
|
|
{
|
|
|
|
firstpkt = 0;
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, sescnt);
|
2012-09-20 07:51:34 +04:00
|
|
|
sestmp = sescnt;
|
|
|
|
|
2016-06-22 02:30:18 +03:00
|
|
|
ds = g_new(struct SCP_DISCONNECTED_SESSION, sescnt);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (ds == 0)
|
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, sestmp);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint8(in_s, continued);
|
|
|
|
in_uint8(in_s, pktcnt);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
for (idx = 0; idx < pktcnt; idx++)
|
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, (ds[totalcnt]).SID); /* session id */
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).type);
|
|
|
|
in_uint16_be(in_s, (ds[totalcnt]).height);
|
|
|
|
in_uint16_be(in_s, (ds[totalcnt]).width);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).bpp);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).idle_days);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).idle_hours);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).idle_minutes);
|
|
|
|
|
|
|
|
in_uint16_be(in_s, (ds[totalcnt]).conn_year);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).conn_month);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).conn_day);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).conn_hour);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).conn_minute);
|
|
|
|
in_uint8(in_s, (ds[totalcnt]).addr_type);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV4)
|
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, (ds[totalcnt]).ipv4addr);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6)
|
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint8a(in_s, (ds[totalcnt]).ipv6addr, 16);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
totalcnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (continued);
|
|
|
|
|
|
|
|
printf("fine\n");
|
|
|
|
/* return data... */
|
|
|
|
(*scount) = sescnt;
|
|
|
|
(*s) = ds;
|
|
|
|
|
|
|
|
return SCP_CLIENT_STATE_LIST_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 043 */
|
|
|
|
enum SCP_CLIENT_STATES_E
|
2021-06-18 13:48:05 +03:00
|
|
|
scp_v1c_select_session(struct trans *t, struct SCP_SESSION *s,
|
2012-09-20 07:51:34 +04:00
|
|
|
SCP_SID sid)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
struct stream *in_s = t->in_s;
|
|
|
|
struct stream *out_s = t->out_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui32 version = 1;
|
2021-06-18 13:48:05 +03:00
|
|
|
int size = 16;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui16 cmd = 43;
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(out_s, 64);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* sending our selection */
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint32_be(out_s, version); /* version */
|
|
|
|
out_uint32_be(out_s, size); /* size */
|
|
|
|
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
|
|
|
out_uint16_be(out_s, cmd); /* cmd */
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint32_be(out_s, sid);
|
|
|
|
s_mark_end(out_s);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_write(t))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* waiting for response.... */
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(in_s, 8);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_read(t, 8))
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, version);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2007-07-18 10:31:11 +04:00
|
|
|
if (version != 1)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, size);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2007-07-18 10:31:11 +04:00
|
|
|
if (size < 12)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(in_s, size - 8);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* read the rest of the packet */
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_read(t, size - 8))
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, cmd);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2007-07-18 10:31:11 +04:00
|
|
|
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, cmd);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (cmd != 46)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* session display */
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, (s->display));
|
2012-09-20 07:51:34 +04:00
|
|
|
/*we don't need to return any data other than the display */
|
|
|
|
/*because we already sent that */
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_OK;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* 044 */
|
2007-05-07 01:02:25 +04:00
|
|
|
enum SCP_CLIENT_STATES_E
|
2021-06-18 13:48:05 +03:00
|
|
|
scp_v1c_select_session_cancel(struct trans *t)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
struct stream *out_s = t->out_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui32 version = 1;
|
|
|
|
tui32 size = 12;
|
|
|
|
tui16 cmd = 44;
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(out_s, 64);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* sending our selection */
|
2021-06-18 13:48:05 +03:00
|
|
|
out_uint32_be(out_s, version); /* version */
|
|
|
|
out_uint32_be(out_s, size); /* size */
|
|
|
|
out_uint16_be(out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
|
|
|
out_uint16_be(out_s, cmd); /* cmd */
|
|
|
|
s_mark_end(out_s);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_write(t))
|
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
|
|
|
return SCP_CLIENT_STATE_END;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
static enum SCP_CLIENT_STATES_E
|
2021-06-18 13:48:05 +03:00
|
|
|
_scp_v1c_check_response(struct trans *t, struct SCP_SESSION *s)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
struct stream *in_s = t->in_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui32 version;
|
2021-06-18 13:48:05 +03:00
|
|
|
int size;
|
2012-09-20 07:51:34 +04:00
|
|
|
tui16 cmd;
|
|
|
|
tui16 dim;
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(in_s, 64);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_read(t, 8))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, version);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (version != 1)
|
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
|
|
|
}
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint32_be(in_s, size);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
init_stream(in_s, size - 8);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* read the rest of the packet */
|
2021-06-18 13:48:05 +03:00
|
|
|
if (0 != trans_force_read(t, size - 8))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, cmd);
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, cmd);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (cmd == 2) /* connection denied */
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, dim);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->errstr != 0)
|
|
|
|
{
|
|
|
|
g_free(s->errstr);
|
|
|
|
}
|
|
|
|
|
2016-06-22 02:30:18 +03:00
|
|
|
s->errstr = g_new(char, dim + 1);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->errstr == 0)
|
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint8a(in_s, s->errstr, dim);
|
2012-09-20 07:51:34 +04:00
|
|
|
(s->errstr)[dim] = '\0';
|
|
|
|
|
|
|
|
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (cmd == 3) /* resend usr/pwd */
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, dim);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->errstr != 0)
|
|
|
|
{
|
|
|
|
g_free(s->errstr);
|
|
|
|
}
|
|
|
|
|
2016-06-22 02:30:18 +03:00
|
|
|
s->errstr = g_new(char, dim + 1);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->errstr == 0)
|
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint8a(in_s, s->errstr, dim);
|
2012-09-20 07:51:34 +04:00
|
|
|
(s->errstr)[dim] = '\0';
|
|
|
|
|
|
|
|
return SCP_CLIENT_STATE_RESEND_CREDENTIALS;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (cmd == 20) /* password change */
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, dim);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->errstr != 0)
|
|
|
|
{
|
|
|
|
g_free(s->errstr);
|
|
|
|
}
|
|
|
|
|
2016-06-22 02:30:18 +03:00
|
|
|
s->errstr = g_new(char, dim + 1);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (s->errstr == 0)
|
|
|
|
{
|
|
|
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint8a(in_s, s->errstr, dim);
|
2012-09-20 07:51:34 +04:00
|
|
|
(s->errstr)[dim] = '\0';
|
|
|
|
|
|
|
|
return SCP_CLIENT_STATE_PWD_CHANGE_REQ;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (cmd == 30) /* display */
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2021-06-18 13:48:05 +03:00
|
|
|
in_uint16_be(in_s, s->display);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return SCP_CLIENT_STATE_OK;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
//else if (cmd == 31) /* there's a disconnected session */
|
|
|
|
//{
|
|
|
|
// return SCP_CLIENT_STATE_RECONNECT_SINGLE;
|
|
|
|
//}
|
|
|
|
//else if (cmd == 33) /* display of a disconnected session */
|
|
|
|
//{
|
|
|
|
// return SCP_CLIENT_STATE_RECONNECT;
|
|
|
|
//}
|
|
|
|
else if (cmd == 40) /* session list */
|
2007-05-07 01:02:25 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SESSION_LIST;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
2007-05-07 01:02:25 +04:00
|
|
|
}
|