Commit 37173087 authored by Balázs Scheidler's avatar Balázs Scheidler Committed by Niels Möller
Browse files

* src/proxy.c: Updated to Bazsi's latest version.

Rev: src/proxy.c:1.4
Rev: src/proxy.h:1.3
parent 39d788ee
......@@ -22,6 +22,7 @@
*/
#include "proxy.h"
#include "proxy_channel.h"
#include "proxy_session.h"
#include "proxy_userauth.h"
#include "channel_commands.h"
......@@ -32,12 +33,61 @@
#include "format.h"
#include "io_commands.h"
#include "ssh.h"
#include "werror.h"
#include <assert.h>
#include <arpa/inet.h>
#include "proxy.c.x"
/* GABA:
(class
(name exc_chain_connections_handler)
(super exception_handler)
(vars
(connection object ssh_connection)))
*/
static void
do_exc_chain_connections_handler(struct exception_handler *c,
const struct exception *e)
{
CAST(exc_chain_connections_handler, self, c);
switch (e->type)
{
case EXC_FINISH_READ:
case EXC_FINISH_IO:
{
struct ssh_connection *chain = self->connection->chain;
if (chain)
{
self->connection->chain->chain = NULL;
self->connection->chain = NULL; /* prevent raising this exception again */
/* FIXME: is it possible to pass the same exception to two handlers? */
EXCEPTION_RAISE(chain->e, e);
}
}
default:
EXCEPTION_RAISE(c->parent, e);
}
}
static struct exception_handler *
make_exc_chain_connections_handler(struct ssh_connection *connection,
struct exception_handler *parent,
const char *context)
{
NEW(exc_chain_connections_handler, self);
self->super.parent = parent;
self->super.raise = do_exc_chain_connections_handler;
self->super.context = context;
self->connection = connection;
return &self->super;
}
/* GABA:
(class
(name chain_connections_continuation)
......@@ -55,12 +105,23 @@ do_chain_connections_continuation(struct command_continuation *s,
self->connection->chain = chained;
chained->chain = self->connection;
/* FIXME: this a little bit kludgy here */
self->connection->e =
make_exc_chain_connections_handler(self->connection,
self->connection->e,
HANDLER_CONTEXT);
chained->e =
make_exc_chain_connections_handler(chained,
chained->e,
HANDLER_CONTEXT);
COMMAND_RETURN(self->super.up, &self->connection->super.super);
}
static struct command_continuation *
make_chain_connections_continuation(struct ssh_connection *connection,
struct command_continuation *c)
struct command_continuation *c)
{
NEW(chain_connections_continuation, self);
......@@ -76,7 +137,8 @@ make_chain_connections_continuation(struct ssh_connection *connection,
(super command)
(vars
(callback object command)
(lv object listen_value)))
(client_addr object listen_value)
(server_addr object address_info)))
*/
static void
......@@ -87,50 +149,60 @@ do_chain_connections(struct command *s,
{
CAST(chain_connections, self, s);
CAST(ssh_connection, connection, x);
struct sockaddr_in sa;
int salen = sizeof(sa);
struct address_info *a = NULL;
/* FIXME: support non AF_INET address families */
if (getsockname(self->lv->fd->fd, (struct sockaddr *) &sa, &salen) != -1)
if (self->server_addr)
a = self->server_addr;
else
{
struct address_info *a;
/*
* a = make_address_info(ssh_format("%z", inet_ntoa(sa.sin_addr)), sa.sin_port);
*/
a = make_address_info(ssh_format("localhost"), 1998);
COMMAND_CALL(self->callback, &a->super,
make_chain_connections_continuation(connection, c),
e);
struct sockaddr_in sa;
int salen = sizeof(sa);
/* try to be transparent */
/* FIXME: support non AF_INET address families */
if (getsockname(self->client_addr->fd->fd, (struct sockaddr *) &sa, &salen) != -1)
{
a = make_address_info(ssh_format("%z", inet_ntoa(sa.sin_addr)), ntohs(sa.sin_port));
/* a = make_address_info(ssh_format("localhost"), 1998); */
}
}
COMMAND_CALL(self->callback, &a->super,
make_chain_connections_continuation(connection, c),
e);
}
static struct command *
make_chain_connections(struct command *callback,
struct listen_value *lv)
struct listen_value *client_addr,
struct address_info *server_addr)
{
NEW(chain_connections, self);
self->super.call = do_chain_connections;
self->callback = callback;
self->lv = lv;
self->client_addr = client_addr;
self->server_addr = server_addr;
return &self->super;
}
static struct lsh_object *
do_collect_chain_params(struct collect_info_2 *info UNUSED,
do_collect_chain_params(struct collect_info_3 *info UNUSED,
struct lsh_object *a,
struct lsh_object *b)
struct lsh_object *b,
struct lsh_object *c)
{
CAST_SUBTYPE(command, callback, a);
CAST_SUBTYPE(listen_value, lv, b);
CAST(listen_value, client_addr, b);
CAST(address_info, server_addr, c);
return &make_chain_connections(callback, lv)->super;
return &make_chain_connections(callback, client_addr, server_addr)->super;
}
struct collect_info_2 chain_connections_2 =
STATIC_COLLECT_2_FINAL(do_collect_chain_params);
struct collect_info_3 chain_connections_3 =
STATIC_COLLECT_3_FINAL(do_collect_chain_params);
struct collect_info_2 chain_connections_2 =
STATIC_COLLECT_2(&chain_connections_3);
struct collect_info_1 chain_connections =
STATIC_COLLECT_1(&chain_connections_2);
......@@ -149,15 +221,26 @@ static void
do_login(struct command *s,
struct lsh_object *x UNUSED,
struct command_continuation *c,
struct exception_handler *e UNUSED)
struct exception_handler *e)
{
CAST(proxy_connection_service, self, s);
COMMAND_RETURN(c,
make_install_fix_channel_open_handler
(ATOM_SESSION,
make_proxy_open_session(self->server_requests,
self->client_requests)));
struct object_list *install_open_handlers;
install_open_handlers =
make_object_list(3,
make_install_fix_channel_open_handler
(ATOM_SESSION,
make_proxy_open_session(self->server_requests,
self->client_requests)),
make_install_fix_channel_open_handler
(ATOM_DIRECT_TCPIP,
make_proxy_open_direct_tcpip()),
make_install_fix_channel_open_handler
(ATOM_FORWARDED_TCPIP,
make_proxy_open_forwarded_tcpip()),
-1);
COMMAND_CALL(&progn_command.super, install_open_handlers, c, e);
}
struct command *
......@@ -329,7 +412,7 @@ do_proxy_offer_service(struct command *s,
= make_proxy_service_handler(self->services, c, e);
#if 0
/* currently servers may not ask for servives in clients */
/* currently servers may not ask for services in clients */
connection->chain->dispatch[SSH_MSG_SERVICE_REQUEST]
= make_proxy_service_request(self->server_services, c, e);
#endif
......@@ -345,4 +428,3 @@ make_proxy_offer_service(struct alist *services)
return &self->super;
}
......@@ -28,6 +28,7 @@
#include "command.h"
extern struct collect_info_1 chain_connections;
#define CHAIN_CONNECTIONS (&chain_connections.super.super.super)
struct command *
make_proxy_connection_service(struct alist *server_requests,
......@@ -36,5 +37,12 @@ make_proxy_connection_service(struct alist *server_requests,
struct command *
make_proxy_offer_service(struct alist *services);
struct channel_open *
make_proxy_open_direct_tcpip(void);
struct channel_open *
make_proxy_open_forwarded_tcpip(void);
#endif /* LSH_PROXY_H_INCLUDED */
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