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

* src/proxy.c, src/proxy.h, src/proxy_session.c,

src/proxy_session.h, src/proxy_userauth.h, src/proxy_userauth.c:
New files (Bazsi)

Rev: src/proxy.c:1.1
Rev: src/proxy.h:1.1
Rev: src/proxy_session.c:1.1
Rev: src/proxy_session.h:1.1
Rev: src/proxy_userauth.c:1.1
Rev: src/proxy_userauth.h:1.1
parent 5cdfc77a
/* proxy.c
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Balázs Scheidler
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "proxy.h"
#include "proxy_session.h"
#include "proxy_userauth.h"
#include "channel_commands.h"
#include "exception.h"
#include "xalloc.h"
#include "connection.h"
#include "command.h"
#include "format.h"
#include "io_commands.h"
#include <assert.h>
#include <arpa/inet.h>
#include "proxy.c.x"
/* GABA:
(class
(name chain_connections_continuation)
(super command_frame)
(vars
(connection object ssh_connection)))
*/
static void
do_chain_connections_continuation(struct command_continuation *s,
struct lsh_object *x)
{
CAST(chain_connections_continuation, self, s);
CAST(ssh_connection, chained, x);
self->connection->chain = chained;
chained->chain = self->connection;
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)
{
NEW(chain_connections_continuation, self);
self->super.super.c = do_chain_connections_continuation;
self->connection = connection;
self->super.up = c;
return &self->super.super;
}
/* GABA:
(class
(name chain_connections)
(super command)
(vars
(callback object command)
(lv object listen_value)))
*/
static void
do_chain_connections(struct command *s,
struct lsh_object *x,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(chain_connections, self, s);
CAST(ssh_connection, connection, x);
struct sockaddr_in sa;
int salen = sizeof(sa);
/* FIXME: support non AF_INET address families */
if (getsockname(self->lv->fd->super.fd, (struct sockaddr *) &sa, &salen) != -1)
{
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);
}
}
static struct command *
make_chain_connections(struct command *callback,
struct listen_value *lv)
{
NEW(chain_connections, self);
self->super.call = do_chain_connections;
self->callback = callback;
self->lv = lv;
return &self->super;
}
static struct lsh_object *
do_collect_chain_params(struct collect_info_2 *info UNUSED,
struct lsh_object *a,
struct lsh_object *b)
{
CAST_SUBTYPE(command, callback, a);
CAST_SUBTYPE(listen_value, lv, b);
return &make_chain_connections(callback, lv)->super;
}
struct collect_info_2 chain_connections_2 =
STATIC_COLLECT_2_FINAL(do_collect_chain_params);
struct collect_info_1 chain_connections =
STATIC_COLLECT_1(&chain_connections_2);
/* gets two params: user connection ->
handles user here, and returns a command taking a connection */
/* GABA:
(class
(name proxy_connection_service)
(super command)
(vars
(session_requests object alist)))
*/
static void
do_login(struct command *s,
struct lsh_object *x UNUSED,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST(proxy_connection_service, self, s);
COMMAND_RETURN(c,
make_install_fix_channel_open_handler
(ATOM_SESSION,
make_proxy_open_session(self->session_requests)));
}
struct command *
make_proxy_connection_service(struct alist *session_requests)
{
NEW(proxy_connection_service, self);
self->super.call = do_login;
self->session_requests = session_requests;
return &self->super;
}
/* proxy.h
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Balázs Scheidler
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LSH_PROXY_H_INCLUDED
#define LSH_PROXY_H_INCLUDED
#include "alist.h"
#include "command.h"
extern struct collect_info_1 chain_connections;
struct command *
make_proxy_connection_service(struct alist *session_requests);
#endif /* LSH_PROXY_H_INCLUDED */
/* proxy_session.c
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Balázs Scheidler
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "proxy_session.h"
#include "xalloc.h"
#include "ssh.h"
#include "werror.h"
#include "proxy_session.c.x"
#define WINDOW_SIZE (SSH_MAX_PACKET << 3)
/* GABA:
(class
(name proxy_channel)
(super ssh_channel)
(vars
(chain object proxy_channel)))
*/
static struct ssh_channel *
make_proxy_channel(UINT32 window_size,
struct alist *session_requests)
{
return NULL;
}
/* GABA:
(class
(name proxy_open_session)
(super channel_open)
(vars
(session_requests object alist)))
*/
static void
do_proxy_open_session(struct channel_open *s,
struct ssh_connection *connection,
struct simple_buffer *args,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(proxy_open_session, closure, s);
debug("server.c: do_proxy_open_session()\n");
if (parse_eod(args))
{
}
else
{
PROTOCOL_ERROR(e, "trailing garbage in open message");
}
}
struct channel_open *
make_proxy_open_session(struct alist *session_requests)
{
NEW(proxy_open_session, self);
self->super.handler = do_proxy_open_session;
self->session_requests = session_requests;
return &self->super;
}
/* proxy_session.h
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Balázs Scheidler
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LSH_PROXY_SESSION_H_INCLUDED
#define LSH_PROXY_SESSION_H_INCLUDED
#include "alist.h"
#include "channel.h"
struct channel_open *
make_proxy_open_session(struct alist *session_requests);
#endif /* LSH_PROXY_SESSION_H_INCLUDED */
/* proxy_userauth.c
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Balzs Scheidler
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "proxy_userauth.h"
#include "proxy.h"
#include "server_userauth.h"
#include "client_userauth.h"
#include "xalloc.h"
#include "ssh.h"
#include "lsh.h"
#include "werror.h"
#define GABA_DEFINE
#include "proxy_userauth.h.x"
#undef GABA_DEFINE
#include "proxy_userauth.c.x"
static struct proxy_user *
make_proxy_user(struct lsh_string *name)
{
NEW(proxy_user, self);
self->name = name;
return self;
}
/* GABA:
(class
(name proxy_userauth_success)
(super packet_handler)
(vars
(name string)
(c object command_continuation)))
*/
static void
do_forward_success(struct packet_handler *c,
struct ssh_connection *connection,
struct lsh_string *packet)
{
CAST(proxy_userauth_success, self, c);
struct simple_buffer buffer;
unsigned msg_number;
simple_buffer_init(&buffer, packet->length, packet->data);
connection->dispatch[SSH_MSG_USERAUTH_FAILURE] = connection->fail;
connection->dispatch[SSH_MSG_USERAUTH_SUCCESS] = connection->fail;
if (parse_uint8(&buffer, &msg_number)
&& (msg_number == SSH_MSG_USERAUTH_SUCCESS)
&& parse_eod(&buffer))
{
C_WRITE(connection->chain, packet);
COMMAND_RETURN(self->c, make_proxy_user(self->name));
}
else
{
PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_USERAUTH_SUCCESS message.");
lsh_string_free(packet);
}
}
static struct packet_handler *
make_forward_success(struct lsh_string *name,
struct command_continuation *c)
{
NEW(proxy_userauth_success, self);
self->super.handler = do_forward_success;
self->name = name;
self->c = c;
return &self->super;
}
/* GABA:
(class
(name proxy_userauth_failure)
(super packet_handler)
(vars
(e object exception_handler)))
*/
static void
do_forward_failure(struct packet_handler *c UNUSED,
struct ssh_connection *connection,
struct lsh_string *packet)
{
struct simple_buffer buffer;
unsigned msg_number;
simple_buffer_init(&buffer, packet->length, packet->data);
connection->dispatch[SSH_MSG_USERAUTH_FAILURE] = connection->fail;
connection->dispatch[SSH_MSG_USERAUTH_SUCCESS] = connection->fail;
if (parse_uint8(&buffer, &msg_number)
&& (msg_number == SSH_MSG_USERAUTH_SUCCESS)
&& parse_eod(&buffer))
{
verbose("Authentication failure");
C_WRITE(connection->chain, packet);
}
else
{
PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_USERAUTH_SUCCESS message.");
lsh_string_free(packet);
}
}
static struct packet_handler *
make_forward_failure(struct exception_handler *e)
{
NEW(proxy_userauth_failure, self);
self->super.handler = do_forward_failure;
self->e = e;
return &self->super;
}
/* ;; GABA:
(class
(name proxy_userauth)
(super userauth)
(vars
*/
static void
do_forward_userauth_req(struct userauth *ignored UNUSED,
struct ssh_connection *connection,
struct lsh_string *username,
UINT32 service,
struct simple_buffer *args,
struct command_continuation *c UNUSED,
struct exception_handler *e UNUSED)
{
struct lsh_string *password;
int change_password;
if (parse_boolean(args, &change_password) &&
(password = parse_string_copy(args)) &&
parse_eod(args))
{
connection->chain->dispatch[SSH_MSG_USERAUTH_FAILURE] =
make_forward_failure(e);
connection->chain->dispatch[SSH_MSG_USERAUTH_SUCCESS] =
make_forward_success(username, c);
C_WRITE(connection->chain, format_userauth_password(username, service, password, 1));
}
}
struct userauth proxy_password_auth =
{ STATIC_HEADER, do_forward_userauth_req };
static void
do_userauth_proxy(struct command *s,
struct lsh_object *x,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(userauth_service, self, s);
CAST(ssh_connection, connection, x);
connection->dispatch[SSH_MSG_USERAUTH_REQUEST] =
make_userauth_handler(self->methods,
self->services,
c,
e);
}
struct command *
make_userauth_proxy(struct int_list *allowed_methods,
struct alist *methods,
struct alist *services)
{
NEW(userauth_service, self);
self->super.call = do_userauth_proxy;
self->advertised_methods = allowed_methods;
self->methods = methods;
self->services = services;
return &self->super;
}
/* proxy_userauth.h
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Balázs Scheidler
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LSH_PROXY_USERAUTH_H_INCLUDED
#define LSH_PROXY_USERAUTH_H_INCLUDED
#include "xalloc.h"
#include "alist.h"
#include "list.h"
#include "userauth.h"
#define GABA_DECLARE
#include "proxy_userauth.h.x"
#undef GABA_DECLARE
/* GABA:
(class
(name proxy_user)
(vars
(name string)))
*/
extern struct userauth proxy_password_auth;
struct command *make_userauth_proxy(struct int_list *allowed_methods,
struct alist *methods,
struct alist *services);
#endif /* LSH_PROXY_USERAUTH_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