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

Finally, it compiles.

Rev: src/channel.c:1.51
Rev: src/channel.h:1.41
Rev: src/channel_commands.c:1.13
Rev: src/command.h:1.33
Rev: src/connection.c:1.38
Rev: src/connection.h:1.34
Rev: src/connection_commands.c:1.10
Rev: src/exception.c:1.3
Rev: src/exception.h:1.4
Rev: src/format.c:1.30
Rev: src/io.c:1.69
Rev: src/keyexchange.c:1.53
Rev: src/lsh.c:1.67
Rev: src/lsh_writekey.c:1.10
Rev: src/lshd.c:1.60
Rev: src/read_line.c:1.27
Rev: src/read_line.h:1.15
Rev: src/read_packet.c:1.40
Rev: src/read_scan.h:1.7
Rev: src/server_session.c:1.13
Rev: src/server_userauth.c:1.14
Rev: src/sexp.h:1.16
Rev: src/sexp_streamed_parser.c:1.8
Rev: src/sexp_test.c:1.10
Rev: src/ssh1_fallback.c:1.8
Rev: src/ssh1_fallback.h:1.5
Rev: src/tcpforward.c:1.27
Rev: src/tcpforward_commands.c:1.10
parent acd090d3
......@@ -43,8 +43,22 @@
struct exception *make_channel_open_exception(UINT32 error_code, char *msg)
{
NEW(channel_open_exception, self);
#define MAX_ERROR 4
static const char *msgs[MAX_ERROR + 1] = {
"",
"Administratively prohibited",
"Connect failed",
"Unknown channel type",
"Resource shortage"
};
assert(error_code > 0);
assert(error_code <= MAX_ERROR);
#undef MAX_ERROR
self->super.type = EXC_CHANNEL_OPEN;
self->super.msg = msg;
self->super.msg = msg ? msg : msgs[error_code];
self->error_code = error_code;
return &self->super;
......@@ -461,6 +475,7 @@ static struct global_request_status *make_global_request_status(void)
return self;
}
/* FIXME: Split into a continuation and an exception handler */
/* GABA:
(class
(name global_request_response)
......
......@@ -112,7 +112,7 @@
; Called when eof is received on the channel (or when it is
; closed, whatever happens first).
(eof method int)
(eof method void)
; Reply from SSH_MSG_CHANNEL_OPEN_REQUEST
;; (open_confirm method int)
......@@ -210,15 +210,15 @@
*/
#define GLOBAL_REQUEST_CALLBACK(c, s) \
((c) ? ((c)->response((c), (s))) : LSH_OK | LSH_GOON)
((c)->response((c), (s)))
/* GABA:
(class
(name global_request)
(vars
(handler method int "struct ssh_connection *connection"
"struct simple_buffer *args"
"struct global_request_callback *response")))
(handler method void "struct ssh_connection *connection"
"struct simple_buffer *args"
"struct global_request_callback *response")))
*/
#define GLOBAL_REQUEST(r, c, a, n) ((r)->handler((r), (c), (a), (n)))
......
......@@ -72,7 +72,7 @@ void do_channel_request_command(struct command *s,
struct lsh_string *request
= FORMAT_CHANNEL_REQUEST(self, channel, &c);
if (c)
if (CONTINUATION_USED_P(c))
object_queue_add_tail(&channel->pending_requests,
&make_command_context(c, e)->super);
......@@ -90,7 +90,7 @@ void do_channel_global_command(struct command *s,
struct lsh_string *request
= FORMAT_GLOBAL_REQUEST(self, connection, &c);
if (c)
if (CONTINUATION_USED_P(c))
object_queue_add_tail(&connection->table->pending_global_requests,
&make_command_context(c, e)->super);
......
......@@ -88,6 +88,8 @@ extern struct command_simple progn_command;
extern struct command_continuation discard_continuation;
#define CONTINUATION_USED_P(c) ((c) != &discard_continuation)
/* GABA:
(class
(name command_frame)
......@@ -241,7 +243,7 @@ struct delayed_apply *
make_delayed_apply(struct command *f,
struct lsh_object *a);
#define FORCE_APPLY(d, c, e) COMMAND_CALL((d)->f, (d)->o, (c), (e))
#define FORCE_APPLY(d, c, e) COMMAND_CALL((d)->f, (d)->a, (c), (e))
struct command_continuation *
make_delay_continuation(struct command *f,
......
......@@ -28,6 +28,7 @@
#include "exception.h"
#include "format.h"
#include "disconnect.h"
#include "io.h"
#include "keyexchange.h"
#include "compress.h"
#include "packet_ignore.h"
......@@ -179,7 +180,7 @@ struct packet_handler *make_unimplemented_handler(void)
static void
do_exc_protocol_handler(struct exception_handler *s,
struct exception *e)
const struct exception *e)
{
CAST(exc_protocol_handler, self, s);
......@@ -191,7 +192,7 @@ do_exc_protocol_handler(struct exception_handler *s,
if (exc->reason)
C_WRITE(self->connection, format_disconnect(exc->reason, exc->super.msg, ""));
EXCEPTION_RAISE(self->super.parent, &exception_finish_read);
EXCEPTION_RAISE(self->super.parent, &finish_read_exception);
}
break;
default:
......
......@@ -122,7 +122,7 @@ struct ssh_connection;
struct ssh_connection *make_ssh_connection(struct command_continuation *c);
struct exception_handler *
make_exc_protocol_handler(struct connection *connection,
make_exc_protocol_handler(struct ssh_connection *connection,
struct exception_handler *parent);
void connection_init_io(struct ssh_connection *connection,
......
......@@ -88,7 +88,8 @@ static void
do_line(struct line_handler **h,
struct read_handler **r,
UINT32 length,
UINT8 *line)
UINT8 *line,
struct exception_handler *e)
{
CAST(connection_line_handler, closure, *h);
......@@ -153,7 +154,8 @@ do_line(struct line_handler **h,
*h = NULL;
SSH1_FALLBACK(closure->fallback,
closure->fd,
length, line);
length, line,
e);
return;
}
......
......@@ -25,45 +25,55 @@
#include "io.h"
#include "ssh.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
#define GABA_DEFINE
#include "exception.h.x"
#undef GABA_DEFINE
static void
do_default_handler(struct exception_handler *ignored UNUSED,
struct exception *e)
const struct exception *e)
{
#if 0
if (e->type & EXC_IO)
{
CAST_SUBTYPE(io_exception, io, e);
werror("i/o error (errno = %i): %z\n", io->error, e->name);
werror("i/o error (errno = %i): %z\n", io->error, e->msg);
if (io->fd)
kill_fd(io->fd);
}
else
#endif
fatal("Unhandled exception of type: %z\n", e->type, e->name);
fatal("Unhandled exception of type: %z\n", e->type, e->msg);
}
struct exception_handler default_exception_handler =
{ STATIC_HEADER, do_default_handler };
struct exception dummy_exception =
{ STATIC_HEADER, LSH_DUMMY, "dummy" };
{ STATIC_HEADER, EXC_DUMMY, "dummy" };
static void
do_ignore_exception_handler(struct exception_handler *self UNUSED,
struct exception *e UNUSED)
const struct exception *e UNUSED)
{}
struct exception_handler ignore_exception_handler =
{ STATIC_HEADER, do_ignore_exception_handler };
struct exception *make_simple_exception(UNIT32 type, const char *name)
struct exception *make_simple_exception(UINT32 type, const char *msg)
{
NEW(exception, e);
e->type = type;
e->name = name;
e->msg = msg;
return e;
}
struct exception *
......@@ -82,13 +92,13 @@ make_protocol_exception(UINT32 reason, const char *msg)
"Connection lost", "By application"
};
assert(reason >= 0);
assert(reason > 0);
assert(reason <= MAX_REASON);
#undef MAX_REASON
self->super.type = EXC_PROTOCOL;
self->super.name = msg ? msg : messages[reason];
self->super.msg = msg ? msg : messages[reason];
self->reason = reason;
......
......@@ -26,7 +26,9 @@
#include "lsh.h"
#define GABA_DECLARE
#include "exception.h.x"
#undef GABA_DECLARE
/* GABA:
(class
......@@ -118,7 +120,7 @@ extern struct exception dummy_exception;
*/
struct exception *
make_simple_exception(UINT32 type, int name);
make_simple_exception(UINT32 type, const char *msg);
/* A protocol exception, that normally terminates the connection */
/* GABA:
......
......@@ -301,7 +301,7 @@ void ssh_vformat_write(const char *f, UINT32 size, UINT8 *buffer, va_list args)
goto end_options;
}
}
end_options:
end_options:
if (literal && decimal)
fatal("Internal error!\n");
......
......@@ -662,33 +662,79 @@ static void init_file(struct io_backend *b, struct lsh_fd *f, int fd,
b->files = f;
}
/* FIXME: How to do this when mocing from return codes to exceptions? */
#if 0
/* Blocking read from a file descriptor (i.e. don't use the backend).
* The fd should *not* be in non-blocking mode. */
int blocking_read(int fd, struct read_handler *handler)
/* FIXME: How to do this when moving from return codes to exceptions? */
/* FIXME: The entire blocking_read mechanism should be replaced by
* ordinary commands and non-blocking i/o command. Right now, it is
* used to read key-files, so that change probably has to wait until
* the parser is rewritten. */
#if 0
/* ;; GABA:
(class
(name blocking_read_exception_handler)
(super exception_handler)
(vars
(flag . int)))
*/
static void
do_blocking_read_handler(struct exception_handler *s,
const struct exception *e UNUSED)
{
struct fd_read r =
{ { STACK_HEADER, do_read }, fd };
CAST(blocking_read_exception_handler, self, s);
self->flag = 1;
}
#endif
#define BLOCKING_READ_SIZE 4096
int blocking_read(int fd, struct read_handler *handler)
{
#if 0
struct blocking_read_exception_handler exc_handler =
{
{ STACK_HEADER, do_blocking_read_handler },
0
};
#endif
char *buffer = alloca(BLOCKING_READ_SIZE);
for (;;)
{
int res = READ_HANDLER(handler,
&r.super);
assert(!(res & (LSH_HOLD | LSH_KILL_OTHERS)));
if (res & (LSH_CLOSE | LSH_DIE))
int res = read(fd, buffer, BLOCKING_READ_SIZE);
if (res < 0)
switch(errno)
{
case EINTR:
break;
case EWOULDBLOCK:
fatal("blocking_read: Unexpected EWOULDBLOCK! fd in non-blocking mode?\n");
default:
werror("blocking_read: read() failed (errno = %i): %z\n",
errno, strerror(errno));
return 0;
}
else if (!res)
return 1;
else
{
close(fd);
return res;
UINT32 got = res;
UINT32 done = 0;
while (handler
&& (done < got))
done += READ_HANDLER(handler, got - done, buffer + done);
}
if (res & LSH_FAIL)
werror("blocking_read: Ignoring error %i\n", res);
}
close(fd);
return !handler;
}
#endif
/* Converts a string port number or service name to a port number.
* Returns the port number in _host_ byte order, or -1 of the port
......@@ -920,18 +966,17 @@ void write_raw(int fd, UINT32 length, UINT8 *data,
continue;
default:
EXCEPTION_RAISE(e, make_io_exception(EXC_IO_BLOCKING_WRITE,
NULL, errno));
NULL, errno, NULL));
return;
}
length -= written;
data += written;
}
return 1;
}
void write_raw_with_poll(int fd, UINT32 length, UINT8 *data,
struct exception_handler *e */)
struct exception_handler *e)
{
while(length)
{
......@@ -952,7 +997,7 @@ void write_raw_with_poll(int fd, UINT32 length, UINT8 *data,
continue;
default:
EXCEPTION_RAISE(e, make_io_exception(EXC_IO_BLOCKING_WRITE,
NULL, errno));
NULL, errno, NULL));
}
written = write(fd, data, length);
......@@ -965,13 +1010,12 @@ void write_raw_with_poll(int fd, UINT32 length, UINT8 *data,
continue;
default:
EXCEPTION_RAISE(e, make_io_exception(EXC_IO_BLOCKING_WRITE,
NULL, errno));
NULL, errno, NULL));
}
length -= written;
data += written;
}
return 1;
}
void io_set_nonblocking(int fd)
......@@ -1092,7 +1136,7 @@ static void really_close(struct lsh_fd *fd)
{
CAST(io_fd, self, fd);
assert(self->buffer);
assert(self->write_buffer);
write_buffer_close(self->write_buffer);
}
......@@ -1207,8 +1251,8 @@ void close_fd_nicely(struct lsh_fd *fd, int reason)
/* Don't attempt to read any further. */
/* FIXME: Is it safe to free the handler here? */
self->want_read = 0;
self->read = NULL;
fd->want_read = 0;
fd->read = NULL;
if (fd->really_close)
/* Mark the write_buffer as closed */
......@@ -1234,7 +1278,7 @@ void close_fd_nicely(struct lsh_fd *fd, int reason)
static void
do_exc_finish_read_handler(struct exception_handler *s,
struct exception *e)
const struct exception *e)
{
CAST(exc_finish_read_handler, self, s);
switch(e->type)
......
......@@ -309,8 +309,9 @@ do_handle_kexinit(struct packet_handler *c,
{
CAST_SUBTYPE(keyexchange_algorithm, kex_algorithm,
ALIST_GET(closure->algorithms, kex_algorithm_atom));
CAST_SUBTYPE(hostkey_algorithm, ALIST_GET(closure->algorithms,
hostkey_algorithm_atom));
CAST_SUBTYPE(signature_algorithm, hostkey_algorithm,
ALIST_GET(closure->algorithms,
hostkey_algorithm_atom));
KEYEXCHANGE_INIT( kex_algorithm,
connection,
hostkey_algorithm_atom,
......
......@@ -239,7 +239,7 @@ do_lsh_default_handler(struct exception_handler *s,
werror("lsh: Service denied: %z\n", e->msg);
break;
default:
EXCEPTION_RAISE(self->parent, e);
EXCEPTION_RAISE(self->super.parent, e);
}
*self->status = EXIT_FAILURE;
}
......
......@@ -54,7 +54,7 @@ do_lsh_writekey_handler(struct exception_handler *s UNUSED,
exit(EXIT_FAILURE);
}
static struct exception_handler handler =
static struct exception_handler exc_handler =
STATIC_EXCEPTION_HANDLER(do_lsh_writekey_handler, NULL);
/* FIXME: Should support encryption of the private key. */
......@@ -158,13 +158,15 @@ do_write_key(struct sexp_handler *h, struct sexp *private)
A_WRITE(make_blocking_write(public_fd, 0),
sexp_format(public, SEXP_TRANSPORT, 0),
&handler);
&exc_handler);
A_WRITE(make_blocking_write(private_fd, 0),
sexp_format(private, SEXP_CANONICAL, 0),
&handler);
&exc_handler);
*closure->status = EXIT_SUCCESS;
return LSH_OK | LSH_CLOSE;
}
#define BLOCK_SIZE 2000
......@@ -236,8 +238,9 @@ int main(int argc UNUSED, char **argv UNUSED)
handler->public_file = public;
handler->private_file = private;
io_read(make_io_fd(backend, STDIN_FILENO),
make_read_sexp(&handler->super, BLOCK_SIZE, SEXP_TRANSPORT, 0),
io_read(make_io_fd(backend, STDIN_FILENO, &exc_handler),
make_buffered_read(BLOCK_SIZE,
make_read_sexp(&handler->super, SEXP_TRANSPORT, 0)),
NULL);
io_run(backend);
......
......@@ -37,6 +37,7 @@
#include "server_password.h"
#include "server_session.h"
#include "randomness.h"
#include "read_scan.h"
#include "reaper.h"
#include "server.h"
#include "server_keyexchange.h"
......@@ -116,7 +117,8 @@ static int do_read_key(struct sexp_handler *h, struct sexp *private)
struct sexp_iterator *i;
struct sexp *e;
mpz_t p, q, g, y, x;
int res;
if (!sexp_check_type(private, "private-key", &i))
{
werror("lshd: Host key file does not contain a private key.");
......@@ -226,17 +228,11 @@ static int read_host_key(const char *name,
handler->keys = keys;
res = blocking_read(fd, make_read_sexp(&handler->super,
2000, SEXP_TRANSPORT, 0));
SEXP_TRANSPORT, 0));
close(fd);
KILL(handler);
if (LSH_FAILUREP(res))
{
werror("lshd: Invalid host key.\n");
return 0;
}
return 1;
}
}
......
......@@ -99,9 +99,9 @@ do_read_line(struct read_handler **h,
if (length && (data[length-1] == 0xd))
length--;
/* NOTE: This call can modify both self->handler and *r. */
PROCESS_LINE(self->handler, h, length, self->buffer);
/* NOTE: This call can modify both self->handler and *h. */
PROCESS_LINE(self->handler, h, length, self->buffer, self->e);
/* Reset */
self->pos = 0;
......
......@@ -45,11 +45,12 @@
(name line_handler)
(vars
(handler indirect-method void "struct read_handler **r"
"UINT32 length" "UINT8 *line")))
"UINT32 length" "UINT8 *line"
"struct exception_handler *e")))
*/
#define PROCESS_LINE(h, r, length, line) \
((h)->handler(&(h), (r), (length), (line)))
#define PROCESS_LINE(h, r, length, line, e) \
((h)->handler(&(h), (r), (length), (line), (e)))
struct read_handler *make_read_line(struct line_handler *handler,
struct exception_handler *e);
......
......@@ -127,12 +127,12 @@ static const struct io_exception read_eof =
STATIC_IO_EXCEPTION(EXC_IO_EOF, "read_packet: Read EOF");
#endif
#define READ(n, dst) do { \
memcpy((dst) + closure->pos, data, (n)); \
closure->pos += (n); \
data += (n); \
total += (n); \
available -= (n); \
#define READ(n, dst) do { \
memcpy((dst)->data + closure->pos, data, (n)); \
closure->pos += (n); \
data += (n); \
total += (n); \
available -= (n); \
} while (0)
static UINT32
......
......@@ -46,6 +46,7 @@
#define LSH_FAIL 1
#define LSH_CLOSE 2
#define LSH_SYNTAX 4
#define LSH_DIE 8
#define TOKEN_EOF -1
#define TOKEN_EOS -2
......
......@@ -282,16 +282,14 @@ struct ssh_channel *make_server_session(struct unix_user *user,
#define WINDOW_SIZE (SSH_MAX_PACKET << 3)
static int do_open_session(struct channel_open *s,
struct ssh_connection *connection UNUSED,
struct simple_buffer *args,
struct command_continuation *c,
struct exception_handler *e)
static void
do_open_session(struct channel_open *s,
struct ssh_connection *connection UNUSED,
struct simple_buffer *args,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(open_session, closure, s);
struct ssh_channel *session = NULL;
UINT32 error;
char *error_msg;
debug("server.c: do_open_session()\n");
......@@ -937,11 +935,12 @@ struct channel_request *make_shell_handler(struct io_backend *backend,
#if WITH_PTY_SUPPORT
/* pty_handler */
static int do_alloc_pty(struct channel_request *c UNUSED,
struct ssh_channel *channel,
struct ssh_connection *connection UNUSED,
int want_reply,
struct simple_buffer *args)
static void
do_alloc_pty(struct channel_request *c UNUSED,
struct ssh_channel *channel,
struct ssh_connection *connection UNUSED,
int want_reply,
struct simple_buffer *args)
{
UINT32 width, height, width_p, height_p;
UINT8 *mode;
......@@ -1007,6 +1006,7 @@ static int do_alloc_pty(struct channel_request *c UNUSED,
verbose(" failed.\n");
lsh_string_free(term);
if (want_reply)
A_WRITE(channel->write, format_channel_failure(channel->channel_number),
channel->e);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment