proxy_tcpforward.c 3.96 KB
Newer Older
Balázs Scheidler's avatar
Balázs Scheidler committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* proxy_tcpforward.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_tcpforward.h"
Niels Möller's avatar
Niels Möller committed
25
26

#include "gateway_channel.h"
Balázs Scheidler's avatar
Balázs Scheidler committed
27
28
29
30
31
32
#include "xalloc.h"
#include "ssh.h"
#include "werror.h"
#include "channel_commands.h"
#include "format.h"

33
#define WINDOW_SIZE 10000
Balázs Scheidler's avatar
Balázs Scheidler committed
34
35
36
37

static void
do_proxy_open_direct_tcpip(struct channel_open *s UNUSED,
			   struct ssh_connection *connection,
38
			   struct channel_open_info *info,
Balázs Scheidler's avatar
Balázs Scheidler committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
			   struct simple_buffer *args,
			   struct command_continuation *c,
			   struct exception_handler *e)
{
  struct lsh_string *host = NULL, *orig_host = NULL;
  UINT32 port, orig_port;

  debug("server.c: do_proxy_open_direct_tcpip()\n");

  if ((host = parse_string_copy(args)) &&
      parse_uint32(args, &port) &&
      (orig_host = parse_string_copy(args)) &&
      parse_uint32(args, &orig_port) &&
      parse_eod(args))
    {
Niels Möller's avatar
Niels Möller committed
54
55
56
57
58
      struct gateway_channel *server
	= make_gateway_channel(NULL);

      /* NOTE: The origin's rec_window_size and rec_max_packet becomes the target's
       * send_window_size and send_max_packet. */
Balázs Scheidler's avatar
Balázs Scheidler committed
59

Niels Möller's avatar
Niels Möller committed
60
      struct command *o
61
	= make_gateway_channel_open_command(info,
Niels Möller's avatar
Niels Möller committed
62
63
64
65
66
67
					    ssh_format("%S%i%S%i",
						       host, port, 
						       orig_host, orig_port), NULL);

      werror("direct-tcpip open request: host to connect=%S:%i, originator=%S:%i",
	     host, port, orig_host, orig_port);
Balázs Scheidler's avatar
Balázs Scheidler committed
68
69
      COMMAND_CALL(o,
		   connection->chain,
Niels Möller's avatar
Niels Möller committed
70
		   make_gateway_channel_open_continuation(c, server),
Balázs Scheidler's avatar
Balázs Scheidler committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
		   e);

    }
  else
    {
      PROTOCOL_ERROR(e, "Trailing garbage in open message");
    }
  lsh_string_free(host);
  lsh_string_free(orig_host);
}

struct channel_open *
make_proxy_open_direct_tcpip(void)			     
{
  NEW(channel_open, self);

  self->handler = do_proxy_open_direct_tcpip;
  return self;
}

static void
do_proxy_open_forwarded_tcpip(struct channel_open *s UNUSED,
			      struct ssh_connection *connection,
94
			      struct channel_open_info *info,
Balázs Scheidler's avatar
Balázs Scheidler committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
			      struct simple_buffer *args,
			      struct command_continuation *c,
			      struct exception_handler *e)
{
  struct lsh_string *host = NULL, *orig_host = NULL;
  UINT32 port, orig_port;

  debug("server.c: do_proxy_open_forwarded_tcpip()\n");

  if ((host = parse_string_copy(args)) &&
      parse_uint32(args, &port) &&
      (orig_host = parse_string_copy(args)) &&
      parse_uint32(args, &orig_port) &&
      parse_eod(args))
    {
Niels Möller's avatar
Niels Möller committed
110
111
112
113
114
      struct gateway_channel *server
	= make_gateway_channel(NULL);

      /* NOTE: The origin's rec_window_size and rec_max_packet becomes the target's
       * send_window_size and send_max_packet. */
115
      struct command *o
116
	= make_gateway_channel_open_command(info,
Niels Möller's avatar
Niels Möller committed
117
118
119
					    ssh_format("%S%i%S%i", 
						       host, port, 
						       orig_host, orig_port), NULL);
Balázs Scheidler's avatar
Balázs Scheidler committed
120

121
122
      werror("direct-tcpip open request: address where connection was accepted=%S:%i, originator=%S:%i",
	     host, port, orig_host, orig_port);
Balázs Scheidler's avatar
Balázs Scheidler committed
123
124
      COMMAND_CALL(o,
		   connection->chain,
Niels Möller's avatar
Niels Möller committed
125
		   make_gateway_channel_open_continuation(c, server),
Balázs Scheidler's avatar
Balázs Scheidler committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
		   e);

    }
  else
    {
      PROTOCOL_ERROR(e, "Trailing garbage in open message");
    }
  lsh_string_free(host);
  lsh_string_free(orig_host);
}

struct channel_open *
make_proxy_open_forwarded_tcpip(void)
{
  NEW(channel_open, self);

  self->handler = do_proxy_open_forwarded_tcpip;
  return self;
}