From ab2e95d699d40cd6fcfb31762968f8a7416aca8c Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Wed, 10 Jun 2020 01:20:27 -0700 Subject: [PATCH] sesman: work on moving sesman to trans, v0 scp working --- sesman/libscp/libscp_types.h | 1 + sesman/libscp/libscp_v0.c | 230 +++++++++++++++++-------------- sesman/libscp/libscp_v0.h | 18 ++- sesman/libscp/libscp_v1s.c | 180 +++++++++++++++++++++++++ sesman/libscp/libscp_v1s.h | 12 ++ sesman/libscp/libscp_v1s_mng.c | 123 +++++++++++++++++ sesman/libscp/libscp_v1s_mng.h | 12 ++ sesman/libscp/libscp_vX.c | 23 ++-- sesman/libscp/libscp_vX.h | 5 +- sesman/scp.c | 37 ++--- sesman/scp.h | 6 +- sesman/scp_v0.c | 20 +-- sesman/scp_v0.h | 10 +- sesman/scp_v1.c | 13 +- sesman/scp_v1.h | 3 + sesman/scp_v1_mng.c | 6 + sesman/scp_v1_mng.h | 3 + sesman/sesman.c | 240 +++++++++++++++++++++++---------- sesman/sesman.h | 3 + sesman/session.c | 12 +- sesman/session.h | 3 +- sesman/sig.c | 1 - 22 files changed, 702 insertions(+), 259 deletions(-) diff --git a/sesman/libscp/libscp_types.h b/sesman/libscp/libscp_types.h index 8cb9166c..7f0c273e 100644 --- a/sesman/libscp/libscp_types.h +++ b/sesman/libscp/libscp_types.h @@ -31,6 +31,7 @@ #include "parse.h" #include "arch.h" #include "log.h" +#include "trans.h" #define SCP_SID tui32 #define SCP_DISPLAY tui16 diff --git a/sesman/libscp/libscp_v0.c b/sesman/libscp/libscp_v0.c index 61bf4fda..95542f42 100644 --- a/sesman/libscp/libscp_v0.c +++ b/sesman/libscp/libscp_v0.c @@ -154,63 +154,30 @@ scp_v0c_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s) /* server API */ /******************************************************************************/ enum SCP_SERVER_STATES_E -scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) +scp_v0s_accept(struct trans *atrans, struct SCP_SESSION **s) { - tui32 version = 0; - tui32 size; struct SCP_SESSION *session = 0; tui16 sz; - tui32 code = 0; + tui32 code; char *buf = 0; + struct stream *in_s; - if (!skipVchk) + in_s = atrans->in_s; + if (!s_check_rem(in_s, 6)) { - LOG_DBG("[v0:%d] starting connection", __LINE__); - - if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) - { - c->in_s->end = c->in_s->data + 8; - in_uint32_be(c->in_s, version); - - if (version != 0) - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__); - return SCP_SERVER_STATE_VERSION_ERR; - } - } - else - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } + return SCP_SERVER_STATE_INTERNAL_ERR; } - - in_uint32_be(c->in_s, size); - - init_stream(c->in_s, 8196); - - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - c->in_s->end = c->in_s->data + (size - 8); - - in_uint16_be(c->in_s, code); - - if (code == 0 || code == 10 || code == 20) + in_uint8s(in_s, 4); /* size */ + in_uint16_be(in_s, code); + if ((code == 0) || (code == 10) || (code == 20)) { session = scp_session_create(); - - if (0 == session) + if (NULL == session) { log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - - scp_session_set_version(session, version); - + scp_session_set_version(session, 0); if (code == 0) { scp_session_set_type(session, SCP_SESSION_TYPE_XVNC); @@ -225,9 +192,17 @@ scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) } /* reading username */ - in_uint16_be(c->in_s, sz); + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; if (0 != scp_session_set_username(session, buf)) { @@ -239,9 +214,17 @@ scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) g_free(buf); /* reading password */ - in_uint16_be(c->in_s, sz); + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; if (0 != scp_session_set_password(session, buf)) { @@ -253,13 +236,25 @@ scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) g_free(buf); /* width */ - in_uint16_be(c->in_s, sz); + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, sz); scp_session_set_width(session, sz); /* height */ - in_uint16_be(c->in_s, sz); + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, sz); scp_session_set_height(session, sz); /* bpp */ - in_uint16_be(c->in_s, sz); + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, sz); if (0 != scp_session_set_bpp(session, (tui8)sz)) { scp_session_destroy(session); @@ -269,60 +264,72 @@ scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) return SCP_SERVER_STATE_INTERNAL_ERR; } - if (s_check_rem(c->in_s, 2)) + if (s_check_rem(in_s, 2)) { /* reading domain */ - in_uint16_be(c->in_s, sz); - + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } if (sz > 0) { buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; scp_session_set_domain(session, buf); g_free(buf); } } - if (s_check_rem(c->in_s, 2)) + if (s_check_rem(in_s, 2)) { /* reading program */ - in_uint16_be(c->in_s, sz); - + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } if (sz > 0) { buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; scp_session_set_program(session, buf); g_free(buf); } } - if (s_check_rem(c->in_s, 2)) + if (s_check_rem(in_s, 2)) { /* reading directory */ - in_uint16_be(c->in_s, sz); - + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } if (sz > 0) { buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; scp_session_set_directory(session, buf); g_free(buf); } } - if (s_check_rem(c->in_s, 2)) + if (s_check_rem(in_s, 2)) { /* reading client IP address */ - in_uint16_be(c->in_s, sz); - + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } if (sz > 0) { buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; scp_session_set_client_ip(session, buf); g_free(buf); @@ -340,12 +347,20 @@ scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) return SCP_SERVER_STATE_INTERNAL_ERR; } - scp_session_set_version(session, version); + scp_session_set_version(session, 0); scp_session_set_type(session, SCP_GW_AUTHENTICATION); /* reading username */ - in_uint16_be(c->in_s, sz); + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; /* g_writeln("Received user name: %s",buf); */ @@ -359,9 +374,17 @@ scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) g_free(buf); /* reading password */ - in_uint16_be(c->in_s, sz); + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } buf = g_new0(char, sz + 1); - in_uint8a(c->in_s, buf, sz); + in_uint8a(in_s, buf, sz); buf[sz] = '\0'; /* g_writeln("Received password: %s",buf); */ @@ -386,72 +409,73 @@ scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) /******************************************************************************/ enum SCP_SERVER_STATES_E -scp_v0s_allow_connection(struct SCP_CONNECTION *c, SCP_DISPLAY d, const tui8 *guid) +scp_v0s_allow_connection(struct trans *atrans, SCP_DISPLAY d, const tui8 *guid) { int msg_size; + struct stream *out_s; + out_s = trans_get_out_s(atrans, 0); msg_size = guid == 0 ? 14 : 14 + 16; - out_uint32_be(c->out_s, 0); /* version */ - out_uint32_be(c->out_s, msg_size); /* size */ - out_uint16_be(c->out_s, 3); /* cmd */ - out_uint16_be(c->out_s, 1); /* data */ - out_uint16_be(c->out_s, d); /* data */ + 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 */ if (msg_size > 14) { - out_uint8a(c->out_s, guid, 16); + out_uint8a(out_s, guid, 16); } - s_mark_end(c->out_s); - - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) + s_mark_end(out_s); + if (0 != trans_write_copy(atrans)) { log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } - LOG_DBG("[v0:%d] connection terminated (allowed)", __LINE__); return SCP_SERVER_STATE_OK; } /******************************************************************************/ enum SCP_SERVER_STATES_E -scp_v0s_deny_connection(struct SCP_CONNECTION *c) +scp_v0s_deny_connection(struct trans *atrans) { - out_uint32_be(c->out_s, 0); /* version */ - out_uint32_be(c->out_s, 14); /* size */ - out_uint16_be(c->out_s, 3); /* cmd */ - out_uint16_be(c->out_s, 0); /* data = 0 - means NOT ok*/ - out_uint16_be(c->out_s, 0); /* reserved for display number*/ - s_mark_end(c->out_s); + struct stream *out_s; - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) + 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)) { log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } - LOG_DBG("[v0:%d] connection terminated (denied)", __LINE__); return SCP_SERVER_STATE_OK; } /******************************************************************************/ enum SCP_SERVER_STATES_E -scp_v0s_replyauthentication(struct SCP_CONNECTION *c, unsigned short int value) +scp_v0s_replyauthentication(struct trans *atrans, unsigned short int value) { - out_uint32_be(c->out_s, 0); /* version */ - out_uint32_be(c->out_s, 14); /* size */ - /* cmd SCP_GW_AUTHENTICATION means authentication reply */ - out_uint16_be(c->out_s, SCP_GW_AUTHENTICATION); - out_uint16_be(c->out_s, value); /* reply code */ - out_uint16_be(c->out_s, 0); /* dummy data */ - s_mark_end(c->out_s); + struct stream *out_s; - /* g_writeln("Total number of bytes that will be sent %d",c->out_s->end - c->out_s->data);*/ - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) + 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)) { /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); */ return SCP_SERVER_STATE_NETWORK_ERR; } - /* until syslog merge LOG_DBG(s_log, "[v0:%d] connection terminated (scp_v0s_deny_authentication)", __LINE__);*/ return SCP_SERVER_STATE_OK; } diff --git a/sesman/libscp/libscp_v0.h b/sesman/libscp/libscp_v0.h index 21fc16cd..a3fd92d1 100644 --- a/sesman/libscp/libscp_v0.h +++ b/sesman/libscp/libscp_v0.h @@ -45,40 +45,38 @@ scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s); /** * * @brief processes the stream using scp version 0 - * @param c connection descriptor + * @param atrans connection trans * @param s session descriptor - * @param skipVchk if set to !0 skips the version control (to be used after - * scp_vXs_accept() ) * */ enum SCP_SERVER_STATES_E -scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk); +scp_v0s_accept(struct trans *atrans, struct SCP_SESSION **s); /** * * @brief allows the connection to TS, returning the display port - * @param c connection descriptor + * @param atrans connection trans * */ enum SCP_SERVER_STATES_E -scp_v0s_allow_connection(struct SCP_CONNECTION* c, SCP_DISPLAY d, const tui8 *guid); +scp_v0s_allow_connection(struct trans *atrans, SCP_DISPLAY d, const tui8 *guid); /** * * @brief denies the connection to TS - * @param c connection descriptor + * @param atrans connection trans * */ enum SCP_SERVER_STATES_E -scp_v0s_deny_connection(struct SCP_CONNECTION* c); +scp_v0s_deny_connection(struct trans *atrans); /** * @brief send reply to an authentication request - * @param c connection descriptor + * @param atrans connection trans * @param value the reply code 0 means ok * @return */ enum SCP_SERVER_STATES_E -scp_v0s_replyauthentication(struct SCP_CONNECTION* c, unsigned short int value); +scp_v0s_replyauthentication(struct trans *atrans, unsigned short int value); #endif diff --git a/sesman/libscp/libscp_v1s.c b/sesman/libscp/libscp_v1s.c index 27e5ef13..5bd4dbdb 100644 --- a/sesman/libscp/libscp_v1s.c +++ b/sesman/libscp/libscp_v1s.c @@ -205,6 +205,186 @@ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION *c, struct SCP_SES return SCP_SERVER_STATE_OK; } +enum SCP_SERVER_STATES_E +scp_v1s_accept_msg(struct trans *atrans, struct SCP_SESSION** s) +{ + struct SCP_SESSION *session; + tui32 size; + tui16 cmdset; + tui16 cmd; + tui8 sz; + char buf[257]; + struct stream *in_s; + + in_s = atrans->in_s; + + if (!s_check_rem(in_s, 6)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + in_uint8s(in_s, 4); /* size */ + + /* reading command set */ + in_uint16_be(in_s, cmdset); + + /* if we are starting a management session */ + if (cmdset == SCP_COMMAND_SET_MANAGE) + { + log_message(LOG_LEVEL_DEBUG, "[v1s:%d] requested management connection", __LINE__); + /* should return SCP_SERVER_STATE_START_MANAGE */ + return scp_v1s_mng_accept_msg(atrans, s); + } + + /* if we started with resource sharing... */ + if (cmdset == SCP_COMMAND_SET_RSR) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + if (!s_check_rem(in_s, 27)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading command */ + in_uint16_be(in_s, cmd); + + if (cmd != 1) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + session = scp_session_create(); + + if (0 == session) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error (malloc returned NULL)", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + scp_session_set_version(session, 1); + + in_uint8(in_s, sz); + + if ((sz != SCP_SESSION_TYPE_XVNC) && (sz != SCP_SESSION_TYPE_XRDP)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: unknown session type", __LINE__); + return SCP_SERVER_STATE_SESSION_TYPE_ERR; + } + + scp_session_set_type(session, sz); + + in_uint16_be(in_s, cmd); + scp_session_set_height(session, cmd); + in_uint16_be(in_s, cmd); + scp_session_set_width(session, cmd); + in_uint8(in_s, sz); + if (0 != scp_session_set_bpp(session, sz)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, + "[v1s:%d] connection aborted: unsupported bpp: %d", + __LINE__, sz); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + scp_session_set_rsr(session, sz); + in_uint8a(in_s, buf, 17); + buf[17] = '\0'; + scp_session_set_locale(session, buf); + + in_uint8(in_s, sz); + + if (sz == SCP_ADDRESS_TYPE_IPV4) + { + if (!s_check_rem(in_s, 4)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint32_be(in_s, size); + scp_session_set_addr(session, sz, &size); + } + else if (sz == SCP_ADDRESS_TYPE_IPV6) + { + if (!s_check_rem(in_s, 16)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8a(in_s, buf, 16); + scp_session_set_addr(session, sz, buf); + } + + buf[256] = '\0'; + /* reading hostname */ + if (!s_check_rem(in_s, 1)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + buf[sz] = '\0'; + in_uint8a(in_s, buf, sz); + + if (0 != scp_session_set_hostname(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading username */ + if (!s_check_rem(in_s, 1)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + buf[sz] = '\0'; + in_uint8a(in_s, buf, sz); + + if (0 != scp_session_set_username(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading password */ + if (!s_check_rem(in_s, 1)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + buf[sz] = '\0'; + in_uint8a(in_s, buf, sz); + + if (0 != scp_session_set_password(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* returning the struct */ + (*s) = session; + + return SCP_SERVER_STATE_OK; +} + enum SCP_SERVER_STATES_E scp_v1s_deny_connection(struct SCP_CONNECTION *c, const char *reason) { diff --git a/sesman/libscp/libscp_v1s.h b/sesman/libscp/libscp_v1s.h index 69e64038..4ffa2d1e 100644 --- a/sesman/libscp/libscp_v1s.h +++ b/sesman/libscp/libscp_v1s.h @@ -44,6 +44,18 @@ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk); +/** + * + * @brief processes the stream using scp version 1 + * @param trans connection trans + * @param s pointer to session descriptor pointer + * + * this function places in *s the address of a newly allocated SCP_SESSION structure + * that should be free()d + */ +enum SCP_SERVER_STATES_E +scp_v1s_accept_msg(struct trans *atrans, struct SCP_SESSION** s); + /** * * @brief denies connection to sesman diff --git a/sesman/libscp/libscp_v1s_mng.c b/sesman/libscp/libscp_v1s_mng.c index 3a3e1d98..be748b37 100644 --- a/sesman/libscp/libscp_v1s_mng.c +++ b/sesman/libscp/libscp_v1s_mng.c @@ -119,6 +119,129 @@ scp_v1s_mng_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s) return SCP_SERVER_STATE_START_MANAGE; } +enum SCP_SERVER_STATES_E +scp_v1s_mng_accept_msg(struct trans *atrans, struct SCP_SESSION **s) +{ + struct SCP_SESSION *session; + tui32 ipaddr; + tui16 cmd; + tui8 sz; + char buf[257]; + struct stream *in_s; + + in_s = atrans->in_s; + + /* reading command */ + if (!s_check_rem(in_s, 2)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint16_be(in_s, cmd); + + if (cmd != 1) /* manager login */ + { + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + session = scp_session_create(); + + if (0 == session) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + scp_session_set_version(session, 1); + scp_session_set_type(session, SCP_SESSION_TYPE_MANAGE); + + /* reading username */ + if (!s_check_rem(in_s, 1)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + buf[sz] = '\0'; + in_uint8a(in_s, buf, sz); + + if (0 != scp_session_set_username(session, buf)) + { + scp_session_destroy(session); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading password */ + if (!s_check_rem(in_s, 1)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + buf[sz] = '\0'; + in_uint8a(in_s, buf, sz); + + if (0 != scp_session_set_password(session, buf)) + { + scp_session_destroy(session); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading remote address */ + if (!s_check_rem(in_s, 1)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + + if (sz == SCP_ADDRESS_TYPE_IPV4) + { + if (!s_check_rem(in_s, 4)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint32_be(in_s, ipaddr); + scp_session_set_addr(session, sz, &ipaddr); + } + else if (sz == SCP_ADDRESS_TYPE_IPV6) + { + if (!s_check_rem(in_s, 16)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8a(in_s, buf, 16); + scp_session_set_addr(session, sz, buf); + } + + /* reading hostname */ + if (!s_check_rem(in_s, 1)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + in_uint8(in_s, sz); + if (!s_check_rem(in_s, sz)) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + buf[sz] = '\0'; + in_uint8a(in_s, buf, sz); + + if (0 != scp_session_set_hostname(session, buf)) + { + scp_session_destroy(session); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* returning the struct */ + (*s) = session; + + return SCP_SERVER_STATE_START_MANAGE; +} + /* 002 */ enum SCP_SERVER_STATES_E scp_v1s_mng_allow_connection(struct SCP_CONNECTION *c, struct SCP_SESSION *s) diff --git a/sesman/libscp/libscp_v1s_mng.h b/sesman/libscp/libscp_v1s_mng.h index 437a06d2..462a06a8 100644 --- a/sesman/libscp/libscp_v1s_mng.h +++ b/sesman/libscp/libscp_v1s_mng.h @@ -42,6 +42,18 @@ enum SCP_SERVER_STATES_E scp_v1s_mng_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s); +/** + * + * @brief processes the stream using scp version 1 + * @param atrans connection descriptor + * @param s pointer to session descriptor pointer + * + * this function places in *s the address of a newly allocated SCP_SESSION structure + * that should be free()d + */ +enum SCP_SERVER_STATES_E +scp_v1s_mng_accept_msg(struct trans *atrans, struct SCP_SESSION **s); + /** * * @brief allows connection to sesman diff --git a/sesman/libscp/libscp_vX.c b/sesman/libscp/libscp_vX.c index 195b9225..815e4664 100644 --- a/sesman/libscp/libscp_vX.c +++ b/sesman/libscp/libscp_vX.c @@ -30,27 +30,26 @@ #include "libscp_vX.h" -/* server API */ -enum SCP_SERVER_STATES_E scp_vXs_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s) +/******************************************************************************/ +enum SCP_SERVER_STATES_E +scp_vXs_accept(struct trans *atrans, struct SCP_SESSION **s) { - tui32 version; + struct stream *in_s; + int version; - /* reading version and packet size */ - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + in_s = atrans->in_s; + if (!s_check_rem(in_s, 4)) { - return SCP_SERVER_STATE_NETWORK_ERR; + return SCP_SERVER_STATE_INTERNAL_ERR; } - - in_uint32_be(c->in_s, version); - + in_uint32_be(in_s, version); if (version == 0) { - return scp_v0s_accept(c, s, 1); + return scp_v0s_accept(atrans, s); } else if (version == 1) { - return scp_v1s_accept(c, s, 1); + return scp_v1s_accept_msg(atrans, s); } - return SCP_SERVER_STATE_VERSION_ERR; } diff --git a/sesman/libscp/libscp_vX.h b/sesman/libscp/libscp_vX.h index ef0a8290..6c7e8170 100644 --- a/sesman/libscp/libscp_vX.h +++ b/sesman/libscp/libscp_vX.h @@ -36,12 +36,13 @@ /** * * @brief version neutral server accept function - * @param c connection descriptor + * @param atrans connection trans * @param s session descriptor pointer address. * it will return a newly allocated descriptor. * It this memory needs to be g_free()d * */ -enum SCP_SERVER_STATES_E scp_vXs_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s); +enum SCP_SERVER_STATES_E +scp_vXs_accept(struct trans *atrans, struct SCP_SESSION **s); #endif diff --git a/sesman/scp.c b/sesman/scp.c index d548052a..ef67ec17 100644 --- a/sesman/scp.c +++ b/sesman/scp.c @@ -36,44 +36,33 @@ extern struct config_sesman *g_cfg; /* in sesman.c */ /******************************************************************************/ -void * -scp_process_start(void *sck) +int +scp_process(struct trans *atrans) { - struct SCP_CONNECTION scon; - struct SCP_SESSION *sdata = NULL; + struct SCP_SESSION *sdata; - scon.in_sck = (int)(tintptr)sck; - LOG_DBG("started scp thread on socket %d", scon.in_sck); - - make_stream(scon.in_s); - make_stream(scon.out_s); - - init_stream(scon.in_s, 8192); - init_stream(scon.out_s, 8192); - - switch (scp_vXs_accept(&scon, &(sdata))) + sdata = NULL; + switch (scp_vXs_accept(atrans, &sdata)) { case SCP_SERVER_STATE_OK: - if (sdata->version == 0) { /* starts processing an scp v0 connection */ LOG_DBG("accept ok, go on with scp v0"); - scp_v0_process(&scon, sdata); + scp_v0_process(atrans, sdata); } else { LOG_DBG("accept ok, go on with scp v1"); /*LOG_DBG("user: %s\npass: %s",sdata->username, sdata->password);*/ - scp_v1_process(&scon, sdata); + scp_v1_process_msg(atrans, sdata); } - break; case SCP_SERVER_STATE_START_MANAGE: /* starting a management session */ log_message(LOG_LEVEL_WARNING, "starting a sesman management session..."); - scp_v1_mng_process(&scon, sdata); + scp_v1_mng_process_msg(atrans, sdata); break; case SCP_SERVER_STATE_VERSION_ERR: /* an unknown scp version was requested, so we shut down the */ @@ -95,14 +84,6 @@ scp_process_start(void *sck) log_message(LOG_LEVEL_ALWAYS, "unknown return from scp_vXs_accept()"); break; } - - free_stream(scon.in_s); - free_stream(scon.out_s); - - if (sdata) - { - scp_session_destroy(sdata); - } - return 0; } + diff --git a/sesman/scp.h b/sesman/scp.h index c174d3d9..40c732f7 100644 --- a/sesman/scp.h +++ b/sesman/scp.h @@ -36,10 +36,10 @@ * @brief Starts a an scp protocol thread. * Starts a an scp protocol thread. * But does only version control.... - * @param socket the connection socket + * @param atrans the connection trans * */ -void* -scp_process_start(void* sck); +int +scp_process(struct trans *atrans); #endif diff --git a/sesman/scp_v0.c b/sesman/scp_v0.c index cc3712cc..8f06b9f6 100644 --- a/sesman/scp_v0.c +++ b/sesman/scp_v0.c @@ -34,7 +34,7 @@ extern struct config_sesman *g_cfg; /* in sesman.c */ /******************************************************************************/ void -scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) +scp_v0_process(struct trans *atrans, struct SCP_SESSION* s) { int display = 0; tbus data; @@ -53,14 +53,14 @@ scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) if (1 == access_login_allowed(s->username)) { /* the user is member of the correct groups. */ - scp_v0s_replyauthentication(c, errorcode); + scp_v0s_replyauthentication(atrans, errorcode); log_message(LOG_LEVEL_INFO, "Access permitted for user: %s", s->username); /* g_writeln("Connection allowed"); */ } else { - scp_v0s_replyauthentication(c, 32 + 3); /* all first 32 are reserved for PAM errors */ + scp_v0s_replyauthentication(atrans, 32 + 3); /* all first 32 are reserved for PAM errors */ log_message(LOG_LEVEL_INFO, "Username okey but group problem for " "user: %s", s->username); /* g_writeln("user password ok, but group problem"); */ @@ -71,7 +71,7 @@ scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) /* g_writeln("username or password error"); */ log_message(LOG_LEVEL_INFO, "Username or password error for user: %s", s->username); - scp_v0s_replyauthentication(c, errorcode); + scp_v0s_replyauthentication(atrans, errorcode); } } else if (data) @@ -123,18 +123,18 @@ scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) if (SCP_SESSION_TYPE_XVNC == s->type) { log_message( LOG_LEVEL_INFO, "starting Xvnc session..."); - display = session_start(data, SESMAN_SESSION_TYPE_XVNC, c, s); + display = session_start(data, SESMAN_SESSION_TYPE_XVNC, s); } else if (SCP_SESSION_TYPE_XRDP == s->type) { log_message(LOG_LEVEL_INFO, "starting X11rdp session..."); - display = session_start(data, SESMAN_SESSION_TYPE_XRDP, c, s); + display = session_start(data, SESMAN_SESSION_TYPE_XRDP, s); } else if (SCP_SESSION_TYPE_XORG == s->type) { /* type is SCP_SESSION_TYPE_XORG */ log_message(LOG_LEVEL_INFO, "starting Xorg session..."); - display = session_start(data, SESMAN_SESSION_TYPE_XORG, c, s); + display = session_start(data, SESMAN_SESSION_TYPE_XORG, s); } /* if the session started up ok, auth_end will be called on sig child */ @@ -148,16 +148,16 @@ scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) if (display == 0) { - scp_v0s_deny_connection(c); + scp_v0s_deny_connection(atrans); } else { - scp_v0s_allow_connection(c, display, s->guid); + scp_v0s_allow_connection(atrans, display, s->guid); } } else { - scp_v0s_deny_connection(c); + scp_v0s_deny_connection(atrans); } if (do_auth_end) { diff --git a/sesman/scp_v0.h b/sesman/scp_v0.h index 41d6bb7e..cc62da36 100644 --- a/sesman/scp_v0.h +++ b/sesman/scp_v0.h @@ -29,15 +29,7 @@ #include "libscp.h" -/** - * - * @brief processes the stream using scp version 0 - * @param in_sck connection socket - * @param in_s input stream - * @param out_s output stream - * - */ void -scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s); +scp_v0_process(struct trans *atrans, struct SCP_SESSION *s); #endif diff --git a/sesman/scp_v1.c b/sesman/scp_v1.c index 60f82112..7dc8b948 100644 --- a/sesman/scp_v1.c +++ b/sesman/scp_v1.c @@ -127,17 +127,17 @@ scp_v1_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) if (SCP_SESSION_TYPE_XVNC == s->type) { log_message(LOG_LEVEL_INFO, "starting Xvnc session..."); - display = session_start(data, SESMAN_SESSION_TYPE_XVNC, c, s); + display = session_start(data, SESMAN_SESSION_TYPE_XVNC, s); } else if (SCP_SESSION_TYPE_XRDP == s->type) { log_message(LOG_LEVEL_INFO, "starting X11rdp session..."); - display = session_start(data, SESMAN_SESSION_TYPE_XRDP, c, s); + display = session_start(data, SESMAN_SESSION_TYPE_XRDP, s); } else if (SCP_SESSION_TYPE_XORG == s->type) { log_message(LOG_LEVEL_INFO, "starting Xorg session..."); - display = session_start(data, SESMAN_SESSION_TYPE_XORG, c, s); + display = session_start(data, SESMAN_SESSION_TYPE_XORG, s); } /* if the session started up ok, auth_end will be called on sig child */ @@ -215,6 +215,13 @@ scp_v1_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) g_free(slist); } +/******************************************************************************/ +void +scp_v1_process_msg(struct trans *atrans, struct SCP_SESSION* s) +{ + // JAY TODO +} + static void parseCommonStates(enum SCP_SERVER_STATES_E e, const char *f) { switch (e) diff --git a/sesman/scp_v1.h b/sesman/scp_v1.h index c7bd72f5..4735c0dd 100644 --- a/sesman/scp_v1.h +++ b/sesman/scp_v1.h @@ -38,4 +38,7 @@ void scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s); +void +scp_v1_process_msg(struct trans *atrans, struct SCP_SESSION* s); + #endif diff --git a/sesman/scp_v1_mng.c b/sesman/scp_v1_mng.c index d44b9e04..31af12ff 100644 --- a/sesman/scp_v1_mng.c +++ b/sesman/scp_v1_mng.c @@ -104,6 +104,12 @@ scp_v1_mng_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) auth_end(data); } +void +scp_v1_mng_process_msg(struct trans *atrans, struct SCP_SESSION *s) +{ + // JAY TODO +} + static void parseCommonStates(enum SCP_SERVER_STATES_E e, const char *f) { switch (e) diff --git a/sesman/scp_v1_mng.h b/sesman/scp_v1_mng.h index 89cacea1..405cb6b8 100644 --- a/sesman/scp_v1_mng.h +++ b/sesman/scp_v1_mng.h @@ -38,4 +38,7 @@ void scp_v1_mng_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s); +void +scp_v1_mng_process_msg(struct trans *atrans, struct SCP_SESSION *s); + #endif diff --git a/sesman/sesman.c b/sesman/sesman.c index 73c7d0a2..1a113aed 100644 --- a/sesman/sesman.c +++ b/sesman/sesman.c @@ -30,13 +30,15 @@ #include "sesman.h" -int g_sck; int g_pid; unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; struct config_sesman *g_cfg; /* defined in config.h */ tintptr g_term_event = 0; +static struct trans *g_list_trans = NULL; +static struct list *g_con_list = NULL; + /******************************************************************************/ int sesman_listen_test(struct config_sesman *cfg) { @@ -76,6 +78,82 @@ int sesman_listen_test(struct config_sesman *cfg) return rv; } + +/******************************************************************************/ +int +sesman_close_all(void) +{ + int index; + struct trans *con_trans; + + log_message(LOG_LEVEL_DEBUG, "sesman_close_all:"); + trans_delete(g_list_trans); + for (index = 0; index < g_con_list->count; index++) + { + con_trans = (struct trans *) list_get_item(g_con_list, index); + trans_delete(con_trans); + } + return 0; +} + +/******************************************************************************/ +static int +sesman_data_in(struct trans *self) +{ + int version; + int size; + + if (self->extra_flags == 0) + { + in_uint32_be(self->in_s, version); + in_uint32_be(self->in_s, size); + if (size > self->in_s->size) + { + log_message(LOG_LEVEL_ERROR, "sesman_data_in: bad message size"); + return 1; + } + self->header_size = size; + self->extra_flags = 1; + } + else + { + /* prcess message */ + self->in_s->p = self->in_s->data; + if (scp_process(self) != 0) + { + log_message(LOG_LEVEL_ERROR, "sesman_data_in: scp_process_msg " + "failed"); + return 1; + } + /* reset for next message */ + self->header_size = 8; + self->extra_flags = 0; + init_stream(self->in_s, 0); + } + return 0; +} + +/******************************************************************************/ +static int +sesman_listen_conn_in(struct trans *self, struct trans *new_self) +{ + if (g_con_list->count < 16) + { + new_self->header_size = 8; + new_self->trans_data_in = sesman_data_in; + new_self->no_stream_init_on_data_in = 1; + new_self->extra_flags = 0; + list_add_item(g_con_list, (intptr_t) new_self); + } + else + { + log_message(LOG_LEVEL_ERROR, "sesman_data_in: error, too many " + "connections, rejecting"); + trans_delete(new_self); + } + return 0; +} + /******************************************************************************/ /** * @@ -85,96 +163,122 @@ int sesman_listen_test(struct config_sesman *cfg) int sesman_main_loop(void) { - int in_sck; int error; int robjs_count; + int wobjs_count; int cont; - int rv = 0; - tbus sck_obj; - tbus robjs[8]; + int timeout; + int index; + intptr_t robjs[32]; + intptr_t wobjs[32]; + struct trans *con_trans; - g_sck = g_tcp_socket(); - if (g_sck < 0) + g_con_list = list_create(); + if (g_con_list == NULL) { - log_message(LOG_LEVEL_ERROR, "error opening socket, g_tcp_socket() failed..."); + log_message(LOG_LEVEL_ERROR, "sesman_main_loop: list_create failed"); return 1; } - - g_tcp_set_non_blocking(g_sck); - error = scp_tcp_bind(g_sck, g_cfg->listen_address, g_cfg->listen_port); - - if (error == 0) + g_list_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); + if (g_list_trans == NULL) { - error = g_tcp_listen(g_sck); - - if (error == 0) + log_message(LOG_LEVEL_ERROR, "sesman_main_loop: trans_create failed"); + list_delete(g_con_list); + return 1; + } + log_message(LOG_LEVEL_DEBUG, "sesman_main_loop: address %s port %s", + g_cfg->listen_address, g_cfg->listen_port); + error = trans_listen_address(g_list_trans, g_cfg->listen_port, + g_cfg->listen_address); + if (error != 0) + { + log_message(LOG_LEVEL_ERROR, "sesman_main_loop: trans_listen_address " + "failed"); + trans_delete(g_list_trans); + list_delete(g_con_list); + return 1; + } + g_list_trans->trans_conn_in = sesman_listen_conn_in; + cont = 1; + while (cont) + { + timeout = -1; + robjs_count = 0; + robjs[robjs_count++] = g_term_event; + wobjs_count = 0; + for (index = 0; index < g_con_list->count; index++) { - log_message(LOG_LEVEL_INFO, "listening to port %s on %s", - g_cfg->listen_port, g_cfg->listen_address); - sck_obj = g_create_wait_obj_from_socket(g_sck, 0); - cont = 1; - - while (cont) + con_trans = (struct trans *) list_get_item(g_con_list, index); + if (con_trans != NULL) { - /* build the wait obj list */ - robjs_count = 0; - robjs[robjs_count++] = sck_obj; - robjs[robjs_count++] = g_term_event; - - /* wait */ - if (g_obj_wait(robjs, robjs_count, 0, 0, -1) != 0) - { - /* error, should not get here */ - g_sleep(100); - } - - if (g_is_wait_obj_set(g_term_event)) /* term */ + error = trans_get_wait_objs_rw(con_trans, robjs, &robjs_count, + wobjs, &wobjs_count, &timeout); + if (error != 0) { + log_message(LOG_LEVEL_ERROR, "sesman_main_loop: " + "trans_get_wait_objs_rw failed"); break; } + } + } + if (error != 0) + { + break; + } + error = trans_get_wait_objs_rw(g_list_trans, robjs, &robjs_count, + wobjs, &wobjs_count, &timeout); + if (error != 0) + { + log_message(LOG_LEVEL_ERROR, "sesman_main_loop: " + "trans_get_wait_objs_rw failed"); + break; + } - if (g_is_wait_obj_set(sck_obj)) /* incoming connection */ + error = g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout); + if (error != 0) + { + /* error, should not get here */ + g_sleep(100); + } + + if (g_is_wait_obj_set(g_term_event)) /* term */ + { + break; + } + + for (index = 0; index < g_con_list->count; index++) + { + con_trans = (struct trans *) list_get_item(g_con_list, index); + if (con_trans != NULL) + { + error = trans_check_wait_objs(con_trans); + if (error != 0) { - in_sck = g_tcp_accept(g_sck); - - if ((in_sck == -1) && g_tcp_last_error_would_block(g_sck)) - { - /* should not get here */ - g_sleep(100); - } - else if (in_sck == -1) - { - /* error, should not get here */ - break; - } - else - { - /* we've got a connection, so we pass it to scp code */ - LOG_DBG("new connection"); - scp_process_start((void*)(tintptr)in_sck); - g_sck_close(in_sck); - } + log_message(LOG_LEVEL_ERROR, "sesman_main_loop: " + "trans_check_wait_objs failed, removing trans"); + trans_delete(con_trans); + list_remove_item(g_con_list, index); + index--; + continue; } } - - g_delete_wait_obj_from_socket(sck_obj); } - else + error = trans_check_wait_objs(g_list_trans); + if (error != 0) { - log_message(LOG_LEVEL_ERROR, "listen error %d (%s)", - g_get_errno(), g_get_strerror()); - rv = 1; + log_message(LOG_LEVEL_ERROR, "sesman_main_loop: " + "trans_check_wait_objs failed"); + break; } } - else + for (index = 0; index < g_con_list->count; index++) { - log_message(LOG_LEVEL_ERROR, "bind error on " - "port '%s': %d (%s)", g_cfg->listen_port, - g_get_errno(), g_get_strerror()); - rv = 1; + con_trans = (struct trans *) list_get_item(g_con_list, index); + trans_delete(con_trans); } - g_tcp_close(g_sck); - return rv; + list_delete(g_con_list); + trans_delete(g_list_trans); + return 0; } /******************************************************************************/ diff --git a/sesman/sesman.h b/sesman/sesman.h index eb0dc21f..c7b3913c 100644 --- a/sesman/sesman.h +++ b/sesman/sesman.h @@ -41,4 +41,7 @@ #include "libscp.h" +int +sesman_close_all(void); + #endif diff --git a/sesman/session.c b/sesman/session.c index f85616c1..802ac024 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -49,7 +49,6 @@ extern unsigned char g_fixedkey[8]; extern struct config_sesman *g_cfg; /* in sesman.c */ -extern int g_sck; /* in sesman.c */ struct session_chain *g_sessions; int g_session_count; @@ -390,8 +389,7 @@ session_start_chansrv(char *username, int display) /******************************************************************************/ /* called with the main thread */ static int -session_start_fork(tbus data, tui8 type, struct SCP_CONNECTION *c, - struct SCP_SESSION *s) +session_start_fork(tbus data, tui8 type, struct SCP_SESSION *s) { int display = 0; int pid = 0; @@ -471,8 +469,7 @@ session_start_fork(tbus data, tui8 type, struct SCP_CONNECTION *c, g_getpid()); auth_start_session(data, display); g_delete_wait_obj(g_term_event); - g_tcp_close(g_sck); - g_tcp_close(c->in_sck); + sesman_close_all(); g_sprintf(geometry, "%dx%d", s->width, s->height); g_sprintf(depth, "%d", s->bpp); g_sprintf(screen, ":%d", display); @@ -894,10 +891,9 @@ session_reconnect_fork(int display, char *username, long data) /* called by a worker thread, ask the main thread to call session_sync_start and wait till done */ int -session_start(long data, tui8 type, struct SCP_CONNECTION *c, - struct SCP_SESSION *s) +session_start(long data, tui8 type, struct SCP_SESSION *s) { - return session_start_fork(data, type, c, s); + return session_start_fork(data, type, s); } /******************************************************************************/ diff --git a/sesman/session.h b/sesman/session.h index 42d747cb..8e038673 100644 --- a/sesman/session.h +++ b/sesman/session.h @@ -105,8 +105,7 @@ session_get_bydata(const char *name, int width, int height, int bpp, int type, * */ int -session_start(long data, tui8 type, struct SCP_CONNECTION *c, - struct SCP_SESSION *s); +session_start(long data, tui8 type, struct SCP_SESSION *s); int session_reconnect(int display, char *username, long data); diff --git a/sesman/sig.c b/sesman/sig.c index 782e8fe2..052a07c4 100644 --- a/sesman/sig.c +++ b/sesman/sig.c @@ -32,7 +32,6 @@ #include "sesman.h" -extern int g_sck; extern int g_pid; extern struct config_sesman *g_cfg; /* in sesman.c */ extern tbus g_term_event;