proxy_tcpforward.c 4.18 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
25
26
27
28
29
30
31
/* 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"
#include "proxy_channel.h"
#include "xalloc.h"
#include "ssh.h"
#include "werror.h"
#include "channel_commands.h"
#include "format.h"

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

static void
do_proxy_open_direct_tcpip(struct channel_open *s UNUSED,
			   struct ssh_connection *connection,
			   UINT32 type,
38
			   UINT32 send_max_packet,
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))
    {
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
      struct proxy_channel *server
	= make_proxy_channel(WINDOW_SIZE,
			     /* FIXME: We should adapt to the other
			      * end's max packet size. Parhaps should
			      * be done by
			      * do_proxy_channel_open_continuation() ?
			      * */
			     SSH_MAX_PACKET,
			     NULL, 0);
      struct command *o
	= make_proxy_channel_open_command(type,
					  send_max_packet,
					  ssh_format("%S%i%S%i",
						     host, port, 
						     orig_host, orig_port), NULL);
Balázs Scheidler's avatar
Balázs Scheidler committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

      werror("direct-tcpip open request: host to connect=%S:%i, originator=%S:%i", host, port, orig_host, orig_port);
      COMMAND_CALL(o,
		   connection->chain,
		   make_proxy_channel_open_continuation(c, server),
		   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,
			      UINT32 type,
98
			      UINT32 send_max_packet, 
Balázs Scheidler's avatar
Balázs Scheidler committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
			      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))
    {
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      struct proxy_channel *server
	= make_proxy_channel(WINDOW_SIZE,
			     /* FIXME: We should adapt to the other
			      * end's max packet size. Parhaps should
			      * be done by
			      * do_proxy_channel_open_continuation() ?
			      * */
			     SSH_MAX_PACKET,
			     NULL, 0);
      struct command *o
	= make_proxy_channel_open_command(type, 
					  send_max_packet,
					  ssh_format("%S%i%S%i", 
						     host, port, 
						     orig_host, orig_port), NULL);
Balázs Scheidler's avatar
Balázs Scheidler committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

      werror("direct-tcpip open request: address where connection was accepted=%S:%i, originator=%S:%i", host, port, orig_host, orig_port);
      COMMAND_CALL(o,
		   connection->chain,
		   make_proxy_channel_open_continuation(c, server),
		   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;
}