Commit f5aa89a8 authored by Niels Möller's avatar Niels Möller
Browse files

Purged dependence on ssh_connection from channel.c. Updated all users.

Rev: src/channel.c:1.125.2.1
Rev: src/channel.h:1.77.2.1
Rev: src/channel_commands.c:1.30.2.1
Rev: src/channel_commands.h:1.21.2.1
Rev: src/client.c:1.166.2.1
Rev: src/client_pty.c:1.27.2.1
Rev: src/client_x11.c:1.26.2.1
Rev: src/gateway_channel.c:1.18.2.1
Rev: src/gateway_commands.c:1.24.2.1
Rev: src/lshd-userauth.c:1.1.2.5
Rev: src/read_data.c:1.37.2.1
Rev: src/server_session.c:1.103.2.1
Rev: src/server_x11.c:1.21.2.1
Rev: src/tcpforward.c:1.69.2.1
Rev: src/tcpforward_commands.c:1.47.2.1
parent 53f8686c
This diff is collapsed.
......@@ -28,11 +28,12 @@
#include "alist.h"
#include "command.h"
#include "connection.h"
#include "parse.h"
#include "server_pty.h"
#include "write_buffer.h"
struct channel_table;
struct channel_open_info
{
uint32_t type_length;
......@@ -118,7 +119,7 @@ struct channel_request_info
(send_window_size . uint32_t)
(send_max_packet . uint32_t)
(connection object ssh_connection)
(table object channel_table)
(request_types object alist)
......@@ -182,10 +183,25 @@ struct channel_request_info
#define CHANNEL_RESERVED 1
#define CHANNEL_IN_USE 2
/* FIXME: If/when lsh is more clearly separated into transport and
service layer, this class ought to be renamed to ssh_connection,
since it is the core of the implementation of the "ssh-connection"
service. */
/* GABA:
(class
(name channel_table)
(vars
; Communication with the transport layer
(e object exception_handler)
(write object abstract_write)
; The chained connection, when using a gateway.
; FIXME: Move to a sub-class?
(chain object channel_table)
; Contains the resource lists for all channels
(resources object resource_list)
; Channels are indexed by local number
(channels space (object ssh_channel) used_channels)
......@@ -249,7 +265,7 @@ struct channel_request_info
(class
(name global_request)
(vars
(handler method void "struct ssh_connection *connection"
(handler method void "struct channel_table *table"
"uint32_t type"
; want-reply is needed only by
; do_gateway_global_request.
......@@ -259,8 +275,8 @@ struct channel_request_info
"struct exception_handler *e")))
*/
#define GLOBAL_REQUEST(r, c, t, w, a, n, e) \
((r)->handler((r), (c), (t), (w), (a), (n), (e)))
#define GLOBAL_REQUEST(r, table, t, w, a, n, e) \
((r)->handler((r), (table), (t), (w), (a), (n), (e)))
/* SSH_MSG_CHANNEL_OPEN */
......@@ -283,27 +299,27 @@ make_channel_open_exception(uint32_t error_code, const char *msg);
(name channel_open)
(vars
(handler method void
"struct ssh_connection *connection"
"struct channel_table *table"
"struct channel_open_info *info"
"struct simple_buffer *data"
"struct command_continuation *c"
"struct exception_handler *e")))
*/
#define CHANNEL_OPEN(o, c, i, d, r, e) \
((o)->handler((o), (c), (i), (d), (r), (e)))
#define DEFINE_CHANNEL_OPEN(name) \
static void do_##name(struct channel_open *s, \
struct ssh_connection *connection, \
struct channel_open_info *info, \
struct simple_buffer *args, \
struct command_continuation *c, \
struct exception_handler *e); \
\
struct channel_open name = \
{ STATIC_HEADER, do_##name }; \
\
#define CHANNEL_OPEN(o, t, i, d, r, e) \
((o)->handler((o), (t), (i), (d), (r), (e)))
#define DEFINE_CHANNEL_OPEN(name) \
static void do_##name(struct channel_open *s, \
struct channel_table *table, \
struct channel_open_info *info, \
struct simple_buffer *args, \
struct command_continuation *c, \
struct exception_handler *e); \
\
struct channel_open name = \
{ STATIC_HEADER, do_##name }; \
\
static void do_##name
/* SSH_MSG_CHANNEL_REQUEST */
......@@ -343,11 +359,12 @@ int alloc_channel(struct channel_table *table);
void dealloc_channel(struct channel_table *table, int i);
void
use_channel(struct ssh_connection *connection,
use_channel(struct channel_table *table,
uint32_t local_channel_number);
void
register_channel(uint32_t local_channel_number,
register_channel(struct channel_table *table,
uint32_t local_channel_number,
struct ssh_channel *channel,
int take_into_use);
......@@ -360,8 +377,10 @@ struct abstract_write *make_channel_write(struct ssh_channel *channel);
struct abstract_write *make_channel_write_extended(struct ssh_channel *channel,
uint32_t type);
struct io_callback *make_channel_read_data(struct ssh_channel *channel);
struct io_callback *make_channel_read_stderr(struct ssh_channel *channel);
struct io_callback *
make_channel_read_data(struct ssh_channel *channel);
struct io_callback *
make_channel_read_stderr(struct ssh_channel *channel);
struct lsh_string *format_global_failure(void);
struct lsh_string *format_global_success(void);
......@@ -424,21 +443,69 @@ make_channel_io_exception_handler(struct ssh_channel *channel,
struct exception_handler *parent,
const char *context);
struct lsh_string *channel_transmit_data(struct ssh_channel *channel,
struct lsh_string *data);
struct lsh_string *
channel_transmit_data(struct ssh_channel *channel,
struct lsh_string *data);
struct lsh_string *
channel_transmit_extended(struct ssh_channel *channel,
uint32_t type,
struct lsh_string *data);
void
handle_global_request(struct channel_table *table,
struct lsh_string *packet);
void
handle_global_success(struct channel_table *table,
struct lsh_string *packet);
void
handle_global_failure(struct channel_table *table,
struct lsh_string *packet);
void
handle_channel_request(struct channel_table *table,
struct lsh_string *packet);
void
handle_channel_open(struct channel_table *table,
struct lsh_string *packet);
struct lsh_string *channel_transmit_extended(struct ssh_channel *channel,
uint32_t type,
struct lsh_string *data);
void
handle_adjust_window(struct channel_table *table,
struct lsh_string *packet);
void init_connection_service(struct ssh_connection *connection);
extern struct command connection_service_command;
#define INIT_CONNECTION_SERVICE (&connection_service_command.super)
void
handle_channel_data(struct channel_table *table,
struct lsh_string *packet);
#if 0
void init_login_service(struct ssh_connection *connection);
extern struct command login_service_command;
#define INIT_LOGIN_SERVICE (&login_service_command.super)
#endif
void
handle_channel_extended_data(struct channel_table *table,
struct lsh_string *packet);
void
handle_channel_eof(struct channel_table *table,
struct lsh_string *packet);
void
handle_channel_close(struct channel_table *table,
struct lsh_string *packet);
void
handle_open_confirm(struct channel_table *table,
struct lsh_string *packet);
void
handle_open_failure(struct channel_table *table,
struct lsh_string *packet);
void
handle_channel_success(struct channel_table *table,
struct lsh_string *packet);
void
handle_channel_failure(struct channel_table *table,
struct lsh_string *packet);
#endif /* LSH_CHANNEL_H_INCLUDED */
......@@ -46,11 +46,11 @@ do_channel_open_command(struct command *s,
struct exception_handler *e)
{
CAST_SUBTYPE(channel_open_command, self, s);
CAST(ssh_connection, connection, x);
CAST(channel_table, table, x);
struct lsh_string *request;
struct ssh_channel *channel;
int index = alloc_channel(connection->table);
int index = alloc_channel(table);
if (index < 0)
{
......@@ -64,12 +64,12 @@ do_channel_open_command(struct command *s,
return;
}
channel = NEW_CHANNEL(self, connection, index, &request);
channel = NEW_CHANNEL(self, table, index, &request);
if (!channel)
{
werror("do_channel_open_command: NEW_CHANNEL failed\n");
dealloc_channel(connection->table, index);
dealloc_channel(table, index);
}
else
{
......@@ -77,9 +77,9 @@ do_channel_open_command(struct command *s,
* perhaps we need not pass the connection to NEW_CHANNEL. */
channel->open_continuation = c;
channel->e = e;
register_channel(index, channel, 0);
register_channel(table, index, channel, 0);
connection_send(connection, request);
A_WRITE(table->write, request);
}
}
......@@ -99,7 +99,7 @@ do_channel_request_command(struct command *s,
object_queue_add_tail(&channel->pending_requests,
&make_command_context(c, e)->super);
connection_send(channel->connection, request);
A_WRITE(channel->table->write, request);
}
void
......@@ -109,16 +109,16 @@ do_channel_global_command(struct command *s,
struct exception_handler *e)
{
CAST_SUBTYPE(global_request_command, self, s);
CAST_SUBTYPE(ssh_connection, connection, x);
CAST_SUBTYPE(channel_table, table, x);
struct lsh_string *request
= FORMAT_GLOBAL_REQUEST(self, connection, &c);
= FORMAT_GLOBAL_REQUEST(self, table, &c);
if (CONTINUATION_USED_P(c))
object_queue_add_tail(&connection->table->pending_global_requests,
object_queue_add_tail(&table->pending_global_requests,
&make_command_context(c, e)->super);
connection_send(connection, request);
A_WRITE(table->write, request);
}
void
......@@ -129,18 +129,18 @@ do_install_global_request_handler(struct command_2 *s,
struct exception_handler *e UNUSED)
{
CAST(install_info, self, s);
CAST(ssh_connection, connection, a1);
CAST(channel_table, table, a1);
CAST_SUBTYPE(global_request, handler, a2);
assert(handler);
trace("Installing global request handler for '%a'\n", self->name);
ALIST_SET(connection->table->global_requests,
ALIST_SET(table->global_requests,
self->name,
&handler->super);
COMMAND_RETURN(c, connection);
COMMAND_RETURN(c, table);
}
void
......@@ -151,18 +151,18 @@ do_install_channel_open_handler(struct command_2 *s,
struct exception_handler *e UNUSED)
{
CAST(install_info, self, s);
CAST(ssh_connection, connection, a1);
CAST(channel_table, table, a1);
CAST_SUBTYPE(channel_open, handler, a2);
assert(handler);
trace("Installing channel open handler for '%a'\n", self->name);
ALIST_SET(connection->table->channel_types,
ALIST_SET(table->channel_types,
self->name,
&handler->super);
COMMAND_RETURN(c, connection);
COMMAND_RETURN(c, table);
}
......@@ -185,11 +185,11 @@ do_install_fix_global_request_handler(struct command *s,
struct exception_handler *e UNUSED)
{
CAST(install_global_request_handler, self, s);
CAST(ssh_connection, connection, x);
CAST(channel_table, table, x);
trace("Installing fix global request handler for '%a'\n", self->name);
ALIST_SET(connection->table->global_requests,
ALIST_SET(table->global_requests,
self->name,
&self->handler->super);
......@@ -228,16 +228,15 @@ do_install_fix_channel_open_handler(struct command *s,
struct exception_handler *e UNUSED)
{
CAST(install_channel_open_handler, self, s);
CAST(ssh_connection, connection, x);
CAST(channel_table, table, x);
trace("Installing fix channel open handler for type '%a'\n", self->name);
ALIST_SET(connection->table
->channel_types,
ALIST_SET(table->channel_types,
self->name,
&self->handler->super);
COMMAND_RETURN(c, connection);
COMMAND_RETURN(c, table);
}
struct command *
......
......@@ -43,7 +43,7 @@
; and create a channel open request by calling
; prepare_channel_open.
(new_channel method "struct ssh_channel *"
"struct ssh_connection *connection"
"struct channel_table *table"
"uint32_t local_channel_number"
"struct lsh_string **request")))
*/
......@@ -84,12 +84,12 @@ void do_channel_request_command(struct command *s,
(super command)
(vars
(format_request method "struct lsh_string *"
"struct ssh_connection *connection"
"struct channel_table *table"
"struct command_continuation **c")))
*/
#define FORMAT_GLOBAL_REQUEST(r, conn, c) \
((r)->format_request((r), (conn), (c)))
#define FORMAT_GLOBAL_REQUEST(r, t, c) \
((r)->format_request((r), (t), (c)))
void do_channel_global_command(struct command *s,
......
......@@ -379,14 +379,14 @@ make_handle_exit_signal(int *exit_status)
static struct ssh_channel *
new_session(struct channel_open_command *s,
struct ssh_connection *connection,
struct channel_table *table,
uint32_t local_channel_number,
struct lsh_string **request)
{
CAST(session_open_command, self, s);
struct ssh_channel *res;
self->session->connection = connection;
self->session->table = table;
*request = format_channel_open(ATOM_SESSION,
local_channel_number,
......
......@@ -111,8 +111,8 @@ do_client_winch_handler(struct window_change_callback *s,
if (!INTERACT_WINDOW_SIZE(tty, &dims))
return;
connection_send(self->channel->connection,
format_window_change(self->channel, &dims));
A_WRITE(self->channel->table->write,
format_window_change(self->channel, &dims));
}
static struct window_change_callback *
......
......@@ -45,6 +45,7 @@
#include "channel_forward.h"
#include "format.h"
#include "lsh_string.h"
#include "randomness.h"
#include "ssh.h"
#include "werror.h"
#include "xalloc.h"
......@@ -422,7 +423,7 @@ make_exc_x11_connect_handler(struct exception_handler *parent,
DEFINE_CHANNEL_OPEN(channel_open_x11)
(struct channel_open *s UNUSED,
struct ssh_connection *connection,
struct channel_table *table,
struct channel_open_info *info UNUSED,
struct simple_buffer *args,
struct command_continuation *c,
......@@ -436,12 +437,11 @@ DEFINE_CHANNEL_OPEN(channel_open_x11)
&& parse_uint32(args, &originator_port)
&& parse_eod(args))
{
struct client_x11_display *display = connection->table->x11_display;
struct client_x11_display *display = table->x11_display;
verbose("x11 connection attempt, originator: %s:%i\n",
originator_length, originator, originator_port);
if (display)
{
struct lsh_fd *fd
......@@ -453,7 +453,7 @@ DEFINE_CHANNEL_OPEN(channel_open_x11)
make_exc_x11_connect_handler(e, HANDLER_CONTEXT));
if (fd)
remember_resource(connection->resources, &fd->super);
remember_resource(table->resources, &fd->super);
else
EXCEPTION_RAISE(e,
make_channel_open_exception(SSH_OPEN_CONNECT_FAILED,
......@@ -470,7 +470,7 @@ DEFINE_CHANNEL_OPEN(channel_open_x11)
else
{
werror("do_channel_open_x11: Invalid message!\n");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_OPEN x11 message.");
PROTOCOL_ERROR(table->e, "Invalid CHANNEL_OPEN x11 message.");
}
}
......@@ -616,7 +616,7 @@ make_client_x11_display(const char *display, struct lsh_string *fake)
(name client_x11_display_resource)
(super resource)
(vars
(connection object ssh_connection)
(table object channel_table)
(display object client_x11_display)))
*/
......@@ -629,21 +629,21 @@ do_kill_x11_display(struct resource *s)
{
self->super.alive = 0;
if (self->connection->table->x11_display == self->display)
self->connection->table->x11_display = NULL;
if (self->table->x11_display == self->display)
self->table->x11_display = NULL;
else
werror("do_kill_x11_display: Display has been replaced.\n");
}
}
static struct resource *
make_client_x11_display_resource(struct ssh_connection *connection,
make_client_x11_display_resource(struct channel_table *table,
struct client_x11_display *display)
{
NEW(client_x11_display_resource, self);
init_resource(&self->super, do_kill_x11_display);
self->connection = connection;
self->table = table;
self->display = display;
return &self->super;
......@@ -654,7 +654,7 @@ make_client_x11_display_resource(struct ssh_connection *connection,
(name request_x11_continuation)
(super command_continuation)
(vars
(connection object ssh_connection)
(table object channel_table)
(display object client_x11_display)
(up object command_continuation)))
*/
......@@ -668,27 +668,27 @@ do_request_x11_continuation(struct command_continuation *s,
verbose("X11 request succeeded\n");
if (self->connection->table->x11_display)
if (self->table->x11_display)
werror("client_x11.c: Replacing old x11 forwarding.\n");
self->connection->table->x11_display = self->display;
self->table->x11_display = self->display;
remember_resource(channel->resources,
make_client_x11_display_resource(self->connection,
make_client_x11_display_resource(self->table,
self->display));
COMMAND_RETURN(self->up, a);
}
static struct command_continuation *
make_request_x11_continuation(struct ssh_connection *connection,
make_request_x11_continuation(struct channel_table *table,
struct client_x11_display *display,
struct command_continuation *up)
{
NEW(request_x11_continuation, self);
self->super.c = do_request_x11_continuation;
self->connection = connection;
self->table = table;
self->display = display;
self->up = up;
......@@ -713,7 +713,7 @@ do_format_request_x11_forward(struct channel_request_command *s,
verbose("Requesting X11 forwarding.\n");
*c = make_request_x11_continuation(channel->connection,
*c = make_request_x11_continuation(channel->table,
self->display, *c);
/* NOTE: The cookie is hex encoded, appearantly so that it can be
......
......@@ -68,13 +68,13 @@ do_receive(struct ssh_channel *c,
switch(type)
{
case CHANNEL_DATA:
connection_send(channel->chain->super.connection,
channel_transmit_data(&channel->chain->super, data));
A_WRITE(channel->chain->super.table->write,
channel_transmit_data(&channel->chain->super, data));
break;
case CHANNEL_STDERR_DATA:
connection_send(channel->chain->super.connection,
channel_transmit_extended(&channel->chain->super,
CHANNEL_STDERR_DATA, data));
A_WRITE(channel->chain->super.table->write,
channel_transmit_extended(&channel->chain->super,
CHANNEL_STDERR_DATA, data));
break;
default:
fatal("Internal error!\n");
......@@ -157,7 +157,7 @@ make_gateway_channel(struct alist *request_types)
static struct ssh_channel *
do_gateway_channel_open(struct channel_open_command *c,
struct ssh_connection *connection,
struct channel_table *table,
uint32_t local_channel_number,
struct lsh_string **request)
{
......@@ -169,7 +169,7 @@ do_gateway_channel_open(struct channel_open_command *c,
target->super.rec_window_size = closure->rec_window_size;
target->super.rec_max_packet = closure->rec_max_packet;
target->super.connection = connection;
target->super.table = table;
*request = format_channel_open_s(closure->type,
local_channel_number,
......@@ -261,7 +261,6 @@ do_gateway_channel_request(struct channel_request *s UNUSED,
struct channel_request gateway_channel_request =
{ STATIC_HEADER, do_gateway_channel_request };
/* GABA:
(class
(name general_global_request_command)
......@@ -272,7 +271,7 @@ struct channel_request gateway_channel_request =
static struct lsh_string *
do_format_general_global_request(struct global_request_command *s,
struct ssh_connection *connection UNUSED,
struct channel_table *table UNUSED,
struct command_continuation **c UNUSED)
{
CAST(general_global_request_command, self, s);
......@@ -295,7 +294,7 @@ make_general_global_request_command(struct lsh_string *request)
static void
do_gateway_global_request(struct global_request *s UNUSED,
struct ssh_connection *connection,
struct channel_table *table,
uint32_t type,
int want_reply,
struct simple_buffer *args,
......@@ -308,7 +307,7 @@ do_gateway_global_request(struct global_request *s UNUSED,
struct command *send = make_general_global_request_command(request);
COMMAND_CALL(send, connection->chain, c, e);
COMMAND_CALL(send, table->chain, c, e);
}
struct global_request gateway_global_request =
......@@ -373,7 +372,7 @@ make_gateway_channel_open_continuation(struct command_continuation *up,
static void
do_channel_open_forward(struct channel_open *s UNUSED,
struct ssh_connection *connection,
struct channel_table *table,
struct channel_open_info *info,
struct simple_buffer *args,
struct command_continuation *c,
......@@ -383,7 +382,7 @@ do_channel_open_forward(struct channel_open *s UNUSED,
= make_gateway_channel_open_command(info, parse_rest_copy(args), NULL);
COMMAND_CALL(command,
connection->chain,