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

* Lots of files: Removed the exception argument from the

A_WRITE-method.

Rev: src/abstract_io.h:1.30
Rev: src/blocking_write.c:1.14
Rev: src/blocking_write.h:1.7
Rev: src/channel.c:1.53
Rev: src/channel_commands.c:1.14
Rev: src/client.c:1.72
Rev: src/client_keyexchange.c:1.31
Rev: src/client_userauth.c:1.19
Rev: src/compress.c:1.7
Rev: src/connection.c:1.39
Rev: src/connection.h:1.35
Rev: src/connection_commands.c:1.11
Rev: src/debug.c:1.28
Rev: src/encrypt.c:1.21
Rev: src/exception.c:1.5
Rev: src/io.c:1.71
Rev: src/keyexchange.c:1.54
Rev: src/lsh_keygen.c:1.14
Rev: src/lsh_writekey.c:1.11
Rev: src/pad.c:1.24
Rev: src/read_data.c:1.22
Rev: src/read_packet.c:1.42
Rev: src/server.c:1.59
Rev: src/server_keyexchange.c:1.29
Rev: src/server_password.c:1.22
Rev: src/server_session.c:1.14
Rev: src/server_userauth.c:1.15
Rev: src/sexp_test.c:1.11
Rev: src/tcpforward.c:1.28
Rev: src/unpad.c:1.18
Rev: src/unpad.h:1.11
Rev: src/write_buffer.c:1.20
parent d53b31d0
......@@ -32,6 +32,24 @@
#include "abstract_io.h.x"
#undef GABA_DECLARE
/* GABA:
(class
(name abstract_write)
(vars
(write method void "struct lsh_string *packet")))
*/
#define A_WRITE(f, packet) ((f)->write((f), (packet) ))
/* A handler that passes packets on to another handler */
/* GABA:
(class
(name abstract_write_pipe)
(super abstract_write)
(vars
(next object abstract_write)))
*/
#if 0
/* A read-function returning n means:
*
......@@ -113,22 +131,5 @@
#define READ_DIE 3
#endif
/* GABA:
(class
(name abstract_write)
(vars
(write method void "struct lsh_string *packet" "struct exception_handler *e")))
*/
#define A_WRITE(f, packet, e) ((f)->write((f), (packet), (e)))
/* A handler that passes packets on to another handler */
/* GABA:
(class
(name abstract_write_pipe)
(super abstract_write)
(vars
(next object abstract_write)))
*/
#endif /*LSH_ABSTRACT_IO_H_INCLUDED */
......@@ -32,34 +32,32 @@
(super abstract_write)
(vars
(fd . int)
(e object exception_handler)
(write . (pointer (function void
int UINT32 "UINT8 *" "struct exception_handler *e")))))
*/
#include "blocking_write.c.x"
#if 0
static struct io_exception blocking_io_exception =
STATIC_IO_EXCEPTION(EXC_IO_BLOCKING_WRITE, "Blocking write failed");
#endif
static void do_blocking_write(struct abstract_write *w,
struct lsh_string *packet,
struct exception_handler *e)
struct lsh_string *packet)
{
CAST(blocking_write, closure, w);
closure->write(closure->fd, packet->length, packet->data, e);
closure->write(closure->fd, packet->length, packet->data, closure->e);
lsh_string_free(packet);
}
struct abstract_write *make_blocking_write(int fd, int with_nonblocking)
struct abstract_write *
make_blocking_write(int fd, int with_nonblocking,
struct exception_handler *e)
{
NEW(blocking_write, closure);
closure->super.write = do_blocking_write;
closure->write = (with_nonblocking ? write_raw_with_poll : write_raw);
closure->e = e;
closure->fd = fd;
return &closure->super;
......
......@@ -7,6 +7,8 @@
#include "abstract_io.h"
struct abstract_write *make_blocking_write(int fd, int with_nonblocking);
struct abstract_write *
make_blocking_write(int fd, int with_nonblocking,
struct exception_handler *e);
#endif /* LSH_BLOCKING_WRITE_H_INCLUDED */
......@@ -375,17 +375,14 @@ static void adjust_rec_window(struct flow_controlled *f, UINT32 written)
CAST_SUBTYPE(ssh_channel, channel, f);
A_WRITE(channel->write,
prepare_window_adjust
(channel, written),
channel->e);
prepare_window_adjust(channel, written));
}
void channel_start_receive(struct ssh_channel *channel)
{
A_WRITE(channel->write,
prepare_window_adjust
(channel, channel->max_window - channel->rec_window_size),
channel->e);
(channel, channel->max_window - channel->rec_window_size));
}
#if 0
......@@ -452,9 +449,11 @@ static int channel_process_status(struct channel_table *table,
lsh_string_free((s)); \
return; } while(0)
#if 0
#define ERROR(e, msg) \
EXCEPTION_RAISE(e, make_protocol_exception \
(SSH_DISCONNECT_PROTOCOL_ERROR, msg))
#endif
/* Channel related messages */
......@@ -508,11 +507,10 @@ do_global_request_response(struct global_request_callback *c,
/* FIXME: Perhaps install some exception handler that cancels
* the queue as soon as a write failes. */
A_WRITE(self->super.connection->write,
C_WRITE(self->super.connection,
(n->status
? format_global_success()
: format_global_failure()),
self->super.connection->e);
: format_global_failure()));
}
}
......@@ -575,7 +573,7 @@ static void do_global_request(struct packet_handler *s UNUSED,
}
else
{
ERROR(connection->e, "Invalid SSH_MSG_GLOBAL_REQUEST message.");
PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_GLOBAL_REQUEST message.");
}
lsh_string_free(packet);
}
......@@ -587,7 +585,7 @@ do_global_request_success(struct packet_handler *s UNUSED,
{
if (packet->length != 1)
{
ERROR(connection->e, "Invalid GLOBAL_REQUEST_SUCCESS message.");
PROTOCOL_ERROR(connection->e, "Invalid GLOBAL_REQUEST_SUCCESS message.");
RETURN;
}
......@@ -616,7 +614,7 @@ do_global_request_failure(struct packet_handler *s UNUSED,
{
if (packet->length != 1)
{
ERROR(connection->e, "Invalid GLOBAL_REQUEST_FAILURE message.");
PROTOCOL_ERROR(connection->e, "Invalid GLOBAL_REQUEST_FAILURE message.");
RETURN;
}
......@@ -893,7 +891,7 @@ static void do_channel_open(struct packet_handler *c UNUSED,
}
}
else
ERROR(connection->e, "Invalid SSH_MSG_CHANNEL_OPEN message.");
PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_CHANNEL_OPEN message.");
lsh_string_free(packet);
}
......@@ -945,7 +943,7 @@ do_channel_request(struct packet_handler *closure UNUSED,
}
}
else
ERROR(connection->e, "Invalid SSH_MSG_CHANNEL_REQUEST message.");
PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_CHANNEL_REQUEST message.");
lsh_string_free(packet);
}
......@@ -990,13 +988,13 @@ do_window_adjust(struct packet_handler *closure UNUSED,
* ignored silently? */
werror("SSH_MSG_CHANNEL_WINDOW_ADJUST on nonexistant or closed "
"channel %i\n", channel_number);
ERROR(connection->e, "Unexpected CHANNEL_WINDOW_ADJUST");
PROTOCOL_ERROR(connection->e, "Unexpected CHANNEL_WINDOW_ADJUST");
}
}
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_WINDOW_ADJUST message.");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_WINDOW_ADJUST message.");
}
}
......@@ -1063,7 +1061,7 @@ do_channel_data(struct packet_handler *closure UNUSED,
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_DATA message.");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_DATA message.");
}
}
......@@ -1143,7 +1141,7 @@ do_channel_extended_data(struct packet_handler *closure UNUSED,
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_EXTENDED_DATA message.");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_EXTENDED_DATA message.");
}
}
......@@ -1173,10 +1171,8 @@ do_channel_eof(struct packet_handler *closure UNUSED,
if (channel->flags & (CHANNEL_RECEIVED_EOF | CHANNEL_RECEIVED_CLOSE))
{
werror("Receiving EOF on channel on closed channel.\n");
EXCEPTION_RAISE
(connection->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Received EOF on channel on closed channel."));
PROTOCOL_ERROR(connection->e,
"Received EOF on channel on closed channel.");
}
else
{
......@@ -1195,13 +1191,13 @@ do_channel_eof(struct packet_handler *closure UNUSED,
{
werror("EOF on non-existant channel %i\n",
channel_number);
ERROR(connection->e, "EOF on non-existant channel");
PROTOCOL_ERROR(connection->e, "EOF on non-existant channel");
}
}
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_EOF message");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_EOF message");
}
}
......@@ -1231,7 +1227,7 @@ do_channel_close(struct packet_handler *closure UNUSED,
if (channel->flags & CHANNEL_RECEIVED_CLOSE)
{
werror("Receiving multiple CLOSE on channel.\n");
ERROR(connection->e, "Receiving multiple CLOSE on channel.");
PROTOCOL_ERROR(connection->e, "Receiving multiple CLOSE on channel.");
}
else
{
......@@ -1263,13 +1259,13 @@ do_channel_close(struct packet_handler *closure UNUSED,
{
werror("CLOSE on non-existant channel %i\n",
channel_number);
ERROR(connection->e, "CLOSE on non-existant channel");
PROTOCOL_ERROR(connection->e, "CLOSE on non-existant channel");
}
}
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_CLOSE message");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_CLOSE message");
}
}
......@@ -1315,13 +1311,13 @@ do_channel_open_confirm(struct packet_handler *closure UNUSED,
{
werror("Unexpected SSH_MSG_CHANNEL_OPEN_CONFIRMATION on channel %i\n",
local_channel_number);
ERROR(connection->e, "Unexpected CHANNEL_OPEN_CONFIRMATION.");
PROTOCOL_ERROR(connection->e, "Unexpected CHANNEL_OPEN_CONFIRMATION.");
}
}
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_OPEN_CONFIRMATION message.");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_OPEN_CONFIRMATION message.");
}
}
......@@ -1372,7 +1368,7 @@ do_channel_open_failure(struct packet_handler *closure UNUSED,
}
else
{
ERROR(connection->e, "Invalid CHANNEL_OPEN_FAILURE message.");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_OPEN_FAILURE message.");
lsh_string_free(packet);
}
}
......@@ -1412,7 +1408,7 @@ do_channel_success(struct packet_handler *closure UNUSED,
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_SUCCESS message");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_SUCCESS message");
}
}
......@@ -1454,7 +1450,7 @@ do_channel_failure(struct packet_handler *closure UNUSED,
else
{
lsh_string_free(packet);
ERROR(connection->e, "Invalid CHANNEL_FAILURE message.");
PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_FAILURE message.");
}
}
......@@ -1574,7 +1570,7 @@ void channel_close(struct ssh_channel *channel)
channel->flags |= CHANNEL_SENT_CLOSE;
A_WRITE(channel->write, format_channel_close(channel), channel->e);
A_WRITE(channel->write, format_channel_close(channel) );
if (channel->flags & CHANNEL_RECEIVED_CLOSE)
EXCEPTION_RAISE(channel->e, &finish_exception);
......@@ -1592,7 +1588,7 @@ void channel_eof(struct ssh_channel *channel)
assert(! (channel->flags & CHANNEL_SENT_EOF));
channel->flags |= CHANNEL_SENT_EOF;
A_WRITE(channel->write, format_channel_eof(channel), channel->e);
A_WRITE(channel->write, format_channel_eof(channel) );
if ( (channel->flags & CHANNEL_CLOSE_AT_EOF)
&& (channel->flags & CHANNEL_RECEIVED_EOF))
......@@ -1666,27 +1662,26 @@ struct lsh_string *channel_transmit_extended(struct ssh_channel *channel,
(type simple UINT32)))
*/
static void do_channel_write(struct abstract_write *w,
struct lsh_string *packet,
struct exception_handler *e)
static void
do_channel_write(struct abstract_write *w,
struct lsh_string *packet)
{
struct channel_write *closure = (struct channel_write *) w;
A_WRITE(closure->channel->write,
channel_transmit_data(closure->channel, packet), e);
channel_transmit_data(closure->channel, packet) );
}
static void do_channel_write_extended(struct abstract_write *w,
struct lsh_string *packet,
struct exception_handler *e)
static void
do_channel_write_extended(struct abstract_write *w,
struct lsh_string *packet)
{
CAST(channel_write_extended, closure, w);
A_WRITE(closure->super.channel->write,
channel_transmit_extended(closure->super.channel,
closure->type,
packet),
e);
packet));
}
struct abstract_write *make_channel_write(struct ssh_channel *channel)
......
......@@ -76,7 +76,7 @@ void do_channel_request_command(struct command *s,
object_queue_add_tail(&channel->pending_requests,
&make_command_context(c, e)->super);
A_WRITE(channel->write, request, e);
A_WRITE(channel->write, request);
}
void do_channel_global_command(struct command *s,
......
......@@ -93,9 +93,7 @@ do_accept_service(struct packet_handler *c,
else
{
lsh_string_free(packet);
EXCEPTION_RAISE(closure->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Invalid SSH_MSG_SERVICE_ACCEPT message"));
PROTOCOL_ERROR(closure->e, "Invalid SSH_MSG_SERVICE_ACCEPT message");
}
}
......@@ -248,10 +246,7 @@ do_exit_status(struct channel_request *c,
}
else
/* Invalid request */
EXCEPTION_RAISE
(channel->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Invalid exit-status message"));
PROTOCOL_ERROR(channel->e, "Invalid exit-status message");
}
static void
......@@ -303,10 +298,7 @@ do_exit_signal(struct channel_request *c,
}
else
/* Invalid request */
EXCEPTION_RAISE
(channel->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Invalid exit-signal message"));
PROTOCOL_ERROR(channel->e, "Invalid exit-signal message");
}
struct channel_request *make_handle_exit_status(int *exit_status)
......@@ -341,10 +333,10 @@ do_receive(struct ssh_channel *c,
switch(type)
{
case CHANNEL_DATA:
A_WRITE(&closure->out->write_buffer->super, data, c->e);
A_WRITE(&closure->out->write_buffer->super, data);
break;
case CHANNEL_STDERR_DATA:
A_WRITE(&closure->err->write_buffer->super, data, c->e);
A_WRITE(&closure->err->write_buffer->super, data);
break;
default:
fatal("Internal error!\n");
......
......@@ -117,9 +117,7 @@ do_handle_dh_reply(struct packet_handler *c,
werror("Installing new keys failed. Hanging up.\n");
KILL(hash);
EXCEPTION_RAISE(connection->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Refusing to use weak key."));
PROTOCOL_ERROR(connection->e, "Refusing to use weak key.");
return;
}
......
......@@ -150,10 +150,7 @@ do_userauth_success(struct packet_handler *c,
else
{
lsh_string_free(packet);
EXCEPTION_RAISE
(connection->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Invalid USERAUTH_SUCCESS message"));
PROTOCOL_ERROR(connection->e, "Invalid USERAUTH_SUCCESS message");
}
}
......@@ -209,10 +206,7 @@ do_userauth_failure(struct packet_handler *c,
{
KILL(methods);
lsh_string_free(packet);
EXCEPTION_RAISE
(connection->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Invalud USERAUTH_FAILURE message."));
PROTOCOL_ERROR(connection->e, "Invalid USERAUTH_FAILURE message.");
}
}
......@@ -244,10 +238,7 @@ do_userauth_banner(struct packet_handler *closure,
werror("%ups", length, msg);
}
else
EXCEPTION_RAISE
(connection->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Invalid USERAUTH_SUCCESS message"));
PROTOCOL_ERROR(connection->e, "Invalid USERAUTH_SUCCESS message");
lsh_string_free(packet);
}
......
......@@ -44,8 +44,7 @@
static void
do_packet_deflate(struct abstract_write *closure,
struct lsh_string *packet,
struct exception_handler *e)
struct lsh_string *packet)
{
CAST(packet_compressor, self, closure);
......@@ -55,13 +54,12 @@ do_packet_deflate(struct abstract_write *closure,
assert(packet);
}
A_WRITE(self->super.next, packet, e);
A_WRITE(self->super.next, packet);
}
static void
do_packet_inflate(struct abstract_write *closure,
struct lsh_string *packet,
struct exception_handler *e)
struct lsh_string *packet)
{
CAST(packet_compressor, self, closure);
......@@ -73,17 +71,19 @@ do_packet_inflate(struct abstract_write *closure,
/* FIXME: It would be nice to pass the error message from zlib on
* to the exception handler. */
EXCEPTION_RAISE
(e, make_protocol_exception(SSH_DISCONNECT_COMPRESSION_ERROR,
"Inflating compressed data failed."));
(self->connection->e,
make_protocol_exception(SSH_DISCONNECT_COMPRESSION_ERROR,
"Inflating compressed data failed."));
return;
}
}
A_WRITE(self->super.next, packet, e);
A_WRITE(self->super.next, packet);
}
struct abstract_write *make_packet_codec(struct abstract_write *next,
struct ssh_connection *connection,
int mode)
struct abstract_write *
make_packet_codec(struct abstract_write *next,
struct ssh_connection *connection,
int mode)
{
NEW(packet_compressor, res);
......
......@@ -49,8 +49,7 @@ static const char *packet_types[0x100] =
static void
handle_connection(struct abstract_write *w,
struct lsh_string *packet,
struct exception_handler *ignored UNUSED)
struct lsh_string *packet)
{
CAST(ssh_connection, closure, w);
UINT8 msg;
......@@ -58,9 +57,7 @@ handle_connection(struct abstract_write *w,
if (!packet->length)
{
werror("connection.c: Received empty packet!\n");
EXCEPTION_RAISE(closure->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Received empty packet."));
PROTOCOL_ERROR(closure->e, "Received empty packet.");
return;
}
......@@ -75,9 +72,7 @@ handle_connection(struct abstract_write *w,
if (msg == SSH_MSG_NEWKEYS)
{
werror("Unexpected NEWKEYS message!\n");
EXCEPTION_RAISE(closure->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Unexpected NEWKEYS message!"));
PROTOCOL_ERROR(closure->e, "Unexpected NEWKEYS message!");
return;
}
break;
......@@ -97,9 +92,7 @@ handle_connection(struct abstract_write *w,
|| (msg == SSH_MSG_KEXINIT))
{
werror("Unexpected KEXINIT or NEWKEYS message!\n");
EXCEPTION_RAISE(closure->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Unexpected KEXINIT or NEWKEYS message!"));
PROTOCOL_ERROR(closure->e, "Unexpected KEXINIT or NEWKEYS message!");
return;
}
break;
......@@ -109,9 +102,7 @@ handle_connection(struct abstract_write *w,
{
werror("Expected NEWKEYS message, but received message %i!\n",
msg);
EXCEPTION_RAISE(closure->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR,
"Expected NEWKEYS message"));
PROTOCOL_ERROR(closure->e, "Expected NEWKEYS message");
return;
}
break;
......@@ -131,9 +122,7 @@ do_fail(struct packet_handler *closure,
lsh_string_free(packet);
EXCEPTION_RAISE
(connection->e,
make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR, NULL));
PROTOCOL_ERROR(connection->e, NULL);
}
struct packet_handler *make_fail_handler(void)
......
......@@ -117,7 +117,7 @@ struct ssh_connection;
))
*/
#define C_WRITE(c, s) A_WRITE((c)->write, (s), (c)->e)
#define C_WRITE(c, s) A_WRITE((c)->write, (s) )
struct ssh_connection *make_ssh_connection(struct command_continuation *c);
......
......@@ -127,14 +127,15 @@ do_line(struct line_handler **h,
new =
make_read_packet(
make_packet_unpad(
make_packet_inflate(
make_packet_debug(&closure->connection->super, "received"),
closure->connection
)
),
closure->connection,
make_packet_inflate(
make_packet_debug(&closure->connection->super, "received"),
closure->connection
)
),
closure->connection
);
);
closure->connection->versions[!closure->mode]
= ssh_format("%ls", length, line);
......@@ -301,15 +302,13 @@ do_connection(struct command *s,
if (self->fallback)
{
A_WRITE(connection->raw,
ssh_format("%lS\n", version),
connection->e);
ssh_format("%lS\n", version));
return;
}
#endif /* WITH_SSH1_FALLBACK */
A_WRITE(connection->raw,
ssh_format("%lS\r\n", version),
connection->e);
ssh_format("%lS\r\n", version));
initiate_keyexchange(connection, self->mode);
}
......
......@@ -44,23 +44,23 @@
static void
do_debug(struct abstract_write *</